diff options
13 files changed, 490 insertions, 33 deletions
diff --git a/features/ccsdk-sli-adaptors-all/pom.xml b/features/ccsdk-sli-adaptors-all/pom.xml index 77ccb4c8..68ad0f77 100644 --- a/features/ccsdk-sli-adaptors-all/pom.xml +++ b/features/ccsdk-sli-adaptors-all/pom.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -16,12 +17,10 @@ <name>ccsdk-sli-adaptors :: features :: ${project.artifactId}</name> - <properties> <ccsdk.sli.adaptors.version>${project.version}</ccsdk.sli.adaptors.version> </properties> - <dependencies> <dependency> <groupId>${project.groupId}</groupId> @@ -37,6 +36,7 @@ <type>xml</type> <classifier>features</classifier> </dependency> + <!-- saltstack-adapter needs to be changed to remove dependency on app-c code <dependency> <groupId>${project.groupId}</groupId> <artifactId>ccsdk-saltstack-adapter</artifactId> @@ -46,6 +46,14 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>ccsdk-grpc-client</artifactId> + <version>${project.version}</version> + <type>xml</type> + <classifier>features</classifier> + </dependency> + --> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>ccsdk-netbox-client</artifactId> <version>${project.version}</version> <type>xml</type> @@ -72,6 +80,5 @@ <type>xml</type> <classifier>features</classifier> </dependency> - </dependencies> </project> diff --git a/grpc-resource/features/ccsdk-grpc-client/pom.xml b/grpc-resource/features/ccsdk-grpc-client/pom.xml index d24d1e23..cc9b9ba5 100644 --- a/grpc-resource/features/ccsdk-grpc-client/pom.xml +++ b/grpc-resource/features/ccsdk-grpc-client/pom.xml @@ -32,11 +32,6 @@ <name>ccsdk-sli-adaptors :: grpc-client :: ${project.artifactId}</name> - - <properties> - <ccsdk.sli.adaptors.version>${project.version}</ccsdk.sli.adaptors.version> - </properties> - <dependencies> <dependency> <groupId>org.opendaylight.controller</groupId> @@ -58,5 +53,12 @@ <artifactId>grpc-client-provider</artifactId> <version>${project.version}</version> </dependency> + + <dependency> + <groupId>com.google.protobuf</groupId> + <artifactId>protobuf-java</artifactId> + <version>3.6.1</version> + </dependency> + </dependencies> </project> diff --git a/grpc-resource/installer/pom.xml b/grpc-resource/installer/pom.xml index 3bb4162c..9586d4fa 100755 --- a/grpc-resource/installer/pom.xml +++ b/grpc-resource/installer/pom.xml @@ -121,7 +121,17 @@ <useRepositoryLayout>true</useRepositoryLayout> <addParentPoms>false</addParentPoms> <copyPom>false</copyPom> - <includeGroupIds>org.onap.ccsdk.sli.adaptors</includeGroupIds> + <includeGroupIds> + org.onap.ccsdk.sli.adaptors, + org.onap.ccsdk.apps.components, + io.grpc, + io.netty, + com.google.protobuf, + io.opencensus, + com.google.api.grpc, + com.google.errorprone, + org.codehaus.mojo + </includeGroupIds> <scope>provided</scope> </configuration> </execution> diff --git a/grpc-resource/provider/pom.xml b/grpc-resource/provider/pom.xml index 20f83c1e..9c0a4a0d 100644 --- a/grpc-resource/provider/pom.xml +++ b/grpc-resource/provider/pom.xml @@ -33,8 +33,9 @@ <name>ccsdk-sli-adaptors :: grpc-client :: ${project.artifactId}</name> <properties> - <ccsdk.sli.adaptors.version>${project.version}</ccsdk.sli.adaptors.version> - <grpc.version>1.16.1</grpc.version> + <grpc.version>1.17.1</grpc.version> + <protobuf.version>3.6.1</protobuf.version> + <grpc.netty.version>4.1.30.Final</grpc.netty.version> </properties> <dependencyManagement> @@ -50,35 +51,62 @@ </dependencyManagement> <dependencies> + + <!-- SLI dependencies --> <dependency> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>sliPluginUtils-provider</artifactId> - <scope>compile</scope> + <scope>provided</scope> </dependency> - <!-- GRPC Dependencies --> + <!-- CDS dependencies --> <dependency> - <groupId>io.grpc</groupId> - <artifactId>grpc-core</artifactId> - <version>${grpc.version}</version> + <groupId>org.onap.ccsdk.apps.components</groupId> + <artifactId>proto-definition</artifactId> + <version>${project.version}</version> + <exclusions> + <exclusion> + <groupId>com.google.code.findbugs</groupId> + <artifactId>jsr305</artifactId> + </exclusion> + <exclusion> + <groupId>com.google.protobuf</groupId> + <artifactId>protobuf-java-util</artifactId> + </exclusion> + </exclusions> </dependency> + + <!-- protobuf dependencies --> <dependency> - <groupId>io.grpc</groupId> - <artifactId>grpc-netty</artifactId> - <version>${grpc.version}</version> + <groupId>com.google.protobuf</groupId> + <artifactId>protobuf-java</artifactId> + <version>${protobuf.version}</version> </dependency> + + <!-- gRPC dependencies --> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-protobuf</artifactId> <version>${grpc.version}</version> + <exclusions> + <exclusion> + <groupId>com.google.code.findbugs</groupId> + <artifactId>jsr305</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-stub</artifactId> <version>${grpc.version}</version> </dependency> + <dependency> + <groupId>io.grpc</groupId> + <artifactId>grpc-netty</artifactId> + <version>${grpc.version}</version> + </dependency> - <!--Testing--> + <!-- Testing --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> @@ -102,8 +130,12 @@ <configuration> <instructions> <Export-Package> - org.onap.ccsdk.sli.adaptors.grpc + io.grpc, + io.grpc.inprocess, + io.grpc.internal, + io.grpc.util </Export-Package> + <Import-Package>!com.google.errorprone.annotations,*</Import-Package> </instructions> </configuration> </plugin> diff --git a/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcClient.java b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcClient.java index c70bcec4..91788274 100644 --- a/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcClient.java +++ b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcClient.java @@ -15,15 +15,18 @@ */ package org.onap.ccsdk.sli.adaptors.grpc; -public class GrpcClient { +import java.util.Map; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; -// ManagedChannel channel = ManagedChannelBuilder -// .forAddress("localhost", 8080) -// .executor(Executors.newSingleThreadExecutor()) -// .intercept() -// .userAgent("CCSDK gRPC Client") -// .usePlaintext() -// //.useTransportSecurity() -// .build(); +public interface GrpcClient extends SvcLogicJavaPlugin { + /** + * Send a request to process to a gRPC server. + * + * @param parameters HashMap<String,String> of parameters passed by the DG to this function. + * Required parameters are defined in implemention. + */ + QueryStatus sendRequest(Map<String, String> parameters, SvcLogicContext ctx); } diff --git a/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcProperties.java b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcProperties.java new file mode 100644 index 00000000..fef1a596 --- /dev/null +++ b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcProperties.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2018 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.sli.adaptors.grpc; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.HashSet; +import java.util.Optional; +import java.util.Properties; +import java.util.Set; +import org.onap.ccsdk.sli.core.utils.JREFileResolver; +import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver; +import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver; +import org.onap.ccsdk.sli.core.utils.common.BundleContextFileResolver; +import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Responsible for determining the properties file to use. + * + * <ol> + * <li>A directory identified by the system environment variable <code>SDNC_CONFIG_DIR</code></li> + * <li>A directory identified by the JRE argument <code>grpc.properties</code></li> + * <li>A <code>grpc.properties</code> file located in the karaf root directory</li> + * </ol> + * + * Partial copy and adaptation of org.onap.ccsdk.sli.adaptors.aai.AAIServiceProvider + */ +public class GrpcProperties { + + private static final Logger LOG = LoggerFactory.getLogger(GrpcProperties.class); + + private static final String GRPC_PROPERTY_FILE_NAME = "grpc.properties"; + private static final String MISSING_PROPERTY_FILE = + "Missing configuration properties resource for GRPC: " + GRPC_PROPERTY_FILE_NAME; + private static final String BLUEPRINT_PROCESSOR_URL_PROP = "org.onap.ccsdk.sli.adaptors.grpc.blueprint.processor.url"; + private static final String BLUEPRINT_PROCESSOR_PORT_PROP = "org.onap.ccsdk.sli.adaptors.grpc.blueprint.processor.port"; + + private Set<PropertiesFileResolver> fileResolvers = new HashSet<>(); + private Properties properties; + + public GrpcProperties() { + fileResolvers.add(new SdncConfigEnvVarFileResolver("Using property file (1) from environment variable")); + fileResolvers.add(new BundleContextFileResolver("Using property file (2) from BundleContext property", + GrpcProperties.class)); + fileResolvers.add(new JREFileResolver("Using property file (3) from JRE argument", GrpcProperties.class)); + fileResolvers.add(new KarafRootFileResolver("Using property file (4) from karaf root", this)); + + loadProps(); + } + + public String getUrl() { + checkArgument(properties != null); + return properties.getProperty(BLUEPRINT_PROCESSOR_URL_PROP); + } + + public int getPort() { + checkArgument(properties != null); + return Integer.parseInt(properties.getProperty(BLUEPRINT_PROCESSOR_PORT_PROP)); + } + + private void checkArgument(final boolean argument) { + if (!argument) { + LOG.info("Propety file {} was missing, trying to reload it", GRPC_PROPERTY_FILE_NAME); + loadProps(); + if (properties == null) { + throw new IllegalArgumentException(MISSING_PROPERTY_FILE); + } + } + } + + private void loadProps() { + // determines properties file as according to the priority described in the class header comment + final File propertiesFile = determinePropertiesFile(); + if (propertiesFile != null) { + try (FileInputStream fileInputStream = new FileInputStream(propertiesFile)) { + properties = new Properties(); + properties.load(fileInputStream); + } catch (final IOException e) { + String errorMsg = "Failed to load properties for file: " + propertiesFile.toString(); + LOG.error(errorMsg, errorMsg); + } + } + } + + private File determinePropertiesFile() { + for (final PropertiesFileResolver resolver : fileResolvers) { + final Optional<File> fileOptional = resolver.resolveFile(GRPC_PROPERTY_FILE_NAME); + if (fileOptional.isPresent()) { + final File file = fileOptional.get(); + LOG.info("{} {}", resolver.getSuccessfulResolutionMessage(), file.getPath()); + return file; + } + } + + LOG.error(MISSING_PROPERTY_FILE); + return null; + } +} diff --git a/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/Utils.java b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/Utils.java new file mode 100644 index 00000000..831f09ea --- /dev/null +++ b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/Utils.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2019 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.sli.adaptors.grpc; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +public final class Utils { + + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + + private Utils() { + throw new AssertionError("Utility class"); + } + + public static String timestamp() { + LocalDateTime now = LocalDateTime.now(ZoneId.systemDefault()); + return formatter.format(now); + } +} diff --git a/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/cds/BlueprintProcessingClient.java b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/cds/BlueprintProcessingClient.java new file mode 100644 index 00000000..33fb8fa2 --- /dev/null +++ b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/cds/BlueprintProcessingClient.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2019 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.sli.adaptors.grpc.cds; + +import io.grpc.ManagedChannel; +import io.grpc.internal.DnsNameResolverProvider; +import io.grpc.netty.NettyChannelBuilder; +import java.util.Map; +import org.onap.ccsdk.sli.adaptors.grpc.GrpcClient; +import org.onap.ccsdk.sli.adaptors.grpc.GrpcProperties; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BlueprintProcessingClient implements GrpcClient { + + private static final Logger log = LoggerFactory.getLogger(BlueprintProcessingClient.class); + + private ManagedChannel channel; + private BlueprintProcessingHandler handler; + + public BlueprintProcessingClient(BlueprintProcessingHandler handler, GrpcProperties props) { + this.channel = NettyChannelBuilder + .forAddress(props.getUrl(), props.getPort()) + .usePlaintext() + .nameResolverFactory(new DnsNameResolverProvider()) + .build(); + this.handler = handler; + } + + // Used by blueprint + public void start() { + log.info("BlueprintProcessingClient started"); + } + + // Used by blueprint + public void stop() { + if (channel != null) { + channel.shutdown(); + } + log.info("BlueprintProcessingClient stopped"); + } + + /* + * @param parameters HashMap<String,String> of parameters passed by the DG to this function. + * <table border="1"> + * <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead> + * <tbody> + * <tr><td>is_force</td><td>Optional</td><td>Whether to force or not the request.</td></tr> + * <tr><td>ttl</td><td>Optional</td><td>Duration of the request.</td></tr> + * <tr><td>blueprint_name</td><td>Mandatory</td><td>Name of the blueprint to process.</td></tr> + * <tr><td>blueprint_version</td><td>Mandatory</td><td>Version of the blueprint to process.</td></tr> + * <tr><td>action</td><td>Mandatory</td><td>Action of the blueprint to process.</td></tr> + * <tr><td>mode</td><td>Mandatory</td><td>Mode to operate the transaction.</td></tr> + * </tbody> + * </table> + */ + @Override + public QueryStatus sendRequest(Map<String, String> parameters, SvcLogicContext ctx) { + return handler.process(parameters, channel); + } +}
\ No newline at end of file diff --git a/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/cds/BlueprintProcessingHandler.java b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/cds/BlueprintProcessingHandler.java new file mode 100644 index 00000000..6a618fb3 --- /dev/null +++ b/grpc-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/grpc/cds/BlueprintProcessingHandler.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2019 Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.sli.adaptors.grpc.cds; + +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.Struct; +import io.grpc.ManagedChannel; +import io.grpc.Status; +import io.grpc.stub.StreamObserver; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; +import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers; +import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader; +import org.onap.ccsdk.apps.controllerblueprints.common.api.Flag; +import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc; +import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceStub; +import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput; +import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput; +import org.onap.ccsdk.sli.adaptors.grpc.Utils; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BlueprintProcessingHandler { + + private static final Logger log = LoggerFactory.getLogger(BlueprintProcessingHandler.class); + + private static final String CCSDK_ORIGINATOR = "CCSDK"; + private static final String IS_FORCE_PROP = "is_force"; + private static final String TTL_PROP = "ttl"; + private static final String BLUEPRINT_NAME_PROP = "blueprint_name"; + private static final String BLUEPRINT_VERSION_PROP = "blueprint_version"; + private static final String ACTION_PROP = "action"; + private static final String MODE_PROP = "mode"; + private static final String PAYLOAD_PROP = "payload"; + + QueryStatus process(final Map<String, String> parameters, final ManagedChannel channel) { + try { + SliPluginUtils.checkParameters(parameters, + new String[]{BLUEPRINT_NAME_PROP, BLUEPRINT_VERSION_PROP, ACTION_PROP, MODE_PROP}, log); + } catch (SvcLogicException e) { + return QueryStatus.FAILURE; + } + + final boolean isForce = Boolean.getBoolean(parameters.get(IS_FORCE_PROP)); + final int ttl = Integer.parseInt(parameters.get(TTL_PROP)); + final String blueprintName = parameters.get(BLUEPRINT_NAME_PROP); + final String blueprintVersion = parameters.get(BLUEPRINT_VERSION_PROP); + final String action = parameters.get(ACTION_PROP); + final String mode = parameters.get(MODE_PROP); + final String payload = parameters.get(PAYLOAD_PROP); + + log.info("Processing blueprint({}:{}) for action({})", blueprintVersion, blueprintName, action); + + final AtomicReference<QueryStatus> responseStatus = new AtomicReference<>(); + final CountDownLatch finishLatch = new CountDownLatch(1); + + final BluePrintProcessingServiceStub asyncStub = BluePrintProcessingServiceGrpc.newStub(channel); + + final StreamObserver<ExecutionServiceOutput> responseObserver = new StreamObserver<ExecutionServiceOutput>() { + @Override + public void onNext(ExecutionServiceOutput output) { + log.info("onNext: {}", output); + } + + @Override + public void onError(Throwable t) { + Status status = Status.fromThrowable(t); + log.error("Failed processing blueprint({}:{}) for action({}). {}", blueprintVersion, blueprintName, + action, status); + responseStatus.compareAndSet(null, QueryStatus.FAILURE); + finishLatch.countDown(); + } + + @Override + public void onCompleted() { + log.info("Completed blueprint({}:{}) for action({})", blueprintVersion, blueprintName, action); + responseStatus.compareAndSet(null, QueryStatus.SUCCESS); + finishLatch.countDown(); + } + }; + + final CommonHeader commonHeader = CommonHeader.newBuilder() + .setOriginatorId(CCSDK_ORIGINATOR) + .setRequestId(UUID.randomUUID().toString()) + .setTimestamp(Utils.timestamp()) + .setFlag(Flag.newBuilder() + .setIsForce(isForce) + .setTtl(ttl) + .build()) + .build(); + final ActionIdentifiers actionIdentifiers = ActionIdentifiers.newBuilder() + .setActionName(action) + .setBlueprintName(blueprintName) + .setBlueprintVersion(blueprintVersion) + .setMode(mode) + .build(); + + Struct struct; + try { + struct = Struct.newBuilder().mergeFrom(payload.getBytes()).build(); + } catch (InvalidProtocolBufferException e) { + log.error("Failed converting payload for blueprint({}:{}) for action({}). {}", blueprintVersion, + blueprintName, action, e); + return QueryStatus.FAILURE; + } + + final ExecutionServiceInput request = ExecutionServiceInput.newBuilder() + .setActionIdentifiers(actionIdentifiers) + .setPayload(struct) + .setCommonHeader(commonHeader).build(); + + final StreamObserver<ExecutionServiceInput> requestObserver = asyncStub.process(responseObserver); + + try { + requestObserver.onNext(request); + } catch (RuntimeException e) { + requestObserver.onError(e); + return QueryStatus.FAILURE; + } + + requestObserver.onCompleted(); + try { + finishLatch.await(1, TimeUnit.MINUTES); + } catch (InterruptedException e) { + log.error("Failed processing blueprint({}:{}) for action({}). {}", blueprintVersion, blueprintName, action, + e); + Thread.currentThread().interrupt(); + return QueryStatus.FAILURE; + } + + return responseStatus.get(); + } +}
\ No newline at end of file diff --git a/grpc-resource/provider/src/main/resources/grpc.properties b/grpc-resource/provider/src/main/resources/grpc.properties new file mode 100755 index 00000000..2d4e795e --- /dev/null +++ b/grpc-resource/provider/src/main/resources/grpc.properties @@ -0,0 +1,15 @@ +# Copyright (C) 2019 Bell Canada +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +org.onap.ccsdk.sli.adaptors.grpc.blueprint.processor.url=blueprint-processor +org.onap.ccsdk.sli.adaptors.grpc.blueprint.processor.port=9111
\ No newline at end of file diff --git a/grpc-resource/provider/src/main/resources/org/opendaylight/blueprint/grpc-client.xml b/grpc-resource/provider/src/main/resources/org/opendaylight/blueprint/grpc-client.xml index 5e9d5c80..e6e75159 100644 --- a/grpc-resource/provider/src/main/resources/org/opendaylight/blueprint/grpc-client.xml +++ b/grpc-resource/provider/src/main/resources/org/opendaylight/blueprint/grpc-client.xml @@ -17,6 +17,17 @@ <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0" odl:use-default-for-reference-types="true"> - <bean id="grpcClient" class="org.onap.ccsdk.sli.adaptors.grpc.GrpcClient"/> + + <bean id="grpcProperty" class="org.onap.ccsdk.sli.adaptors.grpc.GrpcProperties"/> + + <!--CDS--> + + <bean id="blueprintProcessingHandler" class="org.onap.ccsdk.sli.adaptors.grpc.cds.BlueprintProcessingHandler"/> + + <bean id="grpcClient" class="org.onap.ccsdk.sli.adaptors.grpc.cds.BlueprintProcessingClient" + init-method="start" destroy-method="stop"> + <argument ref="blueprintProcessingHandler"/> + <argument ref="grpcProperty"/> + </bean> </blueprint> diff --git a/grpc-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcClientTest.java b/grpc-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/grpc/cds/GrpcClientTest.java index f56736a5..2b1a42ba 100644 --- a/grpc-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/grpc/GrpcClientTest.java +++ b/grpc-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/grpc/cds/GrpcClientTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onap.ccsdk.sli.adaptors.grpc; +package org.onap.ccsdk.sli.adaptors.grpc.cds; public class GrpcClientTest { @@ -111,6 +111,7 @@ <module>ansible-adapter</module> <module>saltstack-adapter</module> <module>netbox-client</module> + <module>grpc-resource</module> <module>mdsal-resource</module> <module>resource-assignment</module> <module>sql-resource</module> |