Beispiel #1
0
  @Override
  public Future<RpcResult<ReadServiceFunctionOutput>> readServiceFunction(
      ReadServiceFunctionInput input) {
    printTraceStart(LOG);
    LOG.info("Input: " + input);

    if (dataBroker != null) {
      ServiceFunctionKey sfkey = new ServiceFunctionKey(input.getName());
      InstanceIdentifier<ServiceFunction> sfIID;
      sfIID =
          InstanceIdentifier.builder(ServiceFunctions.class)
              .child(ServiceFunction.class, sfkey)
              .toInstance();

      ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
      Optional<ServiceFunction> dataObject = null;
      try {
        dataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfIID).get();
      } catch (InterruptedException | ExecutionException e) {
        LOG.debug("Failed to readServiceFunction : {}", e.getMessage());
      }
      if (dataObject instanceof ServiceFunction) {
        LOG.debug("readServiceFunction Success: {}", ((ServiceFunction) dataObject).getName());
        ServiceFunction serviceFunction = (ServiceFunction) dataObject;
        ReadServiceFunctionOutput readServiceFunctionOutput = null;
        ReadServiceFunctionOutputBuilder outputBuilder = new ReadServiceFunctionOutputBuilder();
        outputBuilder
            .setName(serviceFunction.getName())
            .setIpMgmtAddress(serviceFunction.getIpMgmtAddress())
            .setType(serviceFunction.getType());
        readServiceFunctionOutput = outputBuilder.build();
        printTraceStop(LOG);
        return Futures.immediateFuture(
            Rpcs.<ReadServiceFunctionOutput>getRpcResult(
                true, readServiceFunctionOutput, Collections.<RpcError>emptySet()));
      }
      printTraceStop(LOG);
      return Futures.immediateFuture(
          Rpcs.<ReadServiceFunctionOutput>getRpcResult(
              true, null, Collections.<RpcError>emptySet()));
    } else {
      LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]);
      printTraceStop(LOG);
      return Futures.immediateFuture(
          Rpcs.<ReadServiceFunctionOutput>getRpcResult(
              true, null, Collections.<RpcError>emptySet()));
    }
  }
Beispiel #2
0
  @Override
  public Future<RpcResult<Void>> putServiceFunction(PutServiceFunctionInput input) {
    printTraceStart(LOG);
    LOG.info("\n####### Input: " + input);

    if (dataBroker != null) {

      // Data PLane Locator
      List<SfDataPlaneLocator> sfDataPlaneLocatorList = input.getSfDataPlaneLocator();

      ServiceFunctionBuilder sfbuilder = new ServiceFunctionBuilder();
      ServiceFunctionKey sfkey = new ServiceFunctionKey(input.getName());
      ServiceFunction sf =
          sfbuilder
              .setName(input.getName())
              .setType(input.getType())
              .setKey(sfkey)
              .setIpMgmtAddress(input.getIpMgmtAddress())
              .setSfDataPlaneLocator(sfDataPlaneLocatorList)
              .build();

      InstanceIdentifier<ServiceFunction> sfEntryIID =
          InstanceIdentifier.builder(ServiceFunctions.class)
              .child(ServiceFunction.class, sf.getKey())
              .toInstance();

      WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
      writeTx.merge(LogicalDatastoreType.CONFIGURATION, sfEntryIID, sf);
      writeTx.commit();

    } else {
      LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]);
    }
    printTraceStop(LOG);
    return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true, Collections.<RpcError>emptySet()));
  }