From 2f15f49c88921713b8dd6679220c35adee7ca1c5 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Tue, 12 Feb 2019 15:53:39 -0500 Subject: Create restconf component function module Change-Id: I04c29bfc981b677d81da73441228215ce4868833 Issue-ID: CCSDK-1060 Signed-off-by: Muthuramalingam, Brinda Santh --- ms/blueprintsprocessor/functions/pom.xml | 2 + .../functions/restconf-executor/pom.xml | 40 ++++++++++++++ .../restconf/executor/ComponentRestconfExecutor.kt | 62 ++++++++++++++++++++++ .../restconf/executor/RestconfComponentFunction.kt | 33 ++++++++++++ .../executor/RestconfExecutorConfiguration.kt | 29 ++++++++++ .../executor/ComponentRestconfExecutorTest.kt | 56 +++++++++++++++++++ .../src/test/resources/logback-test.xml | 35 ++++++++++++ .../service/BluePrintRestLibPropertyServiceTest.kt | 58 ++++++++++++++++++++ .../rest/service/RestClientServiceTest.kt | 2 +- .../RestPropertyPlaceHolderConfigurationTest.kt | 57 -------------------- ms/blueprintsprocessor/parent/pom.xml | 5 ++ 11 files changed, 321 insertions(+), 58 deletions(-) create mode 100644 ms/blueprintsprocessor/functions/restconf-executor/pom.xml create mode 100644 ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt create mode 100644 ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt create mode 100644 ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfExecutorConfiguration.kt create mode 100644 ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt create mode 100644 ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml create mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt delete mode 100644 ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestPropertyPlaceHolderConfigurationTest.kt (limited to 'ms/blueprintsprocessor') diff --git a/ms/blueprintsprocessor/functions/pom.xml b/ms/blueprintsprocessor/functions/pom.xml index 2a952f88e..503e5f0b9 100755 --- a/ms/blueprintsprocessor/functions/pom.xml +++ b/ms/blueprintsprocessor/functions/pom.xml @@ -1,6 +1,7 @@ + + + + functions + org.onap.ccsdk.apps.blueprintsprocessor + 0.4.1-SNAPSHOT + + 4.0.0 + org.onap.ccsdk.apps.blueprintsprocessor.functions + restconf-executor + Blueprints Processor Function - Restconf Executor + Blueprints Processor Function - Restconf Executor + + + + org.onap.ccsdk.apps.blueprintsprocessor.functions + python-executor + + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt new file mode 100644 index 000000000..67202df49 --- /dev/null +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt @@ -0,0 +1,62 @@ +/* + * Copyright © 2018 IBM. + * + * 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.apps.blueprintsprocessor.functions.restconf.executor + +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService +import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.ApplicationContext +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Component + +@Component("component-restconf-executor") +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class ComponentRestconfExecutor(private var applicationContext: ApplicationContext, + private val blueprintJythonService: BlueprintJythonService, + var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService) : + AbstractComponentFunction() { + + private val log = LoggerFactory.getLogger(ComponentRestconfExecutor::class.java) + + lateinit var scriptComponent: RestconfComponentFunction + + override fun process(executionRequest: ExecutionServiceInput) { + scriptComponent = blueprintJythonService.jythonComponentInstance(this) as RestconfComponentFunction + checkNotNull(scriptComponent) { "failed to get netconf script component" } + + scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService + scriptComponent.processId = processId + scriptComponent.workflowName = workflowName + scriptComponent.stepName = stepName + scriptComponent.interfaceName = interfaceName + scriptComponent.operationName = operationName + scriptComponent.nodeTemplateName = nodeTemplateName + scriptComponent.operationInputs = operationInputs + + // Set the Rest Lib Property Service + scriptComponent.bluePrintRestLibPropertyService = bluePrintRestLibPropertyService + + scriptComponent.process(executionServiceInput) + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + scriptComponent.recover(runtimeException, executionRequest) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt new file mode 100644 index 000000000..7b3615fe3 --- /dev/null +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt @@ -0,0 +1,33 @@ +/* + * Copyright © 2018 IBM. + * + * 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.apps.blueprintsprocessor.functions.restconf.executor + +import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService +import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BlueprintWebClientService +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction + + +abstract class RestconfComponentFunction : AbstractComponentFunction() { + + lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService + + fun restClientService(selector: String): BlueprintWebClientService { + return bluePrintRestLibPropertyService.blueprintWebClientService(selector) + } + + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfExecutorConfiguration.kt new file mode 100644 index 000000000..300f5be13 --- /dev/null +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfExecutorConfiguration.kt @@ -0,0 +1,29 @@ +/* + * Copyright © 2018 IBM. + * + * 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.apps.blueprintsprocessor.functions.restconf.executor + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + + +@Configuration +@ComponentScan +@EnableConfigurationProperties +@ConditionalOnProperty(name = ["blueprintsprocessor.restconfEnabled"], havingValue = "true") +open class RestconfExecutorConfiguration \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt b/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt new file mode 100644 index 000000000..b195fe0fe --- /dev/null +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt @@ -0,0 +1,56 @@ +/* + * Copyright © 2018 IBM. + * + * 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.apps.blueprintsprocessor.functions.restconf.executor + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService +import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty +import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [RestconfExecutorConfiguration::class, ComponentRestconfExecutor::class, + BlueprintJythonService::class, PythonExecutorProperty::class, BluePrintRestLibPropertyService::class, + BlueprintPropertyConfiguration::class,BluePrintProperties::class]) +@TestPropertySource(properties = +["server.port=9111", + "blueprintsprocessor.restconfEnabled=true", + "blueprintsprocessor.restclient.odlPrimary.type=basic-auth", + "blueprintsprocessor.restclient.odlPrimary.url=http://127.0.0.1:9111", + "blueprintsprocessor.restclient.odlPrimary.userId=sampleuser", + "blueprintsprocessor.restclient.odlPrimary.token=sampletoken"]) +class ComponentRestconfExecutorTest { + + @Autowired + lateinit var componentRestconfExecutor: ComponentRestconfExecutor + + @Test + fun `test Restconf Component Instance`() { + + assertNotNull(componentRestconfExecutor, "failed to get ComponentRestconfExecutor instance") + } + + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml new file mode 100644 index 000000000..44ec746cb --- /dev/null +++ b/ms/blueprintsprocessor/functions/restconf-executor/src/test/resources/logback-test.xml @@ -0,0 +1,35 @@ + + + + + + + %d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n + + + + + + + + + + + + + diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt new file mode 100644 index 000000000..d6e5549a6 --- /dev/null +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt @@ -0,0 +1,58 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.apps.blueprintsprocessor.rest.service + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties +import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration +import org.onap.ccsdk.apps.blueprintsprocessor.rest.BluePrintRestLibConfiguration +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class, BluePrintProperties::class]) +@TestPropertySource(properties = +["blueprintsprocessor.restclient.sample.type=basic-auth", + "blueprintsprocessor.restclient.sample.url=http://localhost:8080", + "blueprintsprocessor.restclient.sample.userId=sampleuser"]) + +class BluePrintRestLibPropertyServiceTest { + + @Autowired + lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService + + @Test + fun testRestClientProperties() { + val properties = bluePrintRestLibPropertyService.restClientProperties("blueprintsprocessor.restclient.sample") + assertNotNull(properties, "failed to create property bean") + assertNotNull(properties.url, "failed to get url property in property bean") + } + + @Test + fun testBlueprintWebClientService() { + val blueprintWebClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample") + assertNotNull(blueprintWebClientService, "failed to create blueprintWebClientService") + } + +} + diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt index 1481406ed..25821966f 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestClientServiceTest.kt @@ -37,7 +37,7 @@ import kotlin.test.assertNotNull @EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class]) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class, - SampleController::class, BluePrintProperties::class]) + SampleController::class, BluePrintProperties::class, BluePrintProperties::class]) @TestPropertySource(properties = ["server.port=9111", "blueprintsprocessor.restclient.sample.type=basic-auth", diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestPropertyPlaceHolderConfigurationTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestPropertyPlaceHolderConfigurationTest.kt deleted file mode 100644 index d5e27430e..000000000 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/RestPropertyPlaceHolderConfigurationTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.apps.blueprintsprocessor.rest.service - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties -import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration -import org.onap.ccsdk.apps.blueprintsprocessor.rest.BluePrintRestLibConfiguration -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertNotNull - - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [BluePrintRestLibConfiguration::class, BlueprintPropertyConfiguration::class, BluePrintProperties::class]) -@TestPropertySource(properties = -["blueprintsprocessor.restclient.sample.type=basic-auth", - "blueprintsprocessor.restclient.sample.url=http://localhost:8080", - "blueprintsprocessor.restclient.sample.userId=sampleuser"]) - -class RestPropertyPlaceHolderConfigurationTest { - - @Autowired - lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService - - @Test - fun testRestClientProperties() { - val properties = bluePrintRestLibPropertyService.restClientProperties("blueprintsprocessor.restclient.sample") - assertNotNull(properties, "failed to create property bean") - assertNotNull(properties.url, "failed to get url property in property bean") - } - - @Test - fun testBlueprintWebClientService() { - val blueprintWebClientService = bluePrintRestLibPropertyService.blueprintWebClientService("sample") - assertNotNull(blueprintWebClientService, "failed to create blueprintWebClientService") - } - -} - diff --git a/ms/blueprintsprocessor/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml index 685cf41d6..5fe7641bb 100755 --- a/ms/blueprintsprocessor/parent/pom.xml +++ b/ms/blueprintsprocessor/parent/pom.xml @@ -315,6 +315,11 @@ netconf-executor ${project.version} + + org.onap.ccsdk.apps.blueprintsprocessor.functions + restconf-executor + ${project.version} + -- cgit 1.2.3-korg