/*-
* ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.openecomp.mso.adapters.vnf;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import javax.jws.WebService;
import javax.xml.ws.Holder;
import org.openecomp.mso.adapters.vnf.exceptions.VnfAlreadyExists;
import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
import org.openecomp.mso.adapters.vnf.exceptions.VnfNotFound;
import org.openecomp.mso.cloud.CloudConfig;
import org.openecomp.mso.cloud.CloudConfigFactory;
import org.openecomp.mso.cloud.CloudSite;
import org.openecomp.mso.db.catalog.CatalogDatabase;
import org.openecomp.mso.db.catalog.beans.HeatEnvironment;
import org.openecomp.mso.db.catalog.beans.HeatFiles;
import org.openecomp.mso.db.catalog.beans.HeatTemplate;
import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;
import org.openecomp.mso.db.catalog.beans.VfModule;
import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
import org.openecomp.mso.db.catalog.beans.VnfResource;
import org.openecomp.mso.db.catalog.utils.MavenLikeVersioning;
import org.openecomp.mso.entity.MsoRequest;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoAlarmLogger;
import org.openecomp.mso.logger.MsoLogger;
import org.openecomp.mso.openstack.beans.HeatStatus;
import org.openecomp.mso.openstack.beans.StackInfo;
import org.openecomp.mso.openstack.beans.VnfRollback;
import org.openecomp.mso.openstack.beans.VnfStatus;
import org.openecomp.mso.openstack.exceptions.MsoException;
import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
import org.openecomp.mso.openstack.utils.MsoHeatEnvironmentEntry;
import org.openecomp.mso.openstack.utils.MsoHeatUtils;
import org.openecomp.mso.openstack.utils.MsoHeatUtilsWithUpdate;
import org.openecomp.mso.properties.MsoPropertiesFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@WebService(serviceName = "VnfAdapter", endpointInterface = "org.openecomp.mso.adapters.vnf.MsoVnfAdapter", targetNamespace = "http://org.openecomp.mso/vnf")
public class MsoVnfAdapterImpl implements MsoVnfAdapter {
CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
protected CloudConfig cloudConfig = null;
MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
protected MsoHeatUtils heat;
private static final String MSO_PROP_VNF_ADAPTER = "MSO_PROP_VNF_ADAPTER";
private static final String MSO_CONFIGURATION_ERROR = "MsoConfigurationError";
private static final String VNF_ADAPTER_SERVICE_NAME = "MSO-BPMN:MSO-VnfAdapter.";
private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger();
private static final String CHECK_REQD_PARAMS = "org.openecomp.mso.adapters.vnf.checkRequiredParameters";
private static final String ADD_GET_FILES_ON_VOLUME_REQ = "org.openecomp.mso.adapters.vnf.addGetFilesOnVolumeReq";
private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
/**
* DO NOT use that constructor to instantiate this class, the msoPropertiesfactory will be NULL.
*
* @see MsoVnfAdapterImpl#MsoVnfAdapterImpl(MsoPropertiesFactory, CloudConfigFactory)
*/
public MsoVnfAdapterImpl() {
// empty implementation
}
/**
* This constructor MUST be used if this class is called with the new operator.
*
* @param msoPropFactory
*/
public MsoVnfAdapterImpl(MsoPropertiesFactory msoPropFactory, CloudConfigFactory cloudConfigFact) {
this.msoPropertiesFactory = msoPropFactory;
this.cloudConfigFactory = cloudConfigFact;
heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, this.msoPropertiesFactory, this.cloudConfigFactory);
}
/**
* Health Check web method. Does nothing but return to show the adapter is deployed.
*/
@Override
public void healthCheck() {
LOGGER.debug("Health check call in VNF Adapter");
}
/**
* This is the "Create VNF" web service implementation.
* It will create a new VNF of the requested type in the specified cloud
* and tenant. The tenant must exist before this service is called.
*
* If a VNF with the same name already exists, this can be considered a
* success or failure, depending on the value of the 'failIfExists' parameter.
*
* All VNF types will be defined in the MSO catalog. The caller must request
* one of these pre-defined types or an error will be returned. Within the
* catalog, each VNF type references (among other things) a Heat template
* which is used to deploy the required VNF artifacts (VMs, networks, etc.)
* to the cloud.
*
* Depending on the Heat template, a variable set of input parameters will
* be defined, some of which are required. The caller is responsible to
* pass the necessary input data for the VNF or an error will be thrown.
*
* The method returns the vnfId (the canonical name), a Map of VNF output
* attributes, and a VnfRollback object. This last object can be passed
* as-is to the rollbackVnf operation to undo everything that was created
* for the VNF. This is useful if a VNF is successfully created but the
* orchestrator fails on a subsequent operation.
*
* @param cloudSiteId CLLI code of the cloud site in which to create the VNF
* @param tenantId Openstack tenant identifier
* @param vnfType VNF type key, should match a VNF definition in catalog DB
* @param vnfVersion VNF version key, should match a VNF definition in catalog DB
* @param vnfName Name to be assigned to the new VNF
* @param inputs Map of key=value inputs for VNF stack creation
* @param failIfExists Flag whether already existing VNF should be considered
* a success or failure
* @param msoRequest Request tracking information for logs
* @param vnfId Holder for output VNF Openstack ID
* @param outputs Holder for Map of VNF outputs from heat (assigned IPs, etc)
* @param rollback Holder for returning VnfRollback object
*/
@Override
public void createVnf(String cloudSiteId,
String tenantId,
String vnfType,
String vnfVersion,
String vnfName,
String requestType,
String volumeGroupHeatStackId,
Map inputs,
Boolean failIfExists,
Boolean backout,
MsoRequest msoRequest,
Holder vnfId,
Holder