Ejemplo n.º 1
0
  @Override
  public Future<RpcResult<CreateRenderedPathOutput>> createRenderedPath(
      CreateRenderedPathInput createRenderedPathInput) {

    ServiceFunctionPath createdServiceFunctionPath;
    RenderedServicePath renderedServicePath;
    RenderedServicePath revRenderedServicePath;
    CreateRenderedPathOutputBuilder createRenderedPathOutputBuilder =
        new CreateRenderedPathOutputBuilder();
    RpcResult<CreateRenderedPathOutput> rpcResult;
    String retRspName = null;

    createdServiceFunctionPath =
        SfcProviderServicePathAPI.readServiceFunctionPathExecutor(
            createRenderedPathInput.getParentServiceFunctionPath());

    if (createdServiceFunctionPath != null) {
      renderedServicePath =
          SfcProviderRenderedPathAPI.createRenderedServicePathAndState(
              createdServiceFunctionPath, createRenderedPathInput);
      if (renderedServicePath != null) {
        retRspName = renderedServicePath.getName();
        createRenderedPathOutputBuilder.setName(retRspName);
        rpcResult = RpcResultBuilder.success(createRenderedPathOutputBuilder.build()).build();

        if ((createdServiceFunctionPath.getClassifier() != null)
            && SfcProviderServiceClassifierAPI.readServiceClassifierExecutor(
                    createdServiceFunctionPath.getClassifier())
                != null) {
          SfcProviderServiceClassifierAPI.addRenderedPathToServiceClassifierStateExecutor(
              createdServiceFunctionPath.getClassifier(), renderedServicePath.getName());
        } else {
          LOG.warn("Classifier not provided or does not exist");
        }

        if ((createdServiceFunctionPath.isSymmetric() != null)
            && createdServiceFunctionPath.isSymmetric()) {

          revRenderedServicePath =
              SfcProviderRenderedPathAPI.createSymmetricRenderedServicePathAndState(
                  renderedServicePath);
          if (revRenderedServicePath == null) {
            LOG.error("Failed to create symmetric service path: {}");
          } else if ((createdServiceFunctionPath.getSymmetricClassifier() != null)
              && SfcProviderServiceClassifierAPI.readServiceClassifierExecutor(
                      createdServiceFunctionPath.getSymmetricClassifier())
                  != null) {
            SfcProviderServiceClassifierAPI.addRenderedPathToServiceClassifierStateExecutor(
                createdServiceFunctionPath.getSymmetricClassifier(),
                revRenderedServicePath.getName());

          } else {
            LOG.warn("Symmetric Classifier not provided or does not exist");
          }
        }
      } else {
        rpcResult =
            RpcResultBuilder.<CreateRenderedPathOutput>failed()
                .withError(ErrorType.APPLICATION, "Failed to create RSP")
                .build();
      }

    } else {
      rpcResult =
          RpcResultBuilder.<CreateRenderedPathOutput>failed()
              .withError(ErrorType.APPLICATION, "Service Function Path does not exist")
              .build();
    }
    return Futures.immediateFuture(rpcResult);
  }