From 6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 31 Dec 2018 17:21:27 +0200 Subject: Merge from ECOMP's repository Main Features -------------- - Async-Instantiation jobs mechanism major update; still WIP (package `org.onap.vid.job`) - New features in View/Edit: Activate fabric configuration; show related networks; soft delete - Support AAI service-tree traversal (`AAIServiceTree`) - In-memory cache for SDC models and certain A&AI queries (`CacheProviderWithLoadingCache`) - Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA models - Resolve Cloud-Owner values for MSO - Pass X-ONAP headers to MSO Infrastructure -------------- - Remove codehaus' jackson mapper; use soley fasterxml 2.9.7 - Surefire invokes both TestNG and JUnit tests - Support Kotlin source files - AaiController2 which handles errors in a "Spring manner" - Inline generated-sources and remove jsonschema2pojo Quality -------- - Cumulative bug fixes (A&AI API, UI timeouts, and many more) - Many Sonar issues cleaned-up - Some unused classes removed - Minor changes in vid-automation project, allowing some API verification to run Hard Merges ------------ - HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest) - Moved `package org.onap.vid.controllers` to `controller`, without plural -- just to keep semantic sync with ECOMP. Reference commit in ECOMP: 3d1141625 Issue-ID: VID-378 Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788 Signed-off-by: Ittay Stern --- .../job/command/ServiceInstantiationCommand.java | 146 ++++++--------------- 1 file changed, 41 insertions(+), 105 deletions(-) (limited to 'vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java') diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java index 958fc115e..b40b7015c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java @@ -1,170 +1,106 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2018 Nokia. 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.vid.job.command; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; -import io.joshworks.restclient.http.HttpResponse; -import org.onap.vid.aai.exceptions.InvalidAAIResponseException; +import org.apache.commons.lang3.ObjectUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.exceptions.MaxRetriesException; import org.onap.vid.job.Job; import org.onap.vid.job.JobCommand; import org.onap.vid.job.NextCommand; +import org.onap.vid.job.impl.JobSharedData; import org.onap.vid.model.RequestReferencesContainer; import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; -import org.onap.vid.mso.MsoInterface; +import org.onap.vid.mso.RestMsoImplementation; +import org.onap.vid.mso.RestObject; import org.onap.vid.mso.model.ServiceInstantiationRequestDetails; import org.onap.vid.services.AsyncInstantiationBusinessLogic; -import org.onap.vid.services.AuditService; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; import javax.inject.Inject; import java.util.Map; -import java.util.Objects; -import java.util.UUID; -@Component -@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ServiceInstantiationCommand implements JobCommand { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); +public abstract class ServiceInstantiationCommand extends BaseRootCommand implements JobCommand { private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ServiceInstantiationCommand.class); @Inject - private AsyncInstantiationBusinessLogic asyncInstantiationBL; - - @Inject - private AuditService auditService; + protected AsyncInstantiationBusinessLogic asyncInstantiationBL; @Inject - private MsoInterface restMso; + private RestMsoImplementation restMso; - private UUID uuid; - private ServiceInstantiation serviceInstantiationRequest; - private String userId; + protected String optimisticUniqueServiceInstanceName; public ServiceInstantiationCommand() { } - public ServiceInstantiationCommand(UUID uuid, ServiceInstantiation serviceInstantiationRequest, String userId) { - init(uuid, serviceInstantiationRequest, userId); - } - - ServiceInstantiationCommand(AsyncInstantiationBusinessLogic asyncInstantiationBL, AuditService auditService, MsoInterface msoInterface, - UUID uuid, ServiceInstantiation serviceInstantiation, String userId) { - this(uuid, serviceInstantiation, userId); - this.asyncInstantiationBL = asyncInstantiationBL; - this.auditService = auditService; - this.restMso = msoInterface; - } - @Override public NextCommand call() { RequestDetailsWrapper requestDetailsWrapper ; try { - requestDetailsWrapper = asyncInstantiationBL.generateServiceInstantiationRequest( - uuid, serviceInstantiationRequest, userId - ); + requestDetailsWrapper = generateServiceInstantiationRequest(); } + //Aai return bad response while checking names uniqueness - catch (InvalidAAIResponseException exception) { - LOGGER.error("Failed to check name uniqueness in AAI. VID will try again later", exception); - //put the job in_progress so we will keep trying to check name uniqueness in AAI - //And then send the request to MSO - return new NextCommand(Job.JobStatus.IN_PROGRESS, this); + catch (ExceptionWithRequestInfo exception) { + return handleAaiNameUniquenessBadResponse(exception); } //Vid reached to max retries while trying to find unique name in AAI catch (MaxRetriesException exception) { - LOGGER.error("Failed to find unused name in AAI. Set the job to FAILED ", exception); - return handleCommandFailed(); + return handleMaxRetryInNameUniqueness(exception); } - String path = asyncInstantiationBL.getServiceInstantiationPath(serviceInstantiationRequest); + String path = asyncInstantiationBL.getServiceInstantiationPath(getRequest()); - HttpResponse msoResponse = restMso.post(path, - requestDetailsWrapper, RequestReferencesContainer.class); + RestObject msoResponse = restMso.PostForObject(requestDetailsWrapper, + path, RequestReferencesContainer.class); + return handleRootResponse(msoResponse); - if (msoResponse.getStatus() >= 200 && msoResponse.getStatus() < 400) { - final Job.JobStatus jobStatus = Job.JobStatus.IN_PROGRESS; - final String requestId = msoResponse.getBody().getRequestReferences().getRequestId(); - final String instanceId = msoResponse.getBody().getRequestReferences().getInstanceId(); - asyncInstantiationBL.auditVidStatus(uuid, jobStatus); - setInitialRequestAuditStatusFromMso(requestId); - asyncInstantiationBL.updateServiceInfo(uuid, x-> { - x.setJobStatus(jobStatus); - x.setServiceInstanceId(instanceId); - }); - - return new NextCommand(jobStatus, new InProgressStatusCommand(uuid, requestId)); - } else { - auditService.setFailedAuditStatusFromMso(uuid,null, msoResponse.getStatus(), - Objects.toString(msoResponse.getBody())); - return handleCommandFailed(); - } + } + @Override + protected ServiceInstantiation getRequest() { + return (ServiceInstantiation) getSharedData().getRequest(); } - private void setInitialRequestAuditStatusFromMso(String requestId){ - final String initialMsoRequestStatus = "REQUESTED"; - asyncInstantiationBL.auditMsoStatus(uuid,initialMsoRequestStatus,requestId,null); + protected abstract RequestDetailsWrapper generateServiceInstantiationRequest(); + + private NextCommand handleMaxRetryInNameUniqueness(MaxRetriesException exception) { + LOGGER.error("Failed to find unused name in AAI. Set the job to FAILED ", exception); + return handleCommandFailed(); } - protected NextCommand handleCommandFailed() { - asyncInstantiationBL.handleFailedInstantiation(uuid); - return new NextCommand(Job.JobStatus.FAILED); + private NextCommand handleAaiNameUniquenessBadResponse(ExceptionWithRequestInfo exception) { + LOGGER.error("Failed to check name uniqueness in AAI. VID will try again later", exception); + //put the job in_progress so we will keep trying to check name uniqueness in AAI + //And then send the request to MSO + return new NextCommand(Job.JobStatus.IN_PROGRESS, this); } @Override - public ServiceInstantiationCommand init(UUID jobUuid, Map data) { - final Object request = data.get("request"); + public ServiceInstantiationCommand init(JobSharedData sharedData, Map commandData) { return init( - jobUuid, - OBJECT_MAPPER.convertValue(request, ServiceInstantiation.class), - (String) data.get("userId") + sharedData, + (String) commandData.get("optimisticUniqueServiceInstanceName") ); } - private ServiceInstantiationCommand init(UUID jobUuid, ServiceInstantiation serviceInstantiationRequest, String userId) { - this.uuid = jobUuid; - this.serviceInstantiationRequest = serviceInstantiationRequest; - this.userId = userId; - + protected ServiceInstantiationCommand init(JobSharedData sharedData, String optimisticUniqueServiceInstanceName) { + init(sharedData); + this.optimisticUniqueServiceInstanceName = ObjectUtils.defaultIfNull(optimisticUniqueServiceInstanceName, + (getRequest()).getInstanceName()); return this; } @Override public Map getData() { return ImmutableMap.of( - "uuid", uuid, - "request", serviceInstantiationRequest, - "userId", userId + "optimisticUniqueServiceInstanceName", optimisticUniqueServiceInstanceName ); } } -- cgit 1.2.3-korg