summaryrefslogtreecommitdiffstats
path: root/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl')
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java273
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java201
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java133
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java109
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalCnNssmfManager.java53
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalAnNssmfManager.java54
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalCnNssmfManager.java56
-rw-r--r--adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalTnNssmfManager.java42
8 files changed, 921 insertions, 0 deletions
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java
new file mode 100644
index 0000000000..185dfaff34
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/BaseNssmfManager.java
@@ -0,0 +1,273 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.nssmf.manager.impl;
+
+import org.onap.so.adapters.nssmf.config.NssmfAdapterConfig;
+import org.onap.so.adapters.nssmf.consts.NssmfAdapterConsts;
+import org.onap.so.adapters.nssmf.entity.NssmfUrlInfo;
+import org.onap.so.adapters.nssmf.enums.*;
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
+import org.onap.so.adapters.nssmf.entity.RestResponse;
+import org.onap.so.adapters.nssmf.manager.NssmfManager;
+import org.onap.so.adapters.nssmf.util.RestUtil;
+import org.onap.so.beans.nsmf.*;
+import org.onap.so.db.request.beans.ResourceOperationStatus;
+import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.data.domain.Example;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.ALLOCATE_NSS_SUCCESS;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.MODIFY_NSS_SUCCESS;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
+
+public abstract class BaseNssmfManager implements NssmfManager {
+
+ private static final Logger logger = LoggerFactory.getLogger(BaseNssmfManager.class);
+
+ protected RestUtil restUtil;
+
+ protected ResourceOperationStatusRepository repository;
+
+ protected NssmfAdapterConfig adapterConfig;
+
+ protected ActionType actionType;
+
+ protected EsrInfo esrInfo;
+
+ protected String nssmfUrl;
+
+ protected HttpMethod httpMethod;
+
+ protected String initStatus;
+
+ protected ServiceInfo serviceInfo;
+
+ protected RestResponse restResponse;
+
+ private ExecutorType executorType = ExecutorType.INTERNAL;
+
+ private Map<String, String> params = new HashMap<>(); // request params
+
+ @Override
+ public RestResponse allocateNssi(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+
+ this.params.clear();
+ this.urlHandler();
+ String requestBody = wrapAllocateReqBody(nbiRequest);
+
+ this.restResponse = sendRequest(requestBody);
+
+ this.afterRequest();
+
+ return restResponse;
+ }
+
+ protected abstract String wrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException;
+
+ @Override
+ public RestResponse modifyNssi(NssmfAdapterNBIRequest modifyRequest) throws ApplicationException {
+ this.params.clear();
+ this.urlHandler();
+ String requestBody = wrapModifyReqBody(modifyRequest);
+
+ this.restResponse = sendRequest(requestBody);
+
+ this.afterRequest();
+
+ return restResponse;
+ }
+
+ protected abstract String wrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException;
+
+ @Override
+ public RestResponse deAllocateNssi(NssmfAdapterNBIRequest nbiRequest, String sliceId) throws ApplicationException {
+ this.params.clear();
+ this.params.put("sliceProfileId", sliceId);
+
+ this.urlHandler();
+
+ String reqBody = wrapDeAllocateReqBody(nbiRequest.getDeAllocateNssi());
+
+ this.restResponse = sendRequest(reqBody);
+
+ this.afterRequest();
+
+ return restResponse;
+ }
+
+ protected abstract String wrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException;
+
+ protected abstract String wrapReqBody(Object object) throws ApplicationException;
+
+ @Override
+ public RestResponse activateNssi(NssmfAdapterNBIRequest nbiRequest, String snssai) throws ApplicationException {
+ this.params.clear();
+ this.params.put("snssai", snssai);
+
+ this.urlHandler();
+
+ String reqBody = wrapActDeActReqBody(nbiRequest.getActDeActNssi());
+
+ this.restResponse = sendRequest(reqBody);
+
+ this.afterRequest();
+
+ return restResponse;
+ }
+
+ @Override
+ public RestResponse deActivateNssi(NssmfAdapterNBIRequest nbiRequest, String snssai) throws ApplicationException {
+ return activateNssi(nbiRequest, snssai);
+ }
+
+ protected abstract String wrapActDeActReqBody(ActDeActNssi actDeActNssi) throws ApplicationException;
+
+ @Override
+ public RestResponse queryJobStatus(NssmfAdapterNBIRequest jobReq, String jobId) throws ApplicationException {
+ this.params.clear();
+ this.params.put("jobId", jobId);
+ this.params.put("responseId", jobReq.getResponseId());
+ this.urlHandler();
+
+ /**
+ * find by jobId and nsiId jobId -> OperationId nsiId -> ServiceId serviceUuid -> resourceTemplateUUID
+ */
+ ResourceOperationStatus status =
+ getOperationStatus(serviceInfo.getNsiId(), jobId, serviceInfo.getServiceUuid());
+
+ this.restResponse = doQueryJobStatus(status);
+
+ afterQueryJobStatus(status);
+ return restResponse;
+ }
+
+ protected abstract RestResponse doQueryJobStatus(ResourceOperationStatus status) throws ApplicationException;
+
+
+ protected abstract void afterQueryJobStatus(ResourceOperationStatus status);
+
+ private ResourceOperationStatus getOperationStatus(String nsiId, String jobId, String serviceUuid) {
+
+ ResourceOperationStatus status = new ResourceOperationStatus(nsiId, jobId, serviceUuid);
+
+ Optional<ResourceOperationStatus> optional = repository.findOne(Example.of(status));
+
+ return optional.orElse(null);
+ }
+
+ @Override
+ public RestResponse queryNSSISelectionCapability(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ SelectionType res = doQueryNSSISelectionCapability();
+ HashMap<String, String> hashMap = new HashMap<>();
+ hashMap.put("selection", res.name());
+ RestResponse restResponse = new RestResponse();
+ restResponse.setStatus(200);
+ restResponse.setResponseContent(marshal(hashMap));
+ return restResponse;
+ }
+
+ protected abstract SelectionType doQueryNSSISelectionCapability();
+
+ @Override
+ public RestResponse querySubnetCapability(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ this.params.clear();
+ this.urlHandler();
+
+ return doQuerySubnetCapability(nbiRequest.getSubnetCapabilityQuery());
+ }
+
+ protected abstract RestResponse doQuerySubnetCapability(String req) throws ApplicationException;
+
+ /**
+ * send request to nssmf
+ *
+ * @param content request body
+ * @return response
+ * @throws ApplicationException
+ */
+ protected abstract RestResponse sendRequest(String content) throws ApplicationException;
+
+ /**
+ * handle the url before request to nssmf, include get the nssmf request url, replace the path variable
+ */
+ private void urlHandler() {
+ NssmfUrlInfo nssmfUrlInfo =
+ NssmfAdapterConsts.getNssmfUrlInfo(this.executorType, this.esrInfo.getNetworkType(), actionType);
+ this.nssmfUrl = nssmfUrlInfo.getUrl();
+ this.httpMethod = nssmfUrlInfo.getHttpMethod();
+ this.nssmfUrl = nssmfUrl.replaceAll("\\{apiVersion}", getApiVersion());
+ this.params.forEach((k, v) -> this.nssmfUrl = this.nssmfUrl.replaceAll("\\{" + k + "}", v));
+ }
+
+ /**
+ * after request
+ */
+ protected abstract void afterRequest() throws ApplicationException;
+
+ protected abstract String getApiVersion();
+
+ public RestUtil getRestUtil() {
+ return restUtil;
+ }
+
+ public BaseNssmfManager setEsrInfo(EsrInfo esrInfo) {
+ this.esrInfo = esrInfo;
+ return this;
+ }
+
+ public BaseNssmfManager setExecutorType(ExecutorType executorType) {
+ this.executorType = executorType;
+ return this;
+ }
+
+ public BaseNssmfManager setRestUtil(RestUtil restUtil) {
+ this.restUtil = restUtil;
+ return this;
+ }
+
+ public BaseNssmfManager setActionType(ActionType actionType) {
+ this.actionType = actionType;
+ return this;
+ }
+
+ public BaseNssmfManager setRepository(ResourceOperationStatusRepository repository) {
+ this.repository = repository;
+ return this;
+ }
+
+ public BaseNssmfManager setServiceInfo(ServiceInfo serviceInfo) {
+ this.serviceInfo = serviceInfo;
+ return this;
+ }
+
+ public BaseNssmfManager setInitStatus(String initStatus) {
+ this.initStatus = initStatus;
+ return this;
+ }
+
+ public BaseNssmfManager setAdapterConfig(NssmfAdapterConfig adapterConfig) {
+ this.adapterConfig = adapterConfig;
+ return this;
+ }
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java
new file mode 100644
index 0000000000..f6584da931
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/ExternalNssmfManager.java
@@ -0,0 +1,201 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.nssmf.manager.impl;
+
+import org.apache.http.Header;
+import org.apache.http.message.BasicHeader;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.so.adapters.nssmf.entity.NssmfInfo;
+import org.onap.so.adapters.nssmf.entity.RestResponse;
+import org.onap.so.adapters.nssmf.enums.JobStatus;
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
+import org.onap.so.adapters.nssmf.util.NssmfAdapterUtil;
+import org.onap.so.beans.nsmf.*;
+import org.onap.so.db.request.beans.ResourceOperationStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static java.lang.String.valueOf;
+import static org.onap.so.adapters.nssmf.enums.JobStatus.*;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.*;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal;
+
+public abstract class ExternalNssmfManager extends BaseNssmfManager {
+
+ private static final Logger logger = LoggerFactory.getLogger(ExternalNssmfManager.class);
+
+ @Override
+ protected String wrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ return doWrapExtAllocateReqBody(nbiRequest);
+ }
+
+ protected abstract String doWrapExtAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException;
+
+ @Override
+ protected String wrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ return doWrapModifyReqBody(nbiRequest);
+ }
+
+ protected abstract String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException;
+
+ @Override
+ protected String wrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException {
+ return doWrapDeAllocateReqBody(deAllocateNssi);
+ }
+
+ protected abstract String doWrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException;
+
+ @Override
+ protected void afterQueryJobStatus(ResourceOperationStatus status) {
+ if (Integer.parseInt(status.getProgress()) == 100) {
+
+ ServiceInstance nssiInstance = new ServiceInstance();
+ nssiInstance.setServiceInstanceId(serviceInfo.getNssiId());
+ nssiInstance.setServiceInstanceName(serviceInfo.getNssiName());
+ nssiInstance.setServiceType(serviceInfo.getSST());
+
+ nssiInstance.setOrchestrationStatus(initStatus);
+ nssiInstance.setModelInvariantId(serviceInfo.getServiceInvariantUuid());
+ nssiInstance.setModelVersionId(serviceInfo.getServiceUuid());
+ nssiInstance.setServiceInstanceLocationId(serviceInfo.getPLMNIdList());
+ nssiInstance.setEnvironmentContext(esrInfo.getNetworkType().getNetworkType());
+ nssiInstance.setServiceRole("nssi");
+
+ restUtil.createServiceInstance(nssiInstance, serviceInfo);
+ }
+ }
+
+
+
+ @Override
+ protected String wrapActDeActReqBody(ActDeActNssi actDeActNssi) throws ApplicationException {
+ return marshal(actDeActNssi);
+ }
+
+ protected RestResponse doQueryJobStatus(ResourceOperationStatus status) throws ApplicationException {
+ return doResponseStatus(status);
+ }
+
+ private RestResponse doResponseStatus(ResourceOperationStatus status) throws ApplicationException {
+ RestResponse restResponse = sendRequest(null);
+ ResponseDescriptor rspDesc =
+ unMarshal(restResponse.getResponseContent(), JobStatusResponse.class).getResponseDescriptor();
+ updateRequestDbJobStatus(rspDesc, status, restResponse);
+ return restResponse;
+ }
+
+ @Override
+ protected String wrapReqBody(Object object) throws ApplicationException {
+ return marshal(object);
+ }
+
+ @Override
+ protected RestResponse sendRequest(String content) throws ApplicationException {
+ return sendExternalRequest(content);
+ }
+
+ protected void createStatus(JobStatus jobStatus) throws ApplicationException {
+ if (valueOf(restResponse.getStatus()).startsWith("2")) {
+ logger.info("save segment and operaton info -> begin");
+ NssiResponse response = unMarshal(restResponse.getResponseContent(), NssiResponse.class);
+ ResourceOperationStatus status = new ResourceOperationStatus(serviceInfo.getNsiId(), response.getJobId(),
+ serviceInfo.getServiceUuid());
+ status.setResourceInstanceID(response.getNssiId());
+
+ updateDbStatus(status, restResponse.getStatus(), jobStatus, NssmfAdapterUtil.getStatusDesc(actionType));
+ logger.info("save segment and operaton info -> end");
+ }
+ }
+
+ @Override
+ protected String getApiVersion() {
+ return "v1";
+ }
+
+
+ // external
+ protected RestResponse sendExternalRequest(String content) throws ApplicationException {
+ NssmfInfo nssmfInfo = restUtil.getNssmfHost(esrInfo);
+ Header header = new BasicHeader("X-Auth-Token", restUtil.getToken(nssmfInfo));
+ String nssmfUrl = nssmfInfo.getUrl() + this.nssmfUrl;
+ return restUtil.send(nssmfUrl, this.httpMethod, content, header);
+ }
+
+ private void updateRequestDbJobStatus(ResponseDescriptor rspDesc, ResourceOperationStatus status, RestResponse rsp)
+ throws ApplicationException {
+
+ switch (fromString(rspDesc.getStatus())) {
+ case STARTED:
+ updateDbStatus(status, rsp.getStatus(), STARTED, QUERY_JOB_STATUS_SUCCESS);
+ break;
+ case PROCESSING:
+ updateDbStatus(status, rsp.getStatus(), PROCESSING, QUERY_JOB_STATUS_SUCCESS);
+ break;
+ case FINISHED:
+ if (rspDesc.getProgress() == 100) {
+ updateDbStatus(status, rsp.getStatus(), FINISHED, QUERY_JOB_STATUS_SUCCESS);
+ }
+ break;
+ case ERROR:
+ updateDbStatus(status, rsp.getStatus(), ERROR, QUERY_JOB_STATUS_FAILED);
+ throw new ApplicationException(500, QUERY_JOB_STATUS_FAILED);
+ }
+ }
+
+ protected void updateDbStatus(ResourceOperationStatus status, int rspStatus, JobStatus jobStatus,
+ String description) {
+ status.setErrorCode(valueOf(rspStatus));
+ status.setStatus(jobStatus.toString());
+ status.setStatusDescription(description);
+ logger.info("Updating DB status");
+ repository.save(status);
+ logger.info("Updating successful");
+ }
+
+ @Override
+ protected RestResponse doQuerySubnetCapability(String req) throws ApplicationException {
+ RestResponse response = new RestResponse();
+ response.setStatus(200);
+ response.setResponseContent(null);
+ return response;
+ }
+
+ /**
+ * after request, if response code is 2XX, continue handle, else return
+ */
+ @Override
+ protected void afterRequest() throws ApplicationException {
+ if (valueOf(restResponse.getStatus()).startsWith("2")) {
+ doAfterRequest();
+ }
+ }
+
+
+ protected void doAfterRequest() throws ApplicationException {
+ //
+ NssiResponse response = unMarshal(restResponse.getResponseContent(), NssiResponse.class);
+ ResourceOperationStatus status =
+ new ResourceOperationStatus(serviceInfo.getNsiId(), response.getJobId(), serviceInfo.getServiceUuid());
+ status.setResourceInstanceID(response.getNssiId());
+
+ updateDbStatus(status, restResponse.getStatus(), STARTED, NssmfAdapterUtil.getStatusDesc(actionType));
+ }
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java
new file mode 100644
index 0000000000..a945823f99
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/InternalNssmfManager.java
@@ -0,0 +1,133 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.nssmf.manager.impl;
+
+import org.apache.http.Header;
+import org.apache.http.message.BasicHeader;
+import org.onap.so.adapters.nssmf.consts.NssmfAdapterConsts;
+import org.onap.so.adapters.nssmf.entity.RestResponse;
+import org.onap.so.adapters.nssmf.enums.JobStatus;
+import org.onap.so.adapters.nssmf.enums.SelectionType;
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
+import org.onap.so.beans.nsmf.*;
+import org.onap.so.db.request.beans.ResourceOperationStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static org.onap.so.adapters.nssmf.enums.JobStatus.PROCESSING;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
+
+public abstract class InternalNssmfManager extends BaseNssmfManager {
+
+ private static final Logger logger = LoggerFactory.getLogger(InternalNssmfManager.class);
+
+ @Override
+ protected String wrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ return doWrapAllocateReqBody(nbiRequest);
+ }
+
+ protected abstract String doWrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException;
+
+ @Override
+ protected String wrapReqBody(Object object) throws ApplicationException {
+ NssmfRequest nssmfRequest = new NssmfRequest(serviceInfo, esrInfo.getNetworkType(), object);
+ return marshal(nssmfRequest);
+ }
+
+
+ @Override
+ protected String wrapActDeActReqBody(ActDeActNssi actDeActNssi) throws ApplicationException {
+
+ return wrapReqBody(actDeActNssi);
+ }
+
+
+ @Override
+ protected String wrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException {
+ return wrapReqBody(deAllocateNssi);
+ }
+
+
+ @Override
+ protected RestResponse doQueryJobStatus(ResourceOperationStatus status) throws ApplicationException {
+ return responseDBStatus(status);
+ }
+
+ private RestResponse responseDBStatus(ResourceOperationStatus status) throws ApplicationException {
+ ResponseDescriptor descriptor = new ResponseDescriptor();
+ if (status == null) {
+ descriptor.setProgress(0);
+ descriptor.setStatus(PROCESSING.name());
+ descriptor.setStatusDescription("Initiating Nssi Instance");
+ return restUtil.createResponse(200, marshal(descriptor));
+ }
+ descriptor.setStatus(status.getStatus());
+ descriptor.setStatusDescription(status.getStatusDescription());
+ descriptor.setProgress(Integer.parseInt(status.getProgress()));
+ // descriptor.setResponseId(status.getOperationId());
+ return restUtil.createResponse(200, marshal(descriptor));
+ }
+
+ @Override
+ protected RestResponse sendRequest(String content) {
+ return sendInternalRequest(content);
+ }
+
+ @Override
+ protected void afterRequest() {
+ //
+ }
+
+ @Override
+ protected void afterQueryJobStatus(ResourceOperationStatus status) {
+ // internal
+ }
+
+ // internal
+ private RestResponse sendInternalRequest(String content) {
+ Header header = new BasicHeader("X-Auth-Token", adapterConfig.getInfraAuth());
+ this.nssmfUrl = adapterConfig.getInfraEndpoint() + this.nssmfUrl;
+ return restUtil.send(this.nssmfUrl, this.httpMethod, content, header);
+ }
+
+ @Override
+ protected String getApiVersion() {
+ return NssmfAdapterConsts.CURRENT_INTERNAL_NSSMF_API_VERSION;
+ }
+
+
+ @Override
+ protected SelectionType doQueryNSSISelectionCapability() {
+ return SelectionType.NSSMF;
+ }
+
+ @Override
+ protected String wrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ return doWrapModifyReqBody(nbiRequest);
+ }
+
+ protected abstract String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException;
+
+ @Override
+ protected RestResponse doQuerySubnetCapability(String req) throws ApplicationException {
+ // handler
+ return sendRequest(req);
+ }
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java
new file mode 100644
index 0000000000..e244a85a6c
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.nssmf.manager.impl.external;
+
+import org.onap.so.adapters.nssmf.entity.RestResponse;
+import org.onap.so.adapters.nssmf.enums.ActionType;
+import org.onap.so.adapters.nssmf.enums.JobStatus;
+import org.onap.so.adapters.nssmf.enums.SelectionType;
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
+import org.onap.so.adapters.nssmf.manager.impl.ExternalNssmfManager;
+import org.onap.so.adapters.nssmf.util.NssmfAdapterUtil;
+import org.onap.so.beans.nsmf.DeAllocateNssi;
+import org.onap.so.beans.nsmf.NssiResponse;
+import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest;
+import org.onap.so.db.request.beans.ResourceOperationStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.HashMap;
+import java.util.Map;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal;
+
+
+public class ExternalAnNssmfManager extends ExternalNssmfManager {
+
+ private static final Logger logger = LoggerFactory.getLogger(ExternalAnNssmfManager.class);
+
+ @Override
+ protected String doWrapExtAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ return marshal(nbiRequest.getAllocateAnNssi().getSliceProfile());
+ }
+
+ @Override
+ protected void doAfterRequest() throws ApplicationException {
+ if (ActionType.ALLOCATE.equals(actionType) || ActionType.DEALLOCATE.equals(actionType)) {
+ @SuppressWarnings("unchecked")
+ Map<String, String> response = unMarshal(restResponse.getResponseContent(), Map.class);
+
+ String nssiId = response.get("nSSId");
+
+ NssiResponse resp = new NssiResponse();
+ resp.setJobId(nssiId);
+ resp.setNssiId(nssiId);
+
+ RestResponse returnRsp = new RestResponse();
+
+ returnRsp.setStatus(202);
+ returnRsp.setResponseContent(marshal(resp));
+ restResponse = returnRsp;
+
+ ResourceOperationStatus status =
+ new ResourceOperationStatus(serviceInfo.getNsiId(), nssiId, serviceInfo.getServiceUuid());
+ status.setResourceInstanceID(nssiId);
+
+ updateDbStatus(status, restResponse.getStatus(), JobStatus.FINISHED,
+ NssmfAdapterUtil.getStatusDesc(actionType));
+ }
+ // todo
+ }
+
+ @Override
+ protected String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ // TODO
+ return null;
+ }
+
+ @Override
+ protected String doWrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException {
+ Map<String, String> request = new HashMap<>();
+ request.put("nSSId", deAllocateNssi.getNssiId());
+ return marshal(request);
+ }
+
+
+ @Override
+ public RestResponse modifyNssi(NssmfAdapterNBIRequest modifyRequest) throws ApplicationException {
+ // TODO
+ return null;
+ }
+
+ @Override
+ public RestResponse activateNssi(NssmfAdapterNBIRequest nbiRequest, String snssai) throws ApplicationException {
+ // TODO
+ return null;
+ }
+
+ @Override
+ protected SelectionType doQueryNSSISelectionCapability() {
+ return SelectionType.NSSMF;
+ }
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalCnNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalCnNssmfManager.java
new file mode 100644
index 0000000000..fb76adcce6
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalCnNssmfManager.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.nssmf.manager.impl.external;
+
+import org.onap.so.adapters.nssmf.enums.SelectionType;
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
+import org.onap.so.adapters.nssmf.manager.impl.ExternalNssmfManager;
+import org.onap.so.beans.nsmf.DeAllocateNssi;
+import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
+
+public class ExternalCnNssmfManager extends ExternalNssmfManager {
+
+ @Override
+ protected String doWrapExtAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ return marshal(nbiRequest.getAllocateCnNssi());
+ }
+
+ @Override
+ protected String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ return marshal(nbiRequest.getAllocateCnNssi());
+ }
+
+ @Override
+ protected String doWrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException {
+ return marshal(deAllocateNssi);
+ }
+
+ @Override
+ protected SelectionType doQueryNSSISelectionCapability() {
+
+ return SelectionType.NSMF;
+ }
+
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalAnNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalAnNssmfManager.java
new file mode 100644
index 0000000000..dc6528381b
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalAnNssmfManager.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.nssmf.manager.impl.internal;
+
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
+import org.onap.so.adapters.nssmf.manager.impl.InternalNssmfManager;
+import org.onap.so.beans.nsmf.*;
+import java.util.HashMap;
+import java.util.Map;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
+
+
+public class InternalAnNssmfManager extends InternalNssmfManager {
+
+ @Override
+ protected String doWrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ NssmfRequest request =
+ new NssmfRequest(serviceInfo, nbiRequest.getEsrInfo().getNetworkType(), nbiRequest.getAllocateAnNssi());
+ request.setName(nbiRequest.getAllocateAnNssi().getNssiName());
+ return marshal(request);
+ }
+
+ @Override
+ protected String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ AllocateAnNssi allocateAnNssi = nbiRequest.getAllocateAnNssi();
+ AnSliceProfile sliceProfile = allocateAnNssi.getSliceProfile();
+ Map<String, Object> additional = new HashMap<>();
+ additional.put("modifyAction", "allocate");
+ additional.put("snssaiList", sliceProfile.getSNSSAIList());
+ additional.put("sliceProfileId", sliceProfile.getSliceProfileId());
+ additional.put("nsiInfo", allocateAnNssi.getNsiInfo());
+ additional.put("scriptName", allocateAnNssi.getScriptName());
+ NssmfRequest request = new NssmfRequest(serviceInfo, esrInfo.getNetworkType(), additional);
+ return marshal(request);
+ }
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalCnNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalCnNssmfManager.java
new file mode 100644
index 0000000000..4a93b3007c
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalCnNssmfManager.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.nssmf.manager.impl.internal;
+
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
+import org.onap.so.adapters.nssmf.manager.impl.InternalNssmfManager;
+import org.onap.so.beans.nsmf.*;
+import java.util.HashMap;
+import java.util.Map;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
+
+public class InternalCnNssmfManager extends InternalNssmfManager {
+
+ @Override
+ protected String doWrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+
+ NssmfRequest request =
+ new NssmfRequest(serviceInfo, nbiRequest.getEsrInfo().getNetworkType(), nbiRequest.getAllocateCnNssi());
+ request.setName(nbiRequest.getAllocateCnNssi().getNssiName());
+ return marshal(request);
+ }
+
+ @Override
+ protected String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ AllocateCnNssi allocateCnNssi = nbiRequest.getAllocateCnNssi();
+ CnSliceProfile cnSliceProfile = allocateCnNssi.getSliceProfile();
+ Map<String, Object> additional = new HashMap<>();
+ additional.put("modifyAction", "allocate");
+ additional.put("nsiInfo", allocateCnNssi.getNsiInfo());
+ additional.put("scriptName", allocateCnNssi.getScriptName());
+ additional.put("snssaiList", cnSliceProfile.getSnssaiList());
+ additional.put("sliceProfileId", cnSliceProfile.getSliceProfileId());
+
+ NssmfRequest request = new NssmfRequest(serviceInfo, esrInfo.getNetworkType(), additional);
+ return marshal(request);
+ }
+
+}
diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalTnNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalTnNssmfManager.java
new file mode 100644
index 0000000000..8bfbd55387
--- /dev/null
+++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/internal/InternalTnNssmfManager.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.nssmf.manager.impl.internal;
+
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
+import org.onap.so.adapters.nssmf.manager.impl.InternalNssmfManager;
+import org.onap.so.beans.nsmf.*;
+import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
+
+public class InternalTnNssmfManager extends InternalNssmfManager {
+
+ @Override
+ protected String doWrapAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+
+ return marshal(new NssmfRequest(serviceInfo, nbiRequest.getEsrInfo().getNetworkType(),
+ nbiRequest.getAllocateTnNssi()));
+ }
+
+ @Override
+ protected String doWrapModifyReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException {
+ // TODO
+ return null;
+ }
+}