diff options
author | 2022-06-16 13:22:13 +0100 | |
---|---|---|
committer | 2022-06-16 15:35:44 +0100 | |
commit | 12161045e46f6edd422f265e509c1b21d4f4e07e (patch) | |
tree | 738e52ebd08e597617d9958054f53b93d0716144 /bpmn/so-bpmn-tasks | |
parent | 9267b3ae36ce0ade8d7f7bcd44ff648e78d3a14e (diff) |
[SO] CNF Invoke AS instance updates
Change-Id: I221df282a8cf1b9b4b0c579517393d2818eafaf2
Signed-off-by: SagarS <sagar.shetty@est.tech>
Issue-ID: SO-3905
Diffstat (limited to 'bpmn/so-bpmn-tasks')
4 files changed, 77 insertions, 11 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java index 6d7b3e9287..927be4db61 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java @@ -5,15 +5,15 @@ * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -35,6 +35,7 @@ import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.cnfm.lcm.model.AsInstance; import org.onap.so.cnfm.lcm.model.CreateAsRequest; +import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.RequestDetails; @@ -46,13 +47,15 @@ import org.springframework.stereotype.Component; /** * This class performs CNF Instantiation - * + * * @author sagar.shetty@est.tech * @author Waqas Ikram (waqas.ikram@est.tech) */ @Component public class CnfInstantiateTask { private static final String CREATE_AS_REQUEST_OBJECT = "CreateAsRequestObject"; + private static final String INSTANTIATE_AS_REQUEST_OBJECT = "InstantiateAsRequest"; + private static final String AS_INSTANCE_ID = "asInstanceid"; private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class); private final ExceptionBuilder exceptionUtil; private final CnfmHttpServiceProvider cnfmHttpServiceProvider; @@ -120,6 +123,7 @@ public class CnfInstantiateTask { } final AsInstance asInstance = optional.get(); + execution.setVariable(AS_INSTANCE_ID, asInstance.getAsInstanceid()); LOGGER.debug("Successfully invoked CNFM response: {}", asInstance); } catch (final Exception exception) { @@ -128,4 +132,34 @@ public class CnfInstantiateTask { } } + public void createAsInstanceRequest(final BuildingBlockExecution execution) { + try { + LOGGER.debug("Executing createAsInstanceRequest task ..."); + + final InstantiateAsRequest instantiateAsRequest = new InstantiateAsRequest(); + + LOGGER.debug("Adding InstantiateAsRequest to execution {}", instantiateAsRequest); + + execution.setVariable(INSTANTIATE_AS_REQUEST_OBJECT, instantiateAsRequest); + LOGGER.debug("Finished executing createAsInstanceRequest task ..."); + + } catch (final Exception exception) { + LOGGER.error("Unable to create CreateAsInstanceRequest", exception); + exceptionUtil.buildAndThrowWorkflowException(execution, 2001, exception); + } + } + + public void invokeCnfmWithInstantiateAsRequest(final BuildingBlockExecution execution) { + try { + final InstantiateAsRequest instantiateAsRequest = execution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT); + final String asInstanceId = execution.getVariable(AS_INSTANCE_ID); + cnfmHttpServiceProvider.invokeInstantiateAsRequest(createAsRequest, asInstanceId); + LOGGER.debug("Successfully invoked CNFM instantiate AS request: {}", asInstanceId); + + } catch (final Exception exception) { + LOGGER.error("Unable to invoke CNFM InstantiateAsRequest", exception); + exceptionUtil.buildAndThrowWorkflowException(execution, 2004, exception); + } + } + } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java index 4ff346543f..abf3508fe6 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java @@ -22,7 +22,7 @@ package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; import java.util.Optional; import org.onap.so.cnfm.lcm.model.AsInstance; import org.onap.so.cnfm.lcm.model.CreateAsRequest; - +import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; /** * @author Sagar Shetty (sagar.shetty@est.tech) @@ -33,4 +33,6 @@ public interface CnfmHttpServiceProvider { Optional<AsInstance> invokeCreateAsRequest(final CreateAsRequest createAsRequest); + void invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId); + } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java index f861855b99..bb789607e4 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java @@ -5,15 +5,15 @@ * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; @Service public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider { @@ -80,4 +81,28 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider { } } + @Override + public void invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId) { + try { + + final String url = cnfmUrlProvider.getInstantiateAsRequestUrl(asInstanceId); + final ResponseEntity<AsInstance> response = + httpServiceProvider.postHttpRequest(instantiateAsRequest, url, AsInstance.class); + + final HttpStatus httpStatus = response.getStatusCode(); + if (httpStatus.is2xxSuccessful()) { + if (!response.hasBody()) { + LOGGER.error("Received response without body: {}", response); + } + + } + LOGGER.error("Unable to invoke HTTP POST using URL: {}, Response Code: {}", url, httpStatus.value()); + + } catch (final RestProcessingException | InvalidRestRequestException + | HttpResouceNotFoundException httpInvocationException) { + LOGGER.error("Unexpected error while processing instantiation request", httpInvocationException); + } + + } + } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java index 3a0e4de6f9..6cd5d1e262 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java @@ -5,15 +5,15 @@ * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -44,4 +44,9 @@ public class CnfmUrlProvider { return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").build().toString(); } + public String getInstantiateAsRequestUrl(String asInstanceId) { + return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").pathSegment(asInstanceId) + .pathSegment("instantiate").build().toString(); + } + } |