diff options
Diffstat (limited to 'adapters')
10 files changed, 357 insertions, 74 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java index f39962b2ce..1fabcb279c 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java @@ -71,6 +71,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ public static final String VNF_ID = "vnf_id"; public static final String VF_MODULE_ID = "vf_module_id"; public static final String TEMPLATE_TYPE = "template_type"; + public static final String MULTICLOUD_QUERY_BODY_NULL = "multicloudQueryBody is null"; public static final List<String> MULTICLOUD_INPUTS = Arrays.asList(OOF_DIRECTIVES, SDNC_DIRECTIVES, USER_DIRECTIVES, TEMPLATE_TYPE); @@ -228,7 +229,13 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ if (logger.isDebugEnabled()) { logger.debug("Multicloud Create Response Body: {}", multicloudResponseBody); } - return getStackStatus(cloudSiteId, cloudOwner, tenantId, canonicalName, pollForCompletion, timeoutMinutes, backout); + StackInfo stackStatus = getStackStatus(cloudSiteId, cloudOwner, tenantId, canonicalName, pollForCompletion, timeoutMinutes, backout); + + if (HeatStatus.CREATED.equals(stackStatus.getStatus())) { + multicloudAaiUpdate(cloudSiteId, cloudOwner, tenantId, genericVnfId, vfModuleId, multicloudResponseBody.getWorkloadId(), pollForCompletion, timeoutMinutes); + } + + return stackStatus; } StringBuilder stackErrorStatusReason = new StringBuilder(response.getStatusInfo().getReasonPhrase()); if (null != multicloudResponseBody) { @@ -287,7 +294,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ if (multicloudClient != null) { Response response = multicloudClient.get(); if (logger.isDebugEnabled()) { - logger.debug (String.format("Mulicloud GET Response: %s", response.toString())); + logger.debug (String.format("Multicloud GET Response: %s", response.toString())); } MulticloudQueryResponse multicloudQueryBody = null; @@ -296,11 +303,16 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ returnInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase()); } else if (response.getStatus() == Response.Status.OK.getStatusCode() && response.hasEntity()) { multicloudQueryBody = getQueryBody((java.io.InputStream)response.getEntity()); - returnInfo.setCanonicalName(stackName + "/" + multicloudQueryBody.getWorkloadId()); - returnInfo.setStatus(getHeatStatus(multicloudQueryBody.getWorkloadStatus())); - returnInfo.setStatusMessage(multicloudQueryBody.getWorkloadStatus()); - if (logger.isDebugEnabled()) { - logger.debug("Multicloud Create Response Body: " + multicloudQueryBody.toString()); + if (multicloudQueryBody != null) { + returnInfo.setCanonicalName(stackName + "/" + multicloudQueryBody.getWorkloadId()); + returnInfo.setStatus(getHeatStatus(multicloudQueryBody.getWorkloadStatus())); + returnInfo.setStatusMessage(multicloudQueryBody.getWorkloadStatus()); + if (logger.isDebugEnabled()) { + logger.debug("Multicloud Create Response Body: " + multicloudQueryBody.toString()); + } + } else { + returnInfo.setStatus(HeatStatus.FAILED); + returnInfo.setStatusMessage(MULTICLOUD_QUERY_BODY_NULL); } } else { returnInfo.setStatus(HeatStatus.FAILED); @@ -371,6 +383,81 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ return HeatStatus.UNKNOWN; } + private void multicloudAaiUpdate(String cloudSiteId, String cloudOwner, String tenantId, String genericVnfId, String vfModuleId, String workloadId, + boolean pollForCompletion, int timeoutMinutes) { + + MulticloudRequest multicloudRequest= new MulticloudRequest(); + + multicloudRequest.setGenericVnfId(genericVnfId); + multicloudRequest.setVfModuleId(vfModuleId); + + String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, workloadId); + RestClient multicloudClient = getMulticloudClient(multicloudEndpoint); + + if (multicloudClient == null) { + if (logger.isDebugEnabled()) + logger.debug("Multicloud client could not be initialized"); + } + + Response response = multicloudClient.post(multicloudRequest); + if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) { + if (logger.isDebugEnabled()) + logger.debug("Multicloud AAI update request failed: " + response.getStatus() + response.getStatusInfo()); + return; + } + + if (!pollForCompletion) { + return; + } + + int updatePollInterval = Integer.parseInt(this.environment.getProperty(createPollIntervalProp, createPollIntervalDefault)); + int pollTimeout = (timeoutMinutes * 60) + updatePollInterval; + boolean updateTimedOut = false; + logger.debug("updatePollInterval=" + updatePollInterval + ", pollTimeout=" + pollTimeout); + + StackInfo stackInfo = null; + while (true) { + try { + stackInfo = queryStack(cloudSiteId, cloudOwner, tenantId, workloadId); + if (logger.isDebugEnabled()) + logger.debug (stackInfo.getStatus() + " (" + workloadId + ")"); + + if (HeatStatus.UPDATING.equals(stackInfo.getStatus())) { + if (pollTimeout <= 0) { + // Note that this should not occur, since there is a timeout specified + // in the Openstack (multicloud?) call. + if (logger.isDebugEnabled()) + logger.debug("Multicloud AAI update timeout failure: {} {} {} {}", cloudOwner, cloudSiteId, tenantId, workloadId); + updateTimedOut = true; + break; + } + + sleep(updatePollInterval * 1000L); + + pollTimeout -= updatePollInterval; + if (logger.isDebugEnabled()) + logger.debug("pollTimeout remaining: " + pollTimeout); + } else { + break; + } + } catch (MsoException me) { + if (logger.isDebugEnabled()) + logger.debug("Multicloud AAI update exception: {} {} {} {}", cloudOwner, cloudSiteId, tenantId, workloadId, me); + return; + } + } + if (updateTimedOut) { + if (logger.isDebugEnabled()) + logger.debug("Multicloud AAI update request failed: {} {}", response.getStatus(), response.getStatusInfo().toString()); + } else if (!HeatStatus.UPDATED.equals(stackInfo.getStatus())) { + if (logger.isDebugEnabled()) + logger.debug("Multicloud AAI update request failed: {} {}", response.getStatus(), response.getStatusInfo().toString()); + } else { + if (logger.isDebugEnabled()) + logger.debug("Multicloud AAI update successful: {} {}", response.getStatus(), response.getStatusInfo().toString()); + } + } + private StackInfo getStackStatus(String cloudSiteId, String cloudOwner, String tenantId, String instanceId) throws MsoException { return getStackStatus(cloudSiteId, cloudOwner, tenantId, instanceId, false, 0, false); } @@ -543,7 +630,9 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ } private HeatStatus mapResponseToHeatStatus(Response response) { - if (response.getStatusInfo().getStatusCode() == Response.Status.OK.getStatusCode()) { + if (response == null) { + return HeatStatus.FAILED; + } else if (response.getStatusInfo().getStatusCode() == Response.Status.OK.getStatusCode()) { return HeatStatus.CREATED; } else if (response.getStatusInfo().getStatusCode() == Response.Status.CREATED.getStatusCode()) { return HeatStatus.CREATED; @@ -596,7 +685,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ return null; } - private String getMulticloudEndpoint(String cloudSiteId, String cloudOwner, String workloadId) throws MsoCloudSiteNotFound { + private String getMulticloudEndpoint(String cloudSiteId, String cloudOwner, String workloadId) { String msbIp = System.getenv().get(ONAP_IP); if (null == msbIp || msbIp.isEmpty()) { msbIp = environment.getProperty("mso.msb-ip", DEFAULT_MSB_IP); diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java index fbe532d1fe..e066c4eec6 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java @@ -4,8 +4,6 @@ * ================================================================================ * Copyright (C) 2019 Samsung Intellectual Property. All rights reserved. * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ * 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 @@ -23,6 +21,7 @@ package org.onap.so.openstack.utils; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; @@ -30,12 +29,14 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.when; +import static org.onap.so.openstack.utils.MsoMulticloudUtils.MULTICLOUD_QUERY_BODY_NULL; import java.io.IOException; import java.util.HashMap; import java.util.Optional; import org.apache.http.HttpStatus; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.mockito.InjectMocks; @@ -67,18 +68,43 @@ public class MsoMulticloudUtilsTest extends BaseTest { private static final String CREATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": " + "\"TEST-workload\", \"template_response\": {\"stack\": {\"id\": \"TEST-stack\", \"links\": []}}}"; + private static final String UPDATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": " + + "\"TEST-workload\"}"; + private static final String GET_CREATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": " + + "\"TEST-workload\", \"workload_status\": \"CREATE_COMPLETE\"}"; + private static final String GET_UPDATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": " + + "\"TEST-workload\", \"workload_status\": \"UPDATE_COMPLETE\"}"; - private static final String MULTICLOUD_PATH = "/api/multicloud/v1/CloudOwner/MTN14/infra_workload"; + private static final String MULTICLOUD_CREATE_PATH = "/api/multicloud/v1/CloudOwner/MTN14/infra_workload"; + private static final String MULTICLOUD_UPDATE_PATH = "/api/multicloud/v1/CloudOwner/MTN14/infra_workload/TEST-workload"; + private static final String MULTICLOUD_GET_PATH = "/api/multicloud/v1/CloudOwner/MTN14/infra_workload/TEST-workload"; @Test public void createStackSuccess() throws MsoException, IOException { - wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_PATH)) + wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)).inScenario("CREATE") .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(CREATE_STACK_RESPONSE) - .withStatus(HttpStatus.SC_CREATED))); + .withStatus(HttpStatus.SC_CREATED)) + .willSetStateTo("CREATING")); + wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH)) + .inScenario("CREATE").whenScenarioStateIs("CREATING") + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(GET_CREATE_STACK_RESPONSE) + .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_UPDATE_PATH)).inScenario("CREATE") + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(UPDATE_STACK_RESPONSE) + .withStatus(HttpStatus.SC_ACCEPTED)) + .willSetStateTo("UPDATING")); + wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH)) + .inScenario("CREATE").whenScenarioStateIs("UPDATING") + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(GET_UPDATE_STACK_RESPONSE) + .withStatus(HttpStatus.SC_OK))); StackInfo result = multicloudUtils.createStack("MTN14", "CloudOwner", "TEST-tenant", "TEST-stack", new VduModelInfo(), - "TEST-heat", new HashMap<>(), false, 200, "TEST-env", + "TEST-heat", new HashMap<>(), true, 200, "TEST-env", new HashMap<>(), new HashMap<>(), false); + wireMockServer.resetScenarios(); assertNotNull(result); assertEquals("TEST-stack", result.getName()); } @@ -96,6 +122,18 @@ public class MsoMulticloudUtilsTest extends BaseTest { assertTrue(HeatStatus.NOTFOUND == result.getStatus()); } + @Test + public void queryStackWithNullMulticloudQueryBody() throws MsoException { + wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/instanceId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(CREATE_STACK_RESPONSE) + .withStatus(HttpStatus.SC_OK))); + + StackInfo result = multicloudUtils.queryStack("MTN13", "CloudOwner", "TEST-tenant", "instanceId"); + assertTrue(HeatStatus.FAILED == result.getStatus()); + assertEquals(MULTICLOUD_QUERY_BODY_NULL, result.getStatusMessage()); + } + @Test(expected = VduException.class) public void updateVdu() throws MsoException { multicloudUtils.updateVdu(new CloudInfo(), "instanceId", new HashMap<>(), new VduModelInfo(), @@ -131,7 +169,7 @@ public class MsoMulticloudUtilsTest extends BaseTest { @Test public void createStackBadRequest() { try { - wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_PATH)) + wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withStatus(HttpStatus.SC_BAD_REQUEST))); multicloudUtils.createStack("MTN14", "CloudOwner", "TEST-tenant", "TEST-stack", new VduModelInfo(), @@ -146,7 +184,7 @@ public class MsoMulticloudUtilsTest extends BaseTest { @Test public void createStackEmptyResponseEntity() throws MsoException { - wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_PATH)) + wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withStatus(HttpStatus.SC_CREATED))); StackInfo result = multicloudUtils.createStack("MTN14", "CloudOwner", "TEST-tenant", "TEST-stack", new VduModelInfo(), diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java new file mode 100644 index 0000000000..710a6ddc13 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java @@ -0,0 +1,75 @@ +package org.onap.so.adapters.audit; + +import java.util.Optional; + +import org.camunda.bpm.client.task.ExternalTask; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +public abstract class AbstractAuditService { + + private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class); + + + + protected static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI = "Unable to find all VServers and L-Interaces in A&AI"; + + @Autowired + public Environment env; + + /** + * @param auditHeatStackFailed + * @param auditList + * @return + */ + protected boolean didCreateAuditFail(Optional<AAIObjectAuditList> auditList) { + if (auditList.get().getAuditList() != null && !auditList.get().getAuditList().isEmpty()) { + if (logger.isInfoEnabled()) { + logger.info("Audit Results: {}", auditList.get().toString()); + } + return auditList.get().getAuditList().stream().filter(auditObject -> !auditObject.isDoesObjectExist()) + .findFirst().map(v -> true).orElse(false); + } else { + return false; + } + } + + /** + * @param auditHeatStackFailed + * @param auditList + * @return + */ + protected boolean didDeleteAuditFail(Optional<AAIObjectAuditList> auditList) { + if (auditList.get().getAuditList() != null && !auditList.get().getAuditList().isEmpty()) { + if (logger.isInfoEnabled()) { + logger.info("Audit Results: {}", auditList.get().toString()); + } + return auditList.get().getAuditList().stream().filter(AAIObjectAudit::isDoesObjectExist) + .findFirst().map(v -> true).orElse(false); + } else { + return false; + } + } + + protected String[] getRetrySequence() { + return env.getProperty("mso.workflow.topics.retrySequence",String[].class); + } + + protected void setupMDC(ExternalTask externalTask) { + String msoRequestId = externalTask.getVariable("mso-request-id"); + if(msoRequestId != null && !msoRequestId.isEmpty()) + MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId); + } + + protected long calculateRetryDelay(int currentRetries){ + int retrySequence = getRetrySequence().length - currentRetries; + long retryMultiplier = Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier","6000")); + return Integer.parseInt(getRetrySequence()[retrySequence]) * retryMultiplier; + } +} diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java index da6bea7dec..5dfba25141 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java @@ -40,11 +40,9 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component -public class AuditStackServiceData { - - private static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI = "Unable to find all VServers and L-Interaces in A&AI"; - - private static final Logger logger = LoggerFactory.getLogger(AuditStackServiceData.class); +public class AuditCreateStackService extends AbstractAuditService{ + + private static final Logger logger = LoggerFactory.getLogger(AuditCreateStackService.class); @Autowired public HeatStackAudit heatStackAudit; @@ -64,7 +62,7 @@ public class AuditStackServiceData { if (auditListOpt.isPresent()) { GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); variables.put("auditInventoryResult", objectMapper.getMapper().writeValueAsString(auditListOpt.get())); - success = !didAuditFail(auditListOpt); + success = !didCreateAuditFail(auditListOpt); } } catch (Exception e) { logger.error("Error during audit of stack", e); @@ -88,35 +86,8 @@ public class AuditStackServiceData { logger.debug("The External Task Id: {} Failed", externalTask.getId()); } } - private void setupMDC(ExternalTask externalTask) { - String msoRequestId = externalTask.getVariable("mso-request-id"); - if(msoRequestId != null && !msoRequestId.isEmpty()) - MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId); - } - protected long calculateRetryDelay(int currentRetries){ - int retrySequence = getRetrySequence().length - currentRetries; - long retryMultiplier = Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier","6000")); - return Integer.parseInt(getRetrySequence()[retrySequence]) * retryMultiplier; - } + - /** - * @param auditHeatStackFailed - * @param auditList - * @return - */ - protected boolean didAuditFail(Optional<AAIObjectAuditList> auditList) { - if (auditList.get().getAuditList() != null && !auditList.get().getAuditList().isEmpty()) { - if (logger.isInfoEnabled()) { - logger.info("Audit Results: {}", auditList.get().toString()); - } - return auditList.get().getAuditList().stream().filter(auditObject -> !auditObject.isDoesObjectExist()) - .findFirst().map(v -> true).orElse(false); - } else { - return false; - } - } - public String[] getRetrySequence() { - return env.getProperty("mso.workflow.topics.retrySequence",String[].class); - } + } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDeleteStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDeleteStackService.java new file mode 100644 index 0000000000..2c2b2f810d --- /dev/null +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditDeleteStackService.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.audit; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.so.audit.beans.AuditInventory; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +public class AuditDeleteStackService extends AbstractAuditService{ + + private static final Logger logger = LoggerFactory.getLogger(AuditDeleteStackService.class); + + @Autowired + public HeatStackAudit heatStackAudit; + + @Autowired + public Environment env; + + protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService){ + AuditInventory auditInventory = externalTask.getVariable("auditInventory"); + Map<String, Object> variables = new HashMap<>(); + setupMDC(externalTask); + boolean success = false; + try { + logger.info("Executing External Task Audit Inventory, Retry Number: {} \n {}", auditInventory,externalTask.getRetries()); + Optional<AAIObjectAuditList> auditListOpt=heatStackAudit.auditHeatStack(auditInventory.getCloudRegion(), auditInventory.getCloudOwner(), + auditInventory.getTenantId(), auditInventory.getHeatStackName()); + if (auditListOpt.isPresent()) { + GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); + variables.put("auditInventoryResult", objectMapper.getMapper().writeValueAsString(auditListOpt.get())); + success = didDeleteAuditFail(auditListOpt); + } + } catch (Exception e) { + logger.error("Error during audit of stack", e); + } + variables.put("auditIsSuccessful", success); + if (success) { + externalTaskService.complete(externalTask, variables); + logger.debug("The External Task Id: {} Successful", externalTask.getId()); + } else { + if(externalTask.getRetries() == null){ + logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}", externalTask.getId(),getRetrySequence().length); + externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, getRetrySequence().length, 10000); + }else if(externalTask.getRetries() != null && + externalTask.getRetries()-1 == 0){ + logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTask.getId()); + externalTaskService.complete(externalTask); + }else{ + logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ", externalTask.getId(),externalTask.getRetries()-1, calculateRetryDelay(externalTask.getRetries())); + externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, externalTask.getRetries()-1, calculateRetryDelay(externalTask.getRetries())); + } + logger.debug("The External Task Id: {} Failed", externalTask.getId()); + } + } + +}
\ No newline at end of file diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java index 499c1137c7..1e16c2a016 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java @@ -46,10 +46,13 @@ public class AuditStackService { public Environment env; @Autowired - private AuditStackServiceData auditStack; + private AuditCreateStackService auditCreateStack; + + @Autowired + private AuditDeleteStackService auditDeleteStack; @PostConstruct - public void auditAAIInventory() { + public void auditAddAAIInventory() { String auth = ""; try { auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey")); @@ -60,9 +63,26 @@ public class AuditStackService { auth); ExternalTaskClient client = ExternalTaskClient.create() .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor) - .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(10000, 2, 120000)).build(); - client.subscribe("InventoryAudit").lockDuration(60000) - .handler(auditStack::executeExternalTask).open(); + .asyncResponseTimeout(120000).build(); + client.subscribe("InventoryAddAudit").lockDuration(60000) + .handler(auditCreateStack::executeExternalTask).open(); } - + + @PostConstruct + public void auditDeleteAAIInventory() { + String auth = ""; + try { + auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey")); + } catch (IllegalStateException | GeneralSecurityException e) { + logger.error("Error Decrypting Password", e); + } + ClientRequestInterceptor interceptor = new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), + auth); + ExternalTaskClient client = ExternalTaskClient.create() + .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor) + .asyncResponseTimeout(120000).build(); + client.subscribe("InventoryDeleteAudit").lockDuration(60000) + .handler(auditDeleteStack::executeExternalTask).open(); + } + } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java index aafcb1c600..349aa78d44 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapter.java @@ -28,6 +28,7 @@ import javax.jws.WebParam; import javax.jws.WebParam.Mode; import javax.jws.WebService; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.ws.Holder; import org.onap.so.adapters.vnf.exceptions.VnfAlreadyExists; @@ -35,6 +36,7 @@ import org.onap.so.adapters.vnf.exceptions.VnfException; import org.onap.so.entity.MsoRequest; import org.onap.so.openstack.beans.VnfRollback; import org.onap.so.openstack.beans.VnfStatus; +import org.onap.so.openstack.mappers.MapAdapter; @WebService (name="VnfAdapter", targetNamespace="http://org.onap.so/vnf") public interface MsoVnfAdapter @@ -51,7 +53,7 @@ public interface MsoVnfAdapter @WebParam(name="vnfName") @XmlElement(required=true) String vnfName, @WebParam(name="requestType") @XmlElement(required=false) String requestType, @WebParam(name="volumeGroupHeatStackId") @XmlElement(required=false) String volumeGroupHeatStackId, - @WebParam(name="inputs") Map<String,Object> inputs, + @WebParam(name="inputs") @XmlJavaTypeAdapter(MapAdapter.class) Map<String,Object> inputs, @WebParam(name="failIfExists") Boolean failIfExists, @WebParam(name="backout") Boolean backout, @WebParam(name="enableBridge") Boolean enableBridge, @@ -70,7 +72,7 @@ public interface MsoVnfAdapter @WebParam(name="vnfName") @XmlElement(required=true) String vnfName, @WebParam(name="requestType") @XmlElement(required=false) String requestType, @WebParam(name="volumeGroupHeatStackId") @XmlElement(required=false) String volumeGroupHeatStackId, - @WebParam(name="inputs") Map<String,Object> inputs, + @WebParam(name="inputs") @XmlJavaTypeAdapter(MapAdapter.class) Map<String,Object> inputs, @WebParam(name="request") MsoRequest msoRequest, @WebParam(name="outputs", mode=Mode.OUT) Holder<Map<String,String>> outputs, @WebParam(name="rollback", mode=Mode.OUT) Holder<VnfRollback> rollback ) @@ -114,7 +116,7 @@ public interface MsoVnfAdapter @WebParam(name="volumeGroupHeatStackId") @XmlElement(required=false) String volumeGroupHeatStackId, @WebParam(name="baseVfHeatStackId") @XmlElement(required=false) String baseVfHeatStackId, @WebParam(name = "modelCustomizationUuid") @XmlElement(required = false) String modelCustomizationUuid, - @WebParam(name="inputs") Map<String,Object> inputs, + @WebParam(name="inputs") @XmlJavaTypeAdapter(MapAdapter.class) Map<String,Object> inputs, @WebParam(name="failIfExists") Boolean failIfExists, @WebParam(name="backout") Boolean backout, @WebParam(name="enableBridge") Boolean enableBridge, @@ -145,7 +147,7 @@ public interface MsoVnfAdapter @WebParam(name="baseVfHeatStackId") @XmlElement(required=false) String baseVfHeatStackId, @WebParam(name="vfModuleStackId") @XmlElement(required=false) String vfModuleStackId, @WebParam(name = "modelCustomizationUuid") @XmlElement(required = false) String modelCustomizationUuid, - @WebParam(name="inputs") Map<String,Object> inputs, + @WebParam(name="inputs") @XmlJavaTypeAdapter(MapAdapter.class) Map<String,Object> inputs, @WebParam(name="request") MsoRequest msoRequest, @WebParam(name="outputs", mode=Mode.OUT) Holder<Map<String,String>> outputs, @WebParam(name="rollback", mode=Mode.OUT) Holder<VnfRollback> rollback ) diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsync.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsync.java index 70afb1c69c..5642e01a72 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsync.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsync.java @@ -28,9 +28,11 @@ import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.onap.so.entity.MsoRequest; import org.onap.so.openstack.beans.VnfRollback; +import org.onap.so.openstack.mappers.MapAdapter; /** * This webservice defines the Asynchronous versions of VNF adapter calls. @@ -54,7 +56,7 @@ public interface MsoVnfAdapterAsync @WebParam(name="vnfName") @XmlElement(required=true) String vnfName, @WebParam(name="requestType") @XmlElement(required=false) String requestType, @WebParam(name="volumeGroupHeatStackId") @XmlElement(required=false) String volumeGroupHeatStackId, - @WebParam(name="inputs") Map<String,Object> inputs, + @WebParam(name="inputs") @XmlJavaTypeAdapter(MapAdapter.class) Map<String,Object> inputs, @WebParam(name="failIfExists") Boolean failIfExists, @WebParam(name="backout") Boolean backout, @WebParam(name="enableBridge") Boolean enableBridge, @@ -72,7 +74,7 @@ public interface MsoVnfAdapterAsync @WebParam(name="vnfName") @XmlElement(required=true) String vnfName, @WebParam(name="requestType") @XmlElement(required=false) String requestType, @WebParam(name="volumeGroupHeatStackId") @XmlElement(required=false) String volumeGroupHeatStackId, - @WebParam(name="inputs") Map<String,Object> inputs, + @WebParam(name="inputs") @XmlJavaTypeAdapter(MapAdapter.class) Map<String,Object> inputs, @WebParam(name="messageId") @XmlElement(required=true) String messageId, @WebParam(name="request") MsoRequest msoRequest, @WebParam(name="notificationUrl") @XmlElement(required=true) String notificationUrl ); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactoryImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactoryImpl.java index 72b3795053..141dd4fe50 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactoryImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/factory/OpenstackClientFactoryImpl.java @@ -25,6 +25,7 @@ import org.openstack4j.api.OSClient.OSClientV2; import org.openstack4j.api.OSClient.OSClientV3; import org.openstack4j.api.exceptions.AuthenticationException; import org.openstack4j.openstack.OSFactory; +import org.openstack4j.model.common.Identifier; public class OpenstackClientFactoryImpl implements OpenstackClientFactory { @@ -35,12 +36,14 @@ public class OpenstackClientFactoryImpl implements OpenstackClientFactory { Preconditions.checkNotNull(osAccess.getPassword(), "Keystone-v3 Auth: password not set."); Preconditions.checkNotNull(osAccess.getDomainNameIdentifier(), "Keystone-v3 Auth: domain not set."); Preconditions.checkNotNull(osAccess.getRegion(), "Keystone-v3 Auth: region not set."); + Preconditions.checkNotNull(osAccess.getTenantId(), "Keystone-v3 Auth: tenant-id not set."); OSClientV3 client; try { client = OSFactory.builderV3() .endpoint(osAccess.getUrl()) .credentials(osAccess.getUser(), osAccess.getPassword(), osAccess.getDomainNameIdentifier()) + .scopeToProject(Identifier.byId(osAccess.getTenantId())) .authenticate() .useRegion(osAccess.getRegion()); return new OpenstackV3ClientImpl(client); @@ -54,7 +57,7 @@ public class OpenstackClientFactoryImpl implements OpenstackClientFactory { Preconditions.checkNotNull(osAccess.getUrl(), "Keystone-v2 Auth: endpoint not set."); Preconditions.checkNotNull(osAccess.getUser(), "Keystone-v2 Auth: username not set."); Preconditions.checkNotNull(osAccess.getPassword(), "Keystone-v2 Auth: password not set."); - Preconditions.checkNotNull(osAccess.getTenantId(), "Keystone-v2 Auth: domain not set."); + Preconditions.checkNotNull(osAccess.getTenantId(), "Keystone-v2 Auth: tenant-id not set."); Preconditions.checkNotNull(osAccess.getRegion(), "Keystone-v2 Auth: region not set."); OSClientV2 client; diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java index 29e672a4a6..1eaac18fb6 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java @@ -20,21 +20,17 @@ package org.onap.so.adapters.audit; -import static org.hamcrest.CoreMatchers.isA; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.doReturn; import java.io.File; import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; import java.util.Map; import java.util.Optional; import org.camunda.bpm.client.task.ExternalTask; import org.camunda.bpm.client.task.ExternalTaskService; -import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -42,17 +38,17 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.onap.aai.domain.yang.LInterface; import org.onap.so.audit.beans.AuditInventory; import org.springframework.core.env.Environment; + import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -public class AuditStackServiceDataTest extends AuditStackServiceData { +public class AuditStackServiceDataTest extends AuditCreateStackService { @InjectMocks - private AuditStackServiceData auditStackService = new AuditStackServiceData(); + private AuditCreateStackService auditStackService = new AuditCreateStackService(); @Mock private HeatStackAudit heatStackAuditMock; @@ -191,13 +187,13 @@ public class AuditStackServiceDataTest extends AuditStackServiceData { @Test public void determineAuditResult_Test() throws Exception{ - boolean actual = auditStackService.didAuditFail(auditListOptSuccess); + boolean actual = auditStackService.didCreateAuditFail(auditListOptSuccess); assertEquals(false, actual); } @Test public void determineAuditResult_Failure_Test() throws Exception{ - boolean actual = auditStackService.didAuditFail(auditListOptFailure); + boolean actual = auditStackService.didCreateAuditFail(auditListOptFailure); assertEquals(true, actual); } } |