diff options
author | Byung-Woo Jun <byung-woo.jun@est.tech> | 2020-10-14 11:41:29 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-10-14 11:41:29 +0000 |
commit | 0e4c38d31cf2d5c1b25b05357c7de6af19b61f2e (patch) | |
tree | 35fd267c96d1da444922257081fdd451bb2e5b82 /so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java | |
parent | ad7173bcd94e6e310f258cb4f3d584c4bc25a80d (diff) | |
parent | 1d12326d47c541934fd0ee3376844a159941a9ef (diff) |
Merge "SO-ETSI-NFVO Get NS Operation Status Backend Service"
Diffstat (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java')
2 files changed, 145 insertions, 1 deletions
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLcmOperationOccurrenceManager.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLcmOperationOccurrenceManager.java new file mode 100644 index 0000000000..8a5cee6d75 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLcmOperationOccurrenceManager.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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========================================================= + */ +package org.onap.so.etsi.nfvo.ns.lcm.lifecycle; + +import static org.slf4j.LoggerFactory.getLogger; +import org.onap.so.etsi.nfvo.ns.lcm.EtsiSoNsLcmManagerUrlProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstanceLinksSelf; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOccLinks; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import java.util.Optional; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +@Service +public class NsLcmOperationOccurrenceManager { + + private static final Logger logger = getLogger(NsLcmOperationOccurrenceManager.class); + + private final DatabaseServiceProvider databaseServiceProvider; + private final EtsiSoNsLcmManagerUrlProvider etsiSoNsLcmManagerUrlProvider; + + @Autowired + public NsLcmOperationOccurrenceManager(final DatabaseServiceProvider databaseServiceProvider, + final EtsiSoNsLcmManagerUrlProvider etsiSoNsLcmManagerUrlProvider) { + this.databaseServiceProvider = databaseServiceProvider; + this.etsiSoNsLcmManagerUrlProvider = etsiSoNsLcmManagerUrlProvider; + } + + public Optional<NsLcmOpOccsNsLcmOpOcc> getNsLcmOperationOccurrence(final String nsLcmOpOccId) { + logger.info("Getting NS LCM Operation Occurrence Operation for id: {}", nsLcmOpOccId); + final Optional<NsLcmOpOcc> optionalNsLcmOpOcc = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOccId); + + if (optionalNsLcmOpOcc.isEmpty()) { + logger.info("No NS LCM Operation Occurrence found for id: {}", nsLcmOpOccId); + return Optional.empty(); + } + + logger.info("Found NS LCM Operation Occurrence for id: {}", nsLcmOpOccId); + final NsLcmOpOcc nsLcmOpOcc = optionalNsLcmOpOcc.get(); + final NsLcmOpOccsNsLcmOpOcc nsLcmOpOccsNsLcmOpOcc = convertToNsLcmOpOccsNsLcmOpOcc(nsLcmOpOcc); + return Optional.of(nsLcmOpOccsNsLcmOpOcc); + } + + private NsLcmOpOccsNsLcmOpOcc convertToNsLcmOpOccsNsLcmOpOcc(final NsLcmOpOcc nsLcmOpOcc) { + logger.info("Converting Database NsLcmOpOcc to API NsLcmOpOcc... "); + final NsLcmOpOccsNsLcmOpOcc nsLcmOpOccsNsLcmOpOcc = + new NsLcmOpOccsNsLcmOpOcc().id(nsLcmOpOcc.getId()).statusEnteredTime(nsLcmOpOcc.getStateEnteredTime()) + .startTime(nsLcmOpOcc.getStartTime()).isAutomaticInvocation(nsLcmOpOcc.getIsAutoInvocation()) + .isCancelPending(nsLcmOpOcc.getIsCancelPending()); + + if (nsLcmOpOcc.getNfvoNsInst() != null) { + nsLcmOpOccsNsLcmOpOcc.setNsInstanceId(nsLcmOpOcc.getNfvoNsInst().getNsInstId()); + } + + if (nsLcmOpOcc.getOperationState() != null) { + nsLcmOpOccsNsLcmOpOcc.setOperationState( + NsLcmOpOccsNsLcmOpOcc.OperationStateEnum.fromValue(nsLcmOpOcc.getOperationState().toString())); + } + + if (nsLcmOpOcc.getOperation() != null) { + nsLcmOpOccsNsLcmOpOcc.setLcmOperationType( + NsLcmOpOccsNsLcmOpOcc.LcmOperationTypeEnum.fromValue(nsLcmOpOcc.getOperation().toString())); + } + + if (nsLcmOpOcc.getOperationParams() != null) { + nsLcmOpOccsNsLcmOpOcc.setOperationParams(nsLcmOpOcc.getOperationParams()); + } + + if (nsLcmOpOcc.getCancelMode() != null) { + nsLcmOpOccsNsLcmOpOcc.setCancelMode( + NsLcmOpOccsNsLcmOpOcc.CancelModeEnum.fromValue(nsLcmOpOcc.getCancelMode().toString())); + } + + nsLcmOpOccsNsLcmOpOcc.setLinks(generateLinks(nsLcmOpOcc)); + + logger.info("Database NsLcmOpOcc converted to API NsLcmOpOcc successfully... {}", nsLcmOpOccsNsLcmOpOcc); + return nsLcmOpOccsNsLcmOpOcc; + } + + private NsLcmOpOccsNsLcmOpOccLinks generateLinks(final NsLcmOpOcc nsLcmOpOcc) { + logger.info("Generating links..."); + final String nsLcmOpOccId = nsLcmOpOcc.getId(); + final NsInstancesNsInstanceLinksSelf linksSelfNsLcmOpOcc = new NsInstancesNsInstanceLinksSelf() + .href(etsiSoNsLcmManagerUrlProvider.getNsLcmOpOccUri(nsLcmOpOccId).toString()); + final NsLcmOpOccsNsLcmOpOccLinks links = new NsLcmOpOccsNsLcmOpOccLinks().self(linksSelfNsLcmOpOcc); + + if (nsLcmOpOcc.getNfvoNsInst() != null) { + final String nsInstId = nsLcmOpOcc.getNfvoNsInst().getNsInstId(); + final NsInstancesNsInstanceLinksSelf linksSelfNsInst = new NsInstancesNsInstanceLinksSelf() + .href(etsiSoNsLcmManagerUrlProvider.getCreatedNsResourceUri(nsInstId).toString()); + links.setNsInstance(linksSelfNsInst); + } + + return links; + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesController.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesController.java index ec79ce6329..207f0ff387 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesController.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesController.java @@ -22,20 +22,25 @@ package org.onap.so.etsi.nfvo.ns.lcm.rest; import static org.onap.so.etsi.nfvo.ns.lcm.Constants.NS_LIFE_CYCLE_MANAGEMENT_BASE_URL; import static org.slf4j.LoggerFactory.getLogger; import javax.ws.rs.core.MediaType; +import org.onap.so.etsi.nfvo.ns.lcm.lifecycle.NsLcmOperationOccurrenceManager; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOcc; import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import java.util.Optional; /** * Controller for handling NS lifecycle management operation occurrence requests see clause 6.4.9 and 6.4.10 in * https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/005/02.07.01_60/gs_NFV-SOL005v020701p.pdf * * @author Waqas Ikram (waqas.ikram@est.tech) + * @author Andrew Lamb (andrew.a.lamb@est.tech) * */ @Controller @@ -43,6 +48,12 @@ import org.springframework.web.bind.annotation.RequestMapping; public class NsLcmOperationOccurrencesController { private static final Logger logger = getLogger(NsLcmOperationOccurrencesController.class); + private final NsLcmOperationOccurrenceManager nsLcmOperationOccurrenceManager; + + @Autowired + public NsLcmOperationOccurrencesController(final NsLcmOperationOccurrenceManager nsLcmOperationOccurrenceManager) { + this.nsLcmOperationOccurrenceManager = nsLcmOperationOccurrenceManager; + } /** * The GET method to retrieve status information about a NS lifecycle management operation occurrence by reading an @@ -57,7 +68,18 @@ public class NsLcmOperationOccurrencesController { produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> getOperationStatus(@PathVariable("nsLcmOpOccId") final String nsLcmOpOccId) { logger.info("Received request to retrieve operation status for nsLcmOpOccId: {}", nsLcmOpOccId); - return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet"); + final Optional<NsLcmOpOccsNsLcmOpOcc> optionalNsLcmOpOccs = + nsLcmOperationOccurrenceManager.getNsLcmOperationOccurrence(nsLcmOpOccId); + + if (optionalNsLcmOpOccs.isPresent()) { + final NsLcmOpOccsNsLcmOpOcc nsLcmOpOcc = optionalNsLcmOpOccs.get(); + logger.info("Sending back NsLcmOpOcc: {}", nsLcmOpOcc); + return ResponseEntity.ok().body(nsLcmOpOcc); + } + + final String errorMessage = "Unable to retrieve operation occurrence status for nsLcmOpOccId: " + nsLcmOpOccId; + logger.error(errorMessage); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new InlineResponse400().detail(errorMessage)); } } |