Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golang services #605

Merged
10 commits merged into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions sdk/cpp/core/src/ydk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "crud_service.hpp"
#include "errors.hpp"
#include "logger.hpp"
#include "netconf_provider.hpp"
#include "opendaylight_provider.hpp"
#include "restconf_provider.hpp"
Expand Down Expand Up @@ -763,3 +764,23 @@ LogLevel GetLoggingLevel(void)
}
}

void YLogInfo(const char* msg)
{
ydk::YLOG_INFO(msg);
}

void YLogDebug(const char* msg)
{
ydk::YLOG_DEBUG(msg);
}

void YLogWarn(const char* msg)
{
ydk::YLOG_WARN(msg);
}

void YLogError(const char* msg)
{
ydk::YLOG_ERROR(msg);
}

5 changes: 5 additions & 0 deletions sdk/cpp/core/src/ydk.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ void EnableLogging(LogLevel);
LogLevel GetLoggingLevel(void);
// LogLevel GetLoggingLevel(YDKState*, void);

void YLogInfo(const char*);
void YLogDebug(const char*);
void YLogWarn(const char*);
void YLogError(const char*);

#ifdef __cplusplus
}
#endif
Expand Down
190 changes: 183 additions & 7 deletions sdk/go/core/docsgen/api/services/services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CRUD

Supports CRUD operations on entities.

.. function:: (provider *CrudService) Create(provider ServiceProvider, entity Entity)
.. function:: (c *CrudService) Create(provider ServiceProvider, entity Entity)

Create the entity.

Expand All @@ -22,7 +22,7 @@ CRUD
:return: whether the operation was successful or not
:rtype: ``bool``

.. function:: (provider *CrudService) Update(provider ServiceProvider, entity Entity)
.. function:: (c *CrudService) Update(provider ServiceProvider, entity Entity)

Update the entity.

Expand All @@ -31,7 +31,7 @@ CRUD
:return: whether the operation was successful or not
:rtype: ``bool``

.. function:: (provider *CrudService) Delete(provider ServiceProvider, entity Entity)
.. function:: (c *CrudService) Delete(provider ServiceProvider, entity Entity)

Delete the entity.

Expand All @@ -40,7 +40,7 @@ CRUD
:return: whether the operation was successful or not
:rtype: ``bool``

.. function:: (provider *CrudService) Read(provider ServiceProvider, filter Entity)
.. function:: (c *CrudService) Read(provider ServiceProvider, filter Entity)

Read the entity.

Expand All @@ -49,7 +49,7 @@ CRUD
:return: the entity as identified by the given filter
:rtype: :go:struct:`Entity<ydk/types/Entity>`

.. function:: (provider *CrudService) ReadConfig(provider ServiceProvider, filter Entity)
.. function:: (c *CrudService) ReadConfig(provider ServiceProvider, filter Entity)

Read only config.

Expand All @@ -66,7 +66,7 @@ Codec

Supports encoding and decoding Go model API objects of type :go:struct:`Entity`

.. function:: (provider *CodecService) Encode(provider CodecServiceProvider, entity Entity)
.. function:: (c *CodecService) Encode(provider CodecServiceProvider, entity Entity)

Encode converts entity object to XML/JSON payload

Expand All @@ -75,11 +75,187 @@ Codec
:return: encoded payload
:rtype: A Go ``string``

.. function:: (provider *CodecService) Decode(provider CodecServiceProvider, payload string)
.. function:: (c *CodecService) Decode(provider CodecServiceProvider, payload string)

Decode converts XML/JSON object to entity object

:param provider: An instance :go:struct:`CodecServiceProvider<ydk/types/CodecServiceProvider>`
:param payload: A Go ``string`` representing an encoded payload to decode
:return: the decoded entity object
:rtype: :go:struct:`Entity<ydk/types/Entity>`

Executor
--------

.. go:struct:: ExecutorService

Provides the functionality to execute RPCs

.. function:: (es *ExecutorService) ExecuteRpc (provider types.ServiceProvider, rpcEntity, topEntity types.Entity)

Create the entity

:param provider: An instance of :go:struct:`ServiceProvider`
:param rpcEntity: An instance of :go:struct:`Entity<ydk/types/Entity>` representing an RPC entity
:param topEntity: Provide an instance of :go:struct:`Entity<ydk/types/Entity>` only when expecting data to be returned
:return: Any data the resulting from the operation when provided topEntity parameter
:rtype: :go:struct:`Entity<ydk/types/Entity>` or ``nil``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

Possible Errors:
* a server side error
* there isn't enough information in the entity to prepare the message (eg. missing keys)

Netconf
-------

.. go:struct:: NetconfService

Implements the NETCONF Protocol Operations: https://tools.ietf.org/html/rfc6241.

.. function:: (ns *NetconfService) CancelCommit(provider ServiceProvider, persistId int)

Cancels an ongoing confirmed commit. If the persist_id < 1, the operation **MUST** be issued on the same session that issued the confirmed commit.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param persistId: An ``int``
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) CloseSession(provider ServiceProvider)

Request graceful termination of a NETCONF session

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) Commit(
provider ServiceProvider, confirmed bool, confirmTimeOut, persist, persistId int)

Instructs the device to implement the configuration data contained in the candidate configuration.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param confirmed: A ``bool`` that signals a confirmed commit operation
:param comfirmTimeOut: An ``int`` representing the timeout interval for a confirmed commit
:param persist: An ``int`` that makes the confirmed commit persistent
:param persistId: An ``int`` that is given in order to commit a persistent confirmed commit
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) CopyConfig(
provider ServiceProvider, target, sourceDS DataStore, sourceEntity Entity, url string)

Create or replace an entire configuration DataStore with the contents of another complete configuration DataStore. If the target DataStore exists, it is overwritten. Otherwise, a new one is created, if allowed.
sourceEntity should be nil OR sourceDS should be nil, but not neither or both. url is ignored unless target/sourceDS is set to Url.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param target: An instance of :go:struct:`DataStore<ydk/types/DataStore>` representing the configuration being used as the destination
:param sourceDS: An instance of :go:struct:`DataStore<ydk/types/DataStore>` representing the configuration being used as the source
:param sourceEntity: An instance of :go:struct:`Entity<ydk/types/Entity>` representing the configuration being used as the source
:param url: A ``string`` representing the configuration url
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) DeleteConfig(provider ServiceProvider, target DataStore, url string)

Delete a configuration DataStore. The RUNNING configuration DataStore cannot be deleted.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param target: An instance of :go:struct:`DataStore<ydk/types/DataStore>` representing the configuration being used as the destination
:param url: A ``string`` representing the configuration url
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) DiscardChanges(provider ServiceProvider)

Used to revert the candidate configuration to the current running configuration.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) EditConfig(
provider ServiceProvider, target DataStore, config Entity, defaultOper, testOp, errorOp string)

Loads all or part of a specified configuration to the specified target configuration datastore. Allows the new configuration to be expressed using a local file, a remote file, or inline. If the target configuration datastore does not exist, it will be created.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param target: An instance of :go:struct:`DataStore<ydk/types/DataStore>` representing the configuration being used as the destination
:param config: An instance of :go:struct:`Entity<ydk/types/Entity>` that is a hierarchy configuration of data as defined by one of the device’s data models
:param defaultOper: A ``string`` that changes the default from ``merge`` to either ``merge``, ``replace``, or ``none``
:param testOp: A ``string`` that can be set to ``test-then-set``, ``set``, or ``test-only`` if the device advertises the :validate:1.1 capability
:param errOp: A ``string`` that can be set to ``stop-on-error``, ``continue-on-error``, or ``rollback-on-error``
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) GetConfig(provider ServiceProvider, source DataStore, filter Entity)

Retrieve all or part of a specified configuration datastore

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param source: An instance of :go:struct:`DataStore<ydk/types/DataStore>` representing the configuration being used as the source
:param filter: An instance of :go:struct:`Entity<ydk/types/Entity>` which specifies the portion of the system configuration and state data to retrieve
:return: The requested data
:rtype: :go:struct:`Entity<ydk/types/Entity>`
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) Get(provider ServiceProvider, filter Entity)

Retrieve running configuration and device state information.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param filter: An instance of :go:struct:`Entity<ydk/types/Entity>` which specifies the portion of the system configuration and state data to retrieve
:return: The requested data
:rtype: :go:struct:`Entity<ydk/types/Entity>`
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) KillSession(provider ServiceProvider, sessionId int)

Force the termination of a NETCONF session.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param sessionId: An ``int`` that is the session identifier of the NETCONF session to be terminated
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) Lock(provider ServiceProvider, target DataStore)

Allows the client to lock the entire configuration datastore system of a device.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param target: An instance of :go:struct:`DataStore<ydk/types/DataStore>` representing the configuration to lock
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) Unlock(provider ServiceProvider, target DataStore)

Used to release a configuration lock, previously obtained with the LOCK operation.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param target: An instance of :go:struct:`DataStore<ydk/types/DataStore>` representing the configuration to unlock
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred

.. function:: (ns *NetconfService) Validate(
provider ServiceProvider, sourceDS DataStore, sourceEntity Entity, url string)

Validates the contents of the specified configuration. sourceEntity should be nil OR sourceDS should be nil, but not neither or both. url is ignored unless target/sourceDS is set to Url.

:param provider: An instance of :go:struct:`NetconfServiceProvider<ydk/types/NetconfServiceProvider>`
:param sourceEntity: An instance of :go:struct:`Entity<ydk/types/Entity>` representing the configuration being used as the source
:param sourceDS: An instance of :go:struct:`DataStore<ydk/types/DataStore>` representing the configuration being used as the source
:param url: A ``string`` representing the configuration url
:return: whether or not the operation succeeded
:rtype: ``bool``
:raises: `YGOError<ydk/errors/YGOError>` If error has occurred
10 changes: 5 additions & 5 deletions sdk/go/core/tests/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (suite *DeleteTestSuite) TestDeleteOnListWithIdentitykey() {
k := ysanity.Runner_OneList_IdentityList{}
k.Config.Id = ysanity.Child_Identity{}
k.IdRef = ysanity.Child_Identity{}
k.Filter = types.Delete
k.YFilter = types.Delete
runnerUpdate.OneList.IdentityList = append(runnerUpdate.OneList.IdentityList, k)
suite.CRUD.Update(&suite.Provider, &runnerUpdate)

Expand All @@ -181,7 +181,7 @@ func (suite *DeleteTestSuite) TestDeleteOnContainer() {
suite.CRUD.Create(&suite.Provider, &runnerCreate)

runnerUpdate := ysanity.Runner{}
runnerUpdate.Two.Filter = types.Delete
runnerUpdate.Two.YFilter = types.Delete
suite.CRUD.Update(&suite.Provider, &runnerUpdate)

runnerCmp := ysanity.Runner{}
Expand Down Expand Up @@ -217,7 +217,7 @@ func (suite *DeleteTestSuite) TestDeleteOnListElement() {
suite.CRUD.Create(&suite.Provider, &runnerCreate)

runnerUpdate := runnerCreate
runnerUpdate.InbtwList.Ldata[1].Filter = types.Delete
runnerUpdate.InbtwList.Ldata[1].YFilter = types.Delete
suite.CRUD.Update(&suite.Provider, &runnerUpdate)

entity := suite.CRUD.Read(&suite.Provider, &ysanity.Runner{})
Expand Down Expand Up @@ -249,8 +249,8 @@ func (suite *DeleteTestSuite) TestDeleteOnListElements() {

entity := suite.CRUD.Read(&suite.Provider, &ysanity.Runner{})
runnerUpdate := entity.(*ysanity.Runner)
runnerUpdate.OneList.Ldata[1].Filter = types.Delete
runnerUpdate.OneList.Ldata[2].Filter = types.Delete
runnerUpdate.OneList.Ldata[1].YFilter = types.Delete
runnerUpdate.OneList.Ldata[2].YFilter = types.Delete

suite.CRUD.Update(&suite.Provider, runnerUpdate)

Expand Down
21 changes: 21 additions & 0 deletions sdk/go/core/tests/did_panic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package test

// didPanic returns true if the function passed to it panics. Otherwise, it returns false.
func didPanic(panicTestFunc func()) (bool, string) {

didPanic := false
var message interface{}
func() {

defer func() {
if message = recover(); message != nil {
didPanic = true
}
}()

// call the target function
panicTestFunc()

}()
return didPanic, message.(string)
}
Loading