diff options
Diffstat (limited to 'adapters')
45 files changed, 5225 insertions, 1127 deletions
diff --git a/adapters/mso-adapter-utils/pom.xml b/adapters/mso-adapter-utils/pom.xml index e264a20d9d..ee70fb6f7f 100644 --- a/adapters/mso-adapter-utils/pom.xml +++ b/adapters/mso-adapter-utils/pom.xml @@ -112,6 +112,21 @@ <artifactId>snakeyaml</artifactId> <version>1.15</version> </dependency> - + <dependency> + <groupId>com.shazam</groupId> + <artifactId>shazamcrest</artifactId> + <version>0.11</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </exclusion> + </exclusions> + </dependency> </dependencies> </project> diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/CloudInfo.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/CloudInfo.java new file mode 100644 index 0000000000..035524510e --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/CloudInfo.java @@ -0,0 +1,69 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 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.openecomp.mso.adapters.vdu;
+
+/**
+ * Cloud information structure for deploying/managing a VDU. Includes the cloud site
+ * as well as tenant information within the site. Currently this is defined as a
+ * cloud site ID. which would map to a CloudConfig entry.
+ * Perhaps the CloudConfig entry itself should be provided, instead of requiring each
+ * plug-in to query it.
+ *
+ * The meaning of 'tenant' may differ by cloud provider, but every cloud supports some
+ * sort of tenant partitioning.
+ *
+ */
+public class CloudInfo {
+
+ private String cloudSiteId;
+ private String tenantId;
+ private String tenantName;//bpmn query and pass
+
+ public CloudInfo() {
+ }
+
+ public CloudInfo (String cloudSiteId, String tenantId, String tenantName) {
+ this.cloudSiteId = cloudSiteId;
+ this.tenantId = tenantId;
+ this.tenantName = tenantName;
+ }
+
+ public String getCloudSiteId() {
+ return cloudSiteId;
+ }
+ public void setCloudSiteId(String cloudSiteId) {
+ this.cloudSiteId = cloudSiteId;
+ }
+ public String getTenantId() {
+ return tenantId;
+ }
+ public void setTenantId(String tenantId) {
+ this.tenantId = tenantId;
+ }
+ public String getTenantName() {
+ return tenantName;
+ }
+ public void setTenantName(String tenantName) {
+ this.tenantName = tenantName;
+ }
+
+
+}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/PluginAction.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/PluginAction.java new file mode 100644 index 0000000000..1f3cf2f113 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/PluginAction.java @@ -0,0 +1,63 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 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.openecomp.mso.adapters.vdu;
+
+/**
+ * Java beam representing a detailed action performed within a plugin during VDU
+ * orchestration. This allows the plugin to convey more detailed information about
+ * recent activities it has performed. It is primarily intended for logging and
+ * troubleshooting, so plugins are free to populate this as desired.
+ */
+public class PluginAction {
+
+ private String action;
+ private String status;
+ private String rawMessage;
+
+ public PluginAction () {
+ }
+
+ public PluginAction (String action, String status, String rawMessage) {
+ this.action = action;
+ this.status = status;
+ this.rawMessage = rawMessage;
+ }
+
+ public String getAction() {
+ return action;
+ }
+ public void setAction(String action) {
+ this.action = action;
+ }
+ public String getStatus() {
+ return status;
+ }
+ public void setStatus(String status) {
+ this.status = status;
+ }
+ public String getRawMessage() {
+ return rawMessage;
+ }
+ public void setRawMessage(String rawMessage) {
+ this.rawMessage = rawMessage;
+ }
+
+}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduArtifact.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduArtifact.java new file mode 100644 index 0000000000..394d13d8d2 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduArtifact.java @@ -0,0 +1,64 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 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.openecomp.mso.adapters.vdu;
+
+public class VduArtifact {
+
+ // Enumerate the types of artifacts permitted. This may need to be a variable string
+ // value if arbitrary (cloud-specific) artifacts may be attached to VDUs in ASDC.
+ public enum ArtifactType {
+ MAIN_TEMPLATE, NESTED_TEMPLATE, CONFIG_FILE, SCRIPT_FILE, TEXT_FILE, ENVIRONMENT
+ }
+
+ private String name;
+ private byte[] content;
+ private ArtifactType type;
+
+ // Default constructor
+ public VduArtifact() {}
+
+ // Fully specified constructor
+ public VduArtifact (String name, byte[] content, ArtifactType type) {
+ this.name = name;
+ this.content = content;
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+ public void setName (String name) {
+ this.name = name;
+ }
+ public byte[] getContent() {
+ return content;
+ }
+ public void setContent(byte[] content) {
+ this.content = content;
+ }
+ public ArtifactType getType() {
+ return type;
+ }
+ public void setType(ArtifactType type) {
+ this.type = type;
+ }
+
+}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduException.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduException.java new file mode 100644 index 0000000000..3fd1d2ec8a --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduException.java @@ -0,0 +1,60 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.adapters.vdu;
+
+import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
+
+/**
+ * OpenStack exception.
+ */
+public class VduException extends MsoException
+{
+
+ /**
+ * Serialization id.
+ */
+ private static final long serialVersionUID = 3313636124141766495L;
+
+ /**
+ * Constructor to create a new VduException instance
+ * @param detail error details
+ */
+ public VduException (String detail) {
+ // Set the detailed error as the Exception 'message'
+ super(detail);
+ // TODO: Need a more generic category than OPENSTACK
+ super.category = MsoExceptionCategory.OPENSTACK;
+ }
+
+ /**
+ * Constructor to create a new VduException instance
+ * @param detail error details
+ * @param e the cause
+ */
+ public VduException (String detail, Exception e) {
+ // Set the detailed error as the Exception 'message'
+ super(detail, e);
+ // TODO: Need a more generic category than OPENSTACK
+ super.category = MsoExceptionCategory.OPENSTACK;
+ }
+
+}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduInstance.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduInstance.java new file mode 100644 index 0000000000..5a5a6ab3d2 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduInstance.java @@ -0,0 +1,80 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.adapters.vdu;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/*
+ * This Java bean class relays VDU status information in a cloud-agnostic format.
+ *
+ * This bean is returned by all implementors of the VduPlugin interface operations
+ * (instantiate, query, delete).
+ */
+
+public class VduInstance {
+ // Set defaults for everything
+ protected String vduInstanceId;
+ protected String vduInstanceName;
+ protected VduStatus status;
+ protected Map<String, Object> outputs = new HashMap<>();
+ protected Map<String, Object> inputs = new HashMap<>();
+
+ public String getVduInstanceId() {
+ return vduInstanceId;
+ }
+
+ public void setVduInstanceId(String vduInstanceId) {
+ this.vduInstanceId = vduInstanceId;
+ }
+
+ public String getVduInstanceName() {
+ return vduInstanceName;
+ }
+
+ public void setVduInstanceName(String vduInstanceName) {
+ this.vduInstanceName = vduInstanceName;
+ }
+
+ public VduStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(VduStatus status) {
+ this.status = status;
+ }
+
+ public Map<String, Object> getOutputs() {
+ return outputs;
+ }
+
+ public void setOutputs(Map<String, Object> outputs) {
+ this.outputs = outputs;
+ }
+
+ public Map<String, Object> getInputs() {
+ return inputs;
+ }
+
+ public void setInputs(Map<String, Object> inputs) {
+ this.inputs = inputs;
+ }
+}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduModelInfo.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduModelInfo.java new file mode 100644 index 0000000000..3cef29255f --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduModelInfo.java @@ -0,0 +1,50 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 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.openecomp.mso.adapters.vdu;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class VduModelInfo {
+ private String modelCustomizationUUID;
+ private int timeoutMinutes;
+ private List<VduArtifact> artifacts = new ArrayList<>();
+
+ public String getModelCustomizationUUID() {
+ return modelCustomizationUUID;
+ }
+ public void setModelCustomizationUUID(String modelCustomizationUUID) {
+ this.modelCustomizationUUID = modelCustomizationUUID;
+ }
+ public int getTimeoutMinutes() {
+ return timeoutMinutes;
+ }
+ public void setTimeoutMinutes(int timeoutMinutes) {
+ this.timeoutMinutes = timeoutMinutes;
+ }
+ public List<VduArtifact> getArtifacts() {
+ return artifacts;
+ }
+ public void setArtifacts(List<VduArtifact> artifacts) {
+ this.artifacts = artifacts;
+ }
+
+}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduPlugin.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduPlugin.java new file mode 100644 index 0000000000..3484646387 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduPlugin.java @@ -0,0 +1,186 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 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.openecomp.mso.adapters.vdu;
+
+/**
+ * This interface defines a common API for template-based cloud deployments.
+ * The methods here should be adaptable for Openstack (Heat), Cloudify (TOSCA),
+ * Aria (TOSCA), Multi-VIM (TBD), and others (e.g. Azure Resource Manager).
+ *
+ * The deployed instances are referred to here as Virtual Deployment Units (VDUs).
+ * The package of templates that define a give VDU is referred to as its blueprint.
+ *
+ * Template-based orchestrators all follow a similar template/blueprint model.
+ * - One main template that is the top level definition
+ * - Optional nested templates referenced/included by the main template
+ * - Optional files attached to the template package, typically containing
+ * configuration files, install scripts, orchestration scripts, etc.
+ *
+ * The main template also defines the required inputs for creating a new instance,
+ * and output values exposed by successfully deployed instances. Inputs and outputs
+ * may include simple or complex (JSON) data types.
+ *
+ * Each implementation of this interface is expected to understand the MSO CloudConfig
+ * to obtain the credentials for its sub-orchestrator and the targeted cloud.
+ * The sub-orchestrator may have different credentials from the cloud (e.g. an Aria
+ * instance in front of an Openstack cloud) or they may be the same (e.g. Heat)
+ */
+import java.util.Map;
+
+public interface VduPlugin {
+
+ /**
+ * The instantiateVdu interface deploys a new VDU instance from a vdu model package.
+ *
+ * For some VIMs, this may be a single command (e.g. Heat -> create stack) or may
+ * require a series of API calls (e.g. Cloudify -> upload blueprint, create deployment,
+ * execute install workflow). These details are hidden within the plug-in implementation.
+ * The instantiation should be fully completed before returning. On failures, this
+ * method is expected to back out the attempt, leaving the cloud in its previous state.
+ *
+ * It is expected that parameters have been validated and contain at minimum the
+ * required parameters for the given template with no extra parameters.
+ *
+ * The VDU name supplied by the caller will be globally unique, and identify the artifact
+ * in A&AI. Inventory is managed by the higher levels invoking this function.
+ *
+ * @param cloudInfo The target cloud + tenant identifiers for the VDU.
+ * @param instanceName A unique name for the VDU instance to update.
+ * @param inputs A map of key/value inputs. Values may be strings, numbers, or JSON objects.
+ * Will completely replace any inputs provided on the original instantiation.
+ * @param vduModel Object containing the collection of templates and files that comprise
+ * the blueprint for this VDU.
+ * @param rollbackOnFailure Flag to preserve or roll back the update on Failure. Should normally
+ * be True except in troubleshooting/debug cases. Might not be supported in all plug-ins.
+ *
+ * @return A VduInstance object
+ * @throws VduException Thrown if the sub-orchestrator API calls fail or if a timeout occurs.
+ * Various subclasses of VduException may be thrown.
+ */
+ public VduInstance instantiateVdu (
+ CloudInfo cloudInfo,
+ String instanceName,
+ Map<String,Object> inputs,
+ VduModelInfo vduModel,
+ boolean rollbackOnFailure)
+ throws VduException;
+
+ /**
+ * Query a deployed VDU instance. This call will return a VduInstance object, or null
+ * if the deployment does not exist.
+ *
+ * Some VIM orchestrators identify deployment instances by string UUIDs, and others
+ * by integers. In the latter case, the ID will be passed in as a numeric string.
+ *
+ * The returned VduInstance object contains the input and output parameter maps,
+ * as well as other properties of the deployment (name, status, last action, etc.).
+ *
+ * @param cloudInfo The target cloud + tenant identifiers for the VDU.
+ * @param vduInstanceId The ID of the deployment to query
+ *
+ * @return A VduInstance object
+ * @throws VduException Thrown if the sub-orchestrator API calls fail or if a timeout occurs.
+ * Various subclasses of VduException may be thrown.
+ */
+ public VduInstance queryVdu (
+ CloudInfo cloudInfo,
+ String vduInstanceId)
+ throws VduException;
+
+
+ /**
+ * Delete a VDU instance by ID. If the VIM sub-orchestrator supports pre-installation
+ * of blueprints/models, the blueprint itself may remain installed. This is recommended,
+ * since other VDU instances may be using it.
+ *
+ * Some VIM orchestrators identify deployment instances by string UUIDs, and others
+ * by integers. In the latter case, the ID will be passed in as a numeric string.
+ *
+ * For some VIMs, deletion may be a single command (e.g. Heat -> delete stack) or a
+ * series of API calls (e.g. Cloudify -> execute uninstall workflow, delete deployment).
+ * These details are hidden within the plug-in implementation. The deletion should be
+ * fully completed before returning.
+ *
+ * The successful return is a VduInstance object which contains the state of the VDU
+ * just prior to deletion, with a status of DELETED. If the deployment was not found,
+ * the VduInstance object should be empty (with a status of NOTFOUND).
+ * There is no rollback from a successful deletion.
+ *
+ * A deletion failure will result in an undefined deployment state - the components may
+ * or may not have been all or partially uninstalled, so the resulting deployment must
+ * be considered invalid.
+ *
+ * @param cloudInfo The target cloud + tenant identifiers for the VDU.
+ * @param instanceId The unique id of the deployment to delete.
+ * @param timeoutMinutes Timeout after which the delete action will be cancelled.
+ * Consider sending the entire model here, if it may be of use to the plug-in?
+ *
+ * @return A VduInstance object, representing its state just prior to deletion.
+ *
+ * @throws VduException Thrown if the API calls fail or if a timeout occurs.
+ * Various subclasses of VduException may be thrown.
+ */
+ public VduInstance deleteVdu (
+ CloudInfo cloudInfo,
+ String instanceId,
+ int timeoutMinutes)
+ throws VduException;
+
+
+ /**
+ * The updateVdu interface attempts to update a VDU in-place, using either new inputs or
+ * a new model definition (i.e. updated templates/blueprints). This depends on the
+ * capabilities of the targeted sub-orchestrator, as not all implementations are expected
+ * to support this ability. It is primary included initially only for Heat.
+ *
+ * It is expected that parameters have been validated and contain at minimum the required
+ * parameters for the given template with no extra parameters. The VDU instance name cannot
+ * be updated.
+ *
+ * The update should be fully completed before returning. The successful return is a
+ * VduInstance object containing the updated VDU state.
+ *
+ * An update failure will result in an undefined deployment state - the components may
+ * or may not have been all or partially modified, deleted, recreated, etc. So the resulting
+ * VDU must be considered invalid.
+ *
+ * @param cloudInfo The target cloud + tenant identifiers for the VDU.
+ * @param instanceId The unique ID for the VDU instance to update.
+ * @param inputs A map of key/value inputs. Values may be strings, numbers, or JSON objects.
+ * Will completely replace any inputs provided on the original instantiation.
+ * @param vduModel Object containing the collection of templates and files that comprise
+ * the blueprint for this VDU.
+ * @param rollbackOnFailure Flag to preserve or roll back the update on Failure. Should normally
+ * be True except in troubleshooting/debug cases. Might not be supported in all plug-ins.
+ *
+ * @return A VduInfo object
+ * @throws VduException Thrown if the sub-orchestrator API calls fail or if a timeout occurs.
+ * Various subclasses of VduException may be thrown.
+ */
+ public VduInstance updateVdu (
+ CloudInfo cloudInfo,
+ String instanceId,
+ Map<String,Object> inputs,
+ VduModelInfo vduModel,
+ boolean rollbackOnFailure)
+ throws VduException;
+
+}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduStateType.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduStateType.java new file mode 100644 index 0000000000..92f5cdab3f --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduStateType.java @@ -0,0 +1,36 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.adapters.vdu;
+
+
+/*
+ * Enum status values to capture the state of a generic (cloud-agnostic) VDU.
+ */
+public enum VduStateType {
+ NOTFOUND,
+ INSTANTIATING,
+ INSTANTIATED,
+ DELETING,
+ DELETED, // Note - only returned in success response to deleteVdu call.
+ UPDATING,
+ FAILED,
+ UNKNOWN
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduStatus.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduStatus.java new file mode 100644 index 0000000000..174bed90a2 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/adapters/vdu/VduStatus.java @@ -0,0 +1,54 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 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.openecomp.mso.adapters.vdu;
+
+public class VduStatus {
+
+ private VduStateType state;
+ private String errorMessage;
+ private PluginAction lastAction;
+
+ public VduStateType getState() {
+ return state;
+ }
+ public void setState(VduStateType state) {
+ this.state = state;
+ }
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+ public PluginAction getLastAction() {
+ return lastAction;
+ }
+ public void setLastAction(PluginAction lastAction) {
+ this.lastAction = lastAction;
+ }
+ public void setLastAction (String action, String status, String rawCloudMessage) {
+ lastAction = new PluginAction();
+ lastAction.setAction (action);
+ lastAction.setStatus (status);
+ lastAction.setRawMessage(rawCloudMessage);
+ }
+
+}
\ No newline at end of file diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtils.java index f72e46a9d8..bc3aa4f94f 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtils.java @@ -26,11 +26,22 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import org.openecomp.mso.adapters.vdu.CloudInfo; +import org.openecomp.mso.adapters.vdu.PluginAction; +import org.openecomp.mso.adapters.vdu.VduArtifact; +import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType; +import org.openecomp.mso.adapters.vdu.VduException; +import org.openecomp.mso.adapters.vdu.VduInstance; +import org.openecomp.mso.adapters.vdu.VduModelInfo; +import org.openecomp.mso.adapters.vdu.VduPlugin; +import org.openecomp.mso.adapters.vdu.VduStateType; +import org.openecomp.mso.adapters.vdu.VduStatus; import org.openecomp.mso.cloud.CloudConfig; import org.openecomp.mso.cloud.CloudConfigFactory; import org.openecomp.mso.cloud.CloudSite; @@ -56,6 +67,7 @@ import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.CancelExecution; import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.GetExecution; import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.ListExecutions; import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.StartExecution; +import org.openecomp.mso.cloudify.v3.model.AzureConfig; import org.openecomp.mso.cloudify.v3.model.Blueprint; import org.openecomp.mso.cloudify.v3.model.CancelExecutionParams; import org.openecomp.mso.cloudify.v3.model.CloudifyError; @@ -85,7 +97,7 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -public class MsoCloudifyUtils extends MsoCommonUtils { +public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin{ private MsoPropertiesFactory msoPropertiesFactory; private CloudConfigFactory cloudConfigFactory; @@ -113,6 +125,12 @@ public class MsoCloudifyUtils extends MsoCommonUtils { /** * This constructor MUST be used ONLY in the JUNIT tests, not for real code. + */ + public MsoCloudifyUtils() { + + } + /** + * This constructor MUST be used ONLY in the JUNIT tests, not for real code. * The MsoPropertiesFactory will be added by EJB injection. * * @param msoPropID ID of the mso pro config as defined in web.xml @@ -186,17 +204,24 @@ public class MsoCloudifyUtils extends MsoCommonUtils { Cloudify cloudify = getCloudifyClient (cloudSite.get()); - // Create the Cloudify OpenstackConfig with the credentials - OpenstackConfig openstackConfig = getOpenstackConfig (cloudSite.get(), tenantId); - LOGGER.debug ("Ready to Create Deployment (" + deploymentId + ") with input params: " + inputs); // Build up the inputs, including: // - from provided "environment" file // - passed in by caller - // - special input for Openstack Credentials - Map<String,Object> expandedInputs = new HashMap<String,Object> (inputs); - expandedInputs.put("openstack_config", openstackConfig); + // - special input for cloud-specific Credentials + Map<String,Object> expandedInputs = new HashMap<> (inputs); + + String platform = cloudSite.get().getPlatform(); + if (platform == null || platform.equals("") || platform.equalsIgnoreCase("OPENSTACK")) { + // Create the Cloudify OpenstackConfig with the credentials + OpenstackConfig openstackConfig = getOpenstackConfig (cloudSite.get(), tenantId); + expandedInputs.put("openstack_config", openstackConfig); + } else if (platform.equalsIgnoreCase("AZURE")) { + // Create Cloudify AzureConfig with the credentials + AzureConfig azureConfig = getAzureConfig (cloudSite.get(), tenantId); + expandedInputs.put("azure_config", azureConfig); + } // Build up the parameters to create a new deployment CreateDeploymentParams deploymentParams = new CreateDeploymentParams(); @@ -236,10 +261,11 @@ public class MsoCloudifyUtils extends MsoCommonUtils { /* * It can take some time for Cloudify to be ready to execute a workflow - * on the deployment. Sleep 10 seconds. + * on the deployment. Sleep 30 seconds based on observation of behavior + * in a Cloudify VM instance (delay due to "create_deployment_environment"). */ try { - Thread.sleep(10000); + Thread.sleep(30000); } catch (InterruptedException e) {} /* @@ -825,7 +851,7 @@ public class MsoCloudifyUtils extends MsoCommonUtils { /* * Common method to load a blueprint. May be called from */ - private boolean uploadBlueprint (Cloudify cloudify, String blueprintId, String mainFileName, Map<String,byte[]> blueprintFiles) + protected boolean uploadBlueprint (Cloudify cloudify, String blueprintId, String mainFileName, Map<String,byte[]> blueprintFiles) throws MsoException { // Check if it already exists. If so, return false. @@ -1204,11 +1230,234 @@ public class MsoCloudifyUtils extends MsoCommonUtils { return me; } + + + /******************************************************************************* + * + * Methods (and associated utilities) to implement the VduPlugin interface + * + *******************************************************************************/ + + /** + * VduPlugin interface for instantiate function. + * + * This one is a bit more complex, in that it will first upload the blueprint if needed, + * then create the Cloudify deployment and execute the install workflow. + * + * This implementation also merges any parameters defined in the ENV file with the other + * other input parameters for any undefined parameters). + * The basic MsoCloudifyUtils separates blueprint management from deploument actions, + * but the VduPlugin does not declare blueprint management operations. + */ + public VduInstance instantiateVdu ( + CloudInfo cloudInfo, + String instanceName, + Map<String,Object> inputs, + VduModelInfo vduModel, + boolean rollbackOnFailure) + throws VduException + { + String cloudSiteId = cloudInfo.getCloudSiteId(); + String tenantId = cloudInfo.getTenantId(); + + // Translate the VDU ModelInformation structure to that which is needed for + // creating and uploading a blueprint. Use the model customization UUID as + // the blueprint identifier. + + String blueprintId = vduModel.getModelCustomizationUUID(); + + try { + + if (! isBlueprintLoaded (cloudSiteId, blueprintId)) { + LOGGER.debug ("Blueprint " + blueprintId + " is not loaded. Will upload it now."); + + // Prepare the blueprint inputs. Need the set of blueprint templates and files, + // plus the main blueprint name. + Map<String,byte[]> blueprintFiles = new HashMap<>(); + String mainTemplate = ""; + + // Add all of the blueprint artifacts from the VDU model + List<VduArtifact> vduArtifacts = vduModel.getArtifacts(); + for (VduArtifact vduArtifact: vduArtifacts) + { + // Add all artifacts to the blueprint, with one exception. + // ENVIRONMENT files will be processed later as additional parameters. + + ArtifactType artifactType = vduArtifact.getType(); + if (artifactType != ArtifactType.ENVIRONMENT) { + blueprintFiles.put(vduArtifact.getName(), vduArtifact.getContent()); + + if (artifactType == ArtifactType.MAIN_TEMPLATE) { + mainTemplate = vduArtifact.getName(); + } + } + } + + // Upload the blueprint package + uploadBlueprint(cloudSiteId, blueprintId, mainTemplate, blueprintFiles, false); + } + } + catch (Exception e) { + throw new VduException ("CloudifyUtils (instantiateVDU): blueprint Exception", e); + } + + + // Next, create and install a new deployment based on the blueprint. + // For Cloudify, the deploymentId is specified by the client. Just use the instance name + // as the ID. + + try { + // Query the Cloudify Deployment object and populate a VduInstance + DeploymentInfo deployment = createAndInstallDeployment (cloudSiteId, + tenantId, + instanceName, + blueprintId, + inputs, + true, // (poll for completion) + vduModel.getTimeoutMinutes(), + rollbackOnFailure); + + VduInstance vduInstance = deploymentInfoToVduInstance(deployment); + + return vduInstance; + } + catch (Exception e) { + throw new VduException ("CloudifyUtils (instantiateVDU): Create-and-install-deployment Exception", e); + } + } + + + /** + * VduPlugin interface for query function. + */ + public VduInstance queryVdu (CloudInfo cloudInfo, String instanceId) + throws VduException + { + String cloudSiteId = cloudInfo.getCloudSiteId(); + String tenantId = cloudInfo.getTenantId(); + + try { + // Query the Cloudify Deployment object and populate a VduInstance + DeploymentInfo deployment = queryDeployment (cloudSiteId, tenantId, instanceId); + + VduInstance vduInstance = deploymentInfoToVduInstance(deployment); + + return vduInstance; + } + catch (Exception e) { + throw new VduException ("Query VDU Exception", e); + } + } + + + /** + * VduPlugin interface for delete function. + */ + public VduInstance deleteVdu (CloudInfo cloudInfo, String instanceId, int timeoutMinutes) + throws VduException + { + String cloudSiteId = cloudInfo.getCloudSiteId(); + String tenantId = cloudInfo.getTenantId(); + + try { + // Uninstall and delete the Cloudify Deployment + DeploymentInfo deployment = uninstallAndDeleteDeployment (cloudSiteId, tenantId, instanceId, timeoutMinutes); + + // Populate a VduInstance based on the deleted Cloudify Deployment object + VduInstance vduInstance = deploymentInfoToVduInstance(deployment); + + return vduInstance; + } + catch (Exception e) { + throw new VduException ("Delete VDU Exception", e); + } + } + + + /** + * VduPlugin interface for update function. + * + * Update is currently not supported in the MsoCloudifyUtils implementation. + * Just return a VduException. + * + */ + public VduInstance updateVdu ( + CloudInfo cloudInfo, + String instanceId, + Map<String,Object> inputs, + VduModelInfo vduModel, + boolean rollbackOnFailure) + throws VduException + { + throw new VduException ("CloudifyUtils: updateVDU interface not supported"); + } + + + /* + * Convert the local DeploymentInfo object (Cloudify-specific) to a generic VduInstance object + */ + protected VduInstance deploymentInfoToVduInstance (DeploymentInfo deployment) + { + VduInstance vduInstance = new VduInstance(); + + // only one ID in Cloudify, use for both VDU name and ID + vduInstance.setVduInstanceId(deployment.getId()); + vduInstance.setVduInstanceName(deployment.getId()); + + // Copy inputs and outputs + vduInstance.setInputs(deployment.getInputs()); + vduInstance.setOutputs(deployment.getOutputs()); + + // Translate the status elements + vduInstance.setStatus(deploymentStatusToVduStatus (deployment)); + + return vduInstance; + } + + protected VduStatus deploymentStatusToVduStatus (DeploymentInfo deployment) + { + VduStatus vduStatus = new VduStatus(); + + // Determine the status based on last action & status + // DeploymentInfo object should be enhanced to report a better status internally. + DeploymentStatus status = deployment.getStatus(); + + if (status == null) { + vduStatus.setState(VduStateType.UNKNOWN); + } + else if (status == DeploymentStatus.NOTFOUND) { + vduStatus.setState(VduStateType.NOTFOUND); + } + else if (status == DeploymentStatus.INSTALLED) { + vduStatus.setState(VduStateType.INSTANTIATED); + } + else if (status == DeploymentStatus.CREATED) { + // Deployment exists but is not installed. This shouldn't really happen, + // since create + install or uninstall + delete are always done together. + // But account for it anyway, assuming the operation is still in progress. + String lastAction = deployment.getLastAction(); + if (lastAction == null) + vduStatus.setState(VduStateType.INSTANTIATING); + else + vduStatus.setState(VduStateType.DELETING); + } + else if (status == DeploymentStatus.FAILED) { + vduStatus.setState(VduStateType.FAILED); + } else { + vduStatus.setState(VduStateType.UNKNOWN); + } + + vduStatus.setErrorMessage(deployment.getErrorMessage()); + vduStatus.setLastAction(new PluginAction(deployment.getLastAction(), deployment.getActionStatus(), deployment.getErrorMessage())); + + return vduStatus; + } + /* * Return an OpenstackConfig object as expected by Cloudify Openstack Plug-in. * Base the values on the CloudSite definition. */ - private OpenstackConfig getOpenstackConfig (CloudSite cloudSite, String tenantId) { + protected OpenstackConfig getOpenstackConfig (CloudSite cloudSite, String tenantId) { OpenstackConfig openstackConfig = new OpenstackConfig(); openstackConfig.setRegion (cloudSite.getRegionId()); openstackConfig.setAuthUrl (cloudSite.getIdentityService().getIdentityUrl()); @@ -1217,4 +1466,18 @@ public class MsoCloudifyUtils extends MsoCommonUtils { openstackConfig.setTenantName (tenantId); return openstackConfig; } + + /* + * Return an Azure object as expected by Cloudify Azure Plug-in. + * Base the values on the CloudSite definition. + */ + protected AzureConfig getAzureConfig (CloudSite cloudSite, String tenantId) { + AzureConfig azureConfig = new AzureConfig(); + // TODO: Use adminTenant for now, instead of adding another element + azureConfig.setSubscriptionId (cloudSite.getIdentityService().getAdminTenant()); + azureConfig.setTenantId (tenantId); + azureConfig.setClientId (cloudSite.getIdentityService().getMsoId()); + azureConfig.setClientSecret (cloudSite.getIdentityService().getMsoPass()); + return azureConfig; + } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java index 92220f8717..7046096979 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java @@ -22,218 +22,242 @@ package org.openecomp.mso.openstack.utils; - import java.util.HashSet; import java.util.ArrayList; import java.util.Set; + import org.openecomp.mso.db.catalog.beans.HeatTemplateParam; import org.openecomp.mso.logger.MsoLogger; public class MsoHeatEnvironmentEntry { - private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); - - private Set<MsoHeatEnvironmentParameter> parameters = null; - private Set<MsoHeatEnvironmentResource> resources = null; - private StringBuilder rawEntry = null; - private boolean valid = true; - private String errorString = null; - private StringBuilder resourceRegistryEntryRaw = null; - - public MsoHeatEnvironmentEntry() { - super(); - } - - public MsoHeatEnvironmentEntry(StringBuilder sb) { - this(); - this.rawEntry = sb; - this.processRawEntry(); - } - - private void processRawEntry() { - try { - if (this.rawEntry == null || "".equals(this.rawEntry)) - return; - byte[] b = this.rawEntry.toString().getBytes(); - MsoYamlEditorWithEnvt yaml = new MsoYamlEditorWithEnvt(b); - this.parameters = yaml.getParameterListFromEnvt(); - //this.resources = yaml.getResourceListFromEnvt(); - StringBuilder sb = this.getResourceRegistryRawEntry(); - if (sb == null) { - this.resourceRegistryEntryRaw = new StringBuilder(""); - } else { - this.resourceRegistryEntryRaw = sb; - } - } catch (Exception e) { - LOGGER.debug("Exception:", e); - this.valid = false; - this.errorString = e.getMessage(); - //e.printStackTrace(); - } - } - - public boolean isValid() { - return this.valid; - } - public String getErrorString() { - return this.errorString; - } - - public Set<MsoHeatEnvironmentParameter> getParameters() { - return this.parameters; - } - public Set<MsoHeatEnvironmentResource> getResources() { - return this.resources; - } - public void setParameters(Set<MsoHeatEnvironmentParameter> paramSet) { - if (paramSet == null) { - this.parameters = null; - } else { - this.parameters = paramSet; - } - } - public void setResources(Set<MsoHeatEnvironmentResource> resourceSet) { - if (resourceSet == null) { - this.resources = null; - } else { - this.resources = resourceSet; - } - } - - public void addParameter(MsoHeatEnvironmentParameter hep) { - if (this.parameters == null) { - this.parameters = new HashSet<>(); - } - this.parameters.add(hep); - } - public void addResource(MsoHeatEnvironmentResource her) { - if (this.resources == null) { - this.resources = new HashSet<>(); - } - this.resources.add(her); - } - - public int getNumberOfParameters() { - return this.parameters.size(); - } - public int getNumberOfResources() { - return this.resources.size(); - } - - public boolean hasResources() { - if (this.resources != null && this.resources.size() > 0) { - return true; - } - return false; - } - public boolean hasParameters() { - if (this.parameters != null && this.parameters.size() > 0) { - return true; - } - return false; - } - - public boolean containsParameter(String paramName) { - boolean contains = false; - if (this.parameters == null || this.parameters.size() < 1) { - return false; - } - if (this.parameters.contains(new MsoHeatEnvironmentParameter(paramName))) { - contains = true; - } - return contains; - } - - public boolean containsParameter(String paramName, String paramAlias) { - if (this.containsParameter(paramName)) { - return true; - } - if (this.containsParameter(paramAlias)) { - return true; - } - return false; - } - - @Override - public String toString() { - return "MsoHeatEnvironmentEntry{" + "parameters=" + parameters + - ", resourceRegistryEntryRaw='" + resourceRegistryEntryRaw + '\'' + - '}'; - } - - public StringBuilder toFullStringExcludeNonParams(Set<HeatTemplateParam> params) { - // Basically give back the envt - but exclude the params that aren't in the HeatTemplate - - StringBuilder sb = new StringBuilder(); - ArrayList<String> paramNameList = new ArrayList<String>(params.size()); - for (HeatTemplateParam htp : params) { - paramNameList.add(htp.getParamName()); - } - - if (this.hasParameters()) { - sb.append("parameters:\n"); - for (MsoHeatEnvironmentParameter hep : this.parameters) { - String paramName = hep.getName(); - if (paramNameList.contains(paramName)) { - // This parameter *is* in the Heat Template - so include it: - sb.append(" " + hep.getName() + ": " + hep.getValue() + "\n"); - // New - 1607 - if any of the params mapped badly - JUST RETURN THE ORIGINAL ENVT! - if (hep.getValue().startsWith("_BAD")) { - return this.rawEntry; - } - } - } - sb.append("\n"); - } + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); + + private Set<MsoHeatEnvironmentParameter> parameters = null; + private Set<MsoHeatEnvironmentResource> resources = null; + private StringBuilder rawEntry = null; + private boolean valid = true; + private String errorString = null; + private StringBuilder resourceRegistryEntryRaw = null; + + public MsoHeatEnvironmentEntry() { + super(); + } + + public MsoHeatEnvironmentEntry(StringBuilder sb) { + this(); + this.rawEntry = sb; + this.processRawEntry(); + } + + private void processRawEntry() { + try { + if (this.rawEntry == null || "".equals(this.rawEntry)) + return; + byte[] b = this.rawEntry.toString().getBytes(); + MsoYamlEditorWithEnvt yaml = new MsoYamlEditorWithEnvt(b); + this.parameters = yaml.getParameterListFromEnvt(); + //this.resources = yaml.getResourceListFromEnvt(); + StringBuilder sb = this.getResourceRegistryRawEntry(); + if (sb == null) { + this.resourceRegistryEntryRaw = new StringBuilder(""); + } else { + this.resourceRegistryEntryRaw = sb; + } + } catch (Exception e) { + LOGGER.debug("Exception:", e); + this.valid = false; + this.errorString = e.getMessage(); + //e.printStackTrace(); + } + } + + public boolean isValid() { + return this.valid; + } + + public String getErrorString() { + return this.errorString; + } + + public Set<MsoHeatEnvironmentParameter> getParameters() { + return this.parameters; + } + + public Set<MsoHeatEnvironmentResource> getResources() { + return this.resources; + } + + public void setParameters(Set<MsoHeatEnvironmentParameter> paramSet) { + if (paramSet == null) { + this.parameters = null; + } else { + this.parameters = paramSet; + } + } + + public void setResources(Set<MsoHeatEnvironmentResource> resourceSet) { + if (resourceSet == null) { + this.resources = null; + } else { + this.resources = resourceSet; + } + } + + public void addParameter(MsoHeatEnvironmentParameter hep) { + if (this.parameters == null) { + this.parameters = new HashSet<>(); + } + this.parameters.add(hep); + } + + public void addResource(MsoHeatEnvironmentResource her) { + if (this.resources == null) { + this.resources = new HashSet<>(); + } + this.resources.add(her); + } + + public int getNumberOfParameters() { + return this.parameters.size(); + } + + public int getNumberOfResources() { + return this.resources.size(); + } + + public boolean hasResources() { + if (this.resources != null && this.resources.size() > 0) { + return true; + } + return false; + } + + public boolean hasParameters() { + if (this.parameters != null && this.parameters.size() > 0) { + return true; + } + return false; + } + + public boolean containsParameter(String paramName) { + boolean contains = false; + if (this.parameters == null || this.parameters.size() < 1) { + return false; + } + if (this.parameters.contains(new MsoHeatEnvironmentParameter(paramName))) { + contains = true; + } + return contains; + } + + public boolean containsParameter(String paramName, String paramAlias) { + if (this.containsParameter(paramName)) { + return true; + } + if (this.containsParameter(paramAlias)) { + return true; + } + return false; + } + + @Override + public String toString() { + return "MsoHeatEnvironmentEntry{" + "parameters=" + parameters + + ", resourceRegistryEntryRaw='" + resourceRegistryEntryRaw + '\'' + + '}'; + } + + public StringBuilder toFullStringExcludeNonParams(Set<HeatTemplateParam> params) { + // Basically give back the envt - but exclude the params that aren't in the HeatTemplate + + StringBuilder sb = new StringBuilder(); + ArrayList<String> paramNameList = new ArrayList<String>(params.size()); + for (HeatTemplateParam htp : params) { + paramNameList.add(htp.getParamName()); + } + + if (this.hasParameters()) { + sb.append("parameters:\n"); + for (MsoHeatEnvironmentParameter hep : this.parameters) { + String paramName = hep.getName(); + if (paramNameList.contains(paramName)) { + // This parameter *is* in the Heat Template - so include it: + sb.append(" " + hep.getName() + ": " + hep.getValue() + "\n"); + // New - 1607 - if any of the params mapped badly - JUST RETURN THE ORIGINAL ENVT! + if (hep.getValue().startsWith("_BAD")) { + return this.rawEntry; + } + } + } + sb.append("\n"); + } // if (this.hasResources()) { // sb.append("resource_registry:\n"); // for (MsoHeatEnvironmentResource her : this.resources) { // sb.append(" \"" + her.getName() + "\": " + her.getValue() + "\n"); // } // } - sb.append("\n"); - sb.append(this.resourceRegistryEntryRaw); - return sb; - } - - public StringBuilder toFullString() { - StringBuilder sb = new StringBuilder(); - - if (this.hasParameters()) { - sb.append("parameters:\n"); - for (MsoHeatEnvironmentParameter hep : this.parameters) { - sb.append(" " + hep.getName() + ": " + hep.getValue() + "\n"); - } - sb.append("\n"); - } + sb.append("\n"); + sb.append(this.resourceRegistryEntryRaw); + return sb; + } + + public StringBuilder toFullString() { + StringBuilder sb = new StringBuilder(); + + if (this.hasParameters()) { + sb.append("parameters:\n"); + for (MsoHeatEnvironmentParameter hep : this.parameters) { + sb.append(" " + hep.getName() + ": " + hep.getValue() + "\n"); + } + sb.append("\n"); + } // if (this.hasResources()) { // sb.append("resource_registry:\n"); // for (MsoHeatEnvironmentResource her : this.resources) { // sb.append(" \"" + her.getName() + "\": " + her.getValue() + "\n"); // } // } - sb.append("\n"); - sb.append(this.resourceRegistryEntryRaw); - return sb; - } - - public StringBuilder getRawEntry() { - return this.rawEntry; - } - - private StringBuilder getResourceRegistryRawEntry() { - - if (this.rawEntry == null) { - return null; - } - - StringBuilder sb = new StringBuilder(); - int indexOf = this.rawEntry.indexOf("resource_registry:"); - if (indexOf < 0) { // no resource_registry: - return null; - } - sb.append(this.rawEntry.substring(indexOf)); - return sb; - } - + sb.append("\n"); + sb.append(this.resourceRegistryEntryRaw); + return sb; + } + + public StringBuilder getRawEntry() { + return this.rawEntry; + } + + private StringBuilder getResourceRegistryRawEntry() { + + if (this.rawEntry == null) { + return null; + } + + StringBuilder sb = new StringBuilder(); + int indexOf = this.rawEntry.indexOf("resource_registry:"); + if (indexOf < 0) { // no resource_registry: + return null; + } + sb.append(this.rawEntry.substring(indexOf)); + return sb; + } + + public void setHPAParameters(StringBuilder hpasb) { + try { + MsoYamlEditorWithEnvt yaml = new MsoYamlEditorWithEnvt(hpasb.toString().getBytes()); + Set<MsoHeatEnvironmentParameter> hpaParams = yaml.getParameterListFromEnvt(); + for (MsoHeatEnvironmentParameter hpaparam : hpaParams) { + for (MsoHeatEnvironmentParameter param : this.parameters) { + if (param.getName() == hpaparam.getName()) { + param.setValue(hpaparam.getValue()); + } + } + } + } catch (Exception e) { + LOGGER.debug("Exception:", e); + this.errorString = e.getMessage(); + //e.printStackTrace(); + } + } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java index 7dd14d865c..3f5da19854 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java @@ -30,6 +30,16 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.openecomp.mso.adapters.vdu.CloudInfo; +import org.openecomp.mso.adapters.vdu.PluginAction; +import org.openecomp.mso.adapters.vdu.VduArtifact; +import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType; +import org.openecomp.mso.adapters.vdu.VduException; +import org.openecomp.mso.adapters.vdu.VduInstance; +import org.openecomp.mso.adapters.vdu.VduModelInfo; +import org.openecomp.mso.adapters.vdu.VduPlugin; +import org.openecomp.mso.adapters.vdu.VduStateType; +import org.openecomp.mso.adapters.vdu.VduStatus; import org.openecomp.mso.cloud.CloudConfig; import org.openecomp.mso.cloud.CloudConfigFactory; import org.openecomp.mso.cloud.CloudIdentity; @@ -52,7 +62,6 @@ import org.openecomp.mso.properties.MsoJavaProperties; import org.openecomp.mso.properties.MsoPropertiesException; import org.openecomp.mso.properties.MsoPropertiesFactory; -import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.woorea.openstack.base.client.OpenStackConnectException; @@ -68,7 +77,7 @@ import com.woorea.openstack.keystone.model.Access; import com.woorea.openstack.keystone.model.Authentication; import com.woorea.openstack.keystone.utils.KeystoneUtils; -public class MsoHeatUtils extends MsoCommonUtils { +public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin{ private MsoPropertiesFactory msoPropertiesFactory; @@ -112,6 +121,13 @@ public class MsoHeatUtils extends MsoCommonUtils { /** * This constructor MUST be used ONLY in the JUNIT tests, not for real code. + */ + public MsoHeatUtils() { + + } + + /** + * This constructor MUST be used ONLY in the JUNIT tests, not for real code. * The MsoPropertiesFactory will be added by EJB injection. * * @param msoPropID ID of the mso pro config as defined in web.xml @@ -1643,4 +1659,204 @@ public class MsoHeatUtils extends MsoCommonUtils { return sb.toString(); } + /******************************************************************************* + * + * Methods (and associated utilities) to implement the VduPlugin interface + * + *******************************************************************************/ + + /** + * VduPlugin interface for instantiate function. + * + * Translate the VduPlugin parameters to the corresponding 'createStack' parameters, + * and then invoke the existing function. + */ + public VduInstance instantiateVdu ( + CloudInfo cloudInfo, + String instanceName, + Map<String,Object> inputs, + VduModelInfo vduModel, + boolean rollbackOnFailure) + throws VduException + { + String cloudSiteId = cloudInfo.getCloudSiteId(); + String tenantId = cloudInfo.getTenantId(); + + // Translate the VDU ModelInformation structure to that which is needed for + // creating the Heat stack. Loop through the artifacts, looking specifically + // for MAIN_TEMPLATE and ENVIRONMENT. Any other artifact will + // be attached as a FILE. + String heatTemplate = null; + Map<String,Object> nestedTemplates = new HashMap<>(); + Map<String,Object> files = new HashMap<>(); + String heatEnvironment = null; + + for (VduArtifact vduArtifact: vduModel.getArtifacts()) { + if (vduArtifact.getType() == ArtifactType.MAIN_TEMPLATE) { + heatTemplate = new String(vduArtifact.getContent()); + } + else if (vduArtifact.getType() == ArtifactType.NESTED_TEMPLATE) { + nestedTemplates.put(vduArtifact.getName(), new String(vduArtifact.getContent())); + } + else if (vduArtifact.getType() == ArtifactType.ENVIRONMENT) { + heatEnvironment = new String(vduArtifact.getContent()); + } + } + + try { + StackInfo stackInfo = createStack (cloudSiteId, + tenantId, + instanceName, + heatTemplate, + inputs, + true, // poll for completion + vduModel.getTimeoutMinutes(), + heatEnvironment, + nestedTemplates, + files, + rollbackOnFailure); + + // Populate a vduInstance from the StackInfo + VduInstance vduInstance = stackInfoToVduInstance(stackInfo); + + return vduInstance; + } + catch (Exception e) { + throw new VduException ("MsoHeatUtils (instantiateVDU): createStack Exception", e); + } + } + + + /** + * VduPlugin interface for query function. + */ + public VduInstance queryVdu (CloudInfo cloudInfo, String instanceId) + throws VduException + { + String cloudSiteId = cloudInfo.getCloudSiteId(); + String tenantId = cloudInfo.getTenantId(); + + try { + // Query the Cloudify Deployment object and populate a VduInstance + StackInfo stackInfo = queryStack (cloudSiteId, tenantId, instanceId); + + VduInstance vduInstance = stackInfoToVduInstance(stackInfo); + + return vduInstance; + } + catch (Exception e) { + throw new VduException ("MsoHeatUtile (queryVdu): queryStack Exception ", e); + } + } + + + /** + * VduPlugin interface for delete function. + */ + public VduInstance deleteVdu (CloudInfo cloudInfo, String instanceId, int timeoutMinutes) + throws VduException + { + String cloudSiteId = cloudInfo.getCloudSiteId(); + String tenantId = cloudInfo.getTenantId(); + + try { + // Delete the Heat stack + StackInfo stackInfo = deleteStack (tenantId, cloudSiteId, instanceId, true); + + // Populate a VduInstance based on the deleted Cloudify Deployment object + VduInstance vduInstance = stackInfoToVduInstance(stackInfo); + + // Override return state to DELETED (HeatUtils sets to NOTFOUND) + vduInstance.getStatus().setState(VduStateType.DELETED); + + return vduInstance; + } + catch (Exception e) { + throw new VduException ("Delete VDU Exception", e); + } + } + + + /** + * VduPlugin interface for update function. + * + * Update is currently not supported in the MsoHeatUtils implementation of VduPlugin. + * Just return a VduException. + * + */ + public VduInstance updateVdu ( + CloudInfo cloudInfo, + String instanceId, + Map<String,Object> inputs, + VduModelInfo vduModel, + boolean rollbackOnFailure) + throws VduException + { + throw new VduException ("MsoHeatUtils: updateVdu interface not supported"); + } + + + /* + * Convert the local DeploymentInfo object (Cloudify-specific) to a generic VduInstance object + */ + private VduInstance stackInfoToVduInstance (StackInfo stackInfo) + { + VduInstance vduInstance = new VduInstance(); + + // The full canonical name as the instance UUID + vduInstance.setVduInstanceId(stackInfo.getCanonicalName()); + vduInstance.setVduInstanceName(stackInfo.getName()); + + // Copy inputs and outputs + vduInstance.setInputs(stackInfo.getParameters()); + vduInstance.setOutputs(stackInfo.getOutputs()); + + // Translate the status elements + vduInstance.setStatus(stackStatusToVduStatus (stackInfo)); + + return vduInstance; + } + + private VduStatus stackStatusToVduStatus (StackInfo stackInfo) + { + VduStatus vduStatus = new VduStatus(); + + // Map the status fields to more generic VduStatus. + // There are lots of HeatStatus values, so this is a bit long... + HeatStatus heatStatus = stackInfo.getStatus(); + String statusMessage = stackInfo.getStatusMessage(); + + if (heatStatus == HeatStatus.INIT || heatStatus == HeatStatus.BUILDING) { + vduStatus.setState(VduStateType.INSTANTIATING); + vduStatus.setLastAction((new PluginAction ("create", "in_progress", statusMessage))); + } + else if (heatStatus == HeatStatus.NOTFOUND) { + vduStatus.setState(VduStateType.NOTFOUND); + } + else if (heatStatus == HeatStatus.CREATED) { + vduStatus.setState(VduStateType.INSTANTIATED); + vduStatus.setLastAction((new PluginAction ("create", "complete", statusMessage))); + } + else if (heatStatus == HeatStatus.UPDATED) { + vduStatus.setState(VduStateType.INSTANTIATED); + vduStatus.setLastAction((new PluginAction ("update", "complete", statusMessage))); + } + else if (heatStatus == HeatStatus.UPDATING) { + vduStatus.setState(VduStateType.UPDATING); + vduStatus.setLastAction((new PluginAction ("update", "in_progress", statusMessage))); + } + else if (heatStatus == HeatStatus.DELETING) { + vduStatus.setState(VduStateType.DELETING); + vduStatus.setLastAction((new PluginAction ("delete", "in_progress", statusMessage))); + } + else if (heatStatus == HeatStatus.FAILED) { + vduStatus.setState(VduStateType.FAILED); + vduStatus.setErrorMessage(stackInfo.getStatusMessage()); + } else { + vduStatus.setState(VduStateType.UNKNOWN); + } + + return vduStatus; + } + } diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapters/vdu/BeansTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapters/vdu/BeansTest.java new file mode 100644 index 0000000000..1452c1569c --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapters/vdu/BeansTest.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 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.openecomp.mso.adapters.vdu; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class BeansTest { + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Test + public void pojoStructure() { + test("org.openecomp.mso.adapters.vdu"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java new file mode 100644 index 0000000000..821522fedc --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java @@ -0,0 +1,143 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 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.cloudify.utils; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.openecomp.mso.cloud.CloudConfigFactory; +import org.openecomp.mso.cloud.CloudSite; +import org.openecomp.mso.cloudify.beans.DeploymentInfo; +import org.openecomp.mso.cloudify.exceptions.MsoCloudifyManagerNotFound; +import org.openecomp.mso.cloudify.v3.client.Cloudify; +import org.openecomp.mso.cloudify.v3.model.DeploymentOutputs; +import org.openecomp.mso.openstack.exceptions.MsoException; +import org.openecomp.mso.properties.MsoPropertiesFactory; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.HashMap; +import java.util.Map; +import static org.mockito.Mockito.mock; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MsoCloudifyUtils.class}) + + +public class MsoCloudifyUtilsTest { + + + @Mock + MsoPropertiesFactory msoPropertiesFactory; + + @Mock + CloudConfigFactory cloudConfigFactory; + + @Mock + DeploymentInfo deploymentInfo; + + @Mock + Cloudify cloudify; + + @Mock + DeploymentOutputs deploymentOutputs; + + @Mock + CloudSite cloudSite; + + @Test(expected = NullPointerException.class) + public void testCreateandInstallDeployment() throws MsoException { + + MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); + Map<String, Object> inputs = new HashMap<>(); + inputs.put("1", "value"); + + mcu.createAndInstallDeployment("cloudSiteId", "tenantId", "deploymentId", "blueprintId" + , inputs, true, 1, true); + + assert (mcu.createAndInstallDeployment("cloudSiteId", "tenantId", "deploymentId", "blueprintId" + , inputs, true, 1, true) != null); + + + } + + @Test(expected = NullPointerException.class) + public void testDeploymentOutputs() throws MsoException { + + MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); + mcu.queryDeployment("cloudSiteId", "tenantId", "deploymentId"); + assert (mcu.queryDeployment("cloudSiteId", "tenantId", "deploymentId") != null); + } + + @Test(expected = NullPointerException.class) + public void testUninstallAndDeleteDeployment() throws MsoException { + + MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); + mcu.uninstallAndDeleteDeployment("cloudSiteId", "tenantId", "deploymentId", 1); + assert (mcu.uninstallAndDeleteDeployment("cloudSiteId", "tenantId", "deploymentId", 1) != null); + } + + @Test(expected = NullPointerException.class) + public void testIsBlueprintLoaded() throws MsoException { + + MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); + mcu.isBlueprintLoaded("cloudSiteId", "blueprintId"); + assertTrue(mcu.isBlueprintLoaded("cloudSiteId", "blueprintId")); + } + + @Test(expected = MsoCloudifyManagerNotFound.class) + public void testCloudifyClient() throws MsoException { + + MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); + mcu.getCloudifyClient(cloudSite); + assert (mcu.getCloudifyClient(cloudSite) != null); + + } + + + @Test(expected = NullPointerException.class) + public void testuploadBlueprint() throws MsoException { + + MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); + + Map<String, byte[]> blueprintFiles = new HashMap<String, byte[]>(); + byte[] byteArray = new byte[]{8, 1, 2, 8}; + blueprintFiles.put("1", byteArray); + + mcu.uploadBlueprint("cloudSiteId", "blueprintId", "mainFileName", blueprintFiles, false); + + } + + @Test(expected = NullPointerException.class) + public void testqueryDeployment() throws MsoException { + + MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory); + mcu.queryDeployment(cloudify, "deploymentId"); + assert (mcu.queryDeployment(cloudify, "deploymentId") != null); + + + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest2.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest2.java new file mode 100644 index 0000000000..05608b4d99 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest2.java @@ -0,0 +1,254 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 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.openecomp.mso.cloudify.utils;
+
+import static com.shazam.shazamcrest.MatcherAssert.assertThat;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.mso.adapters.vdu.CloudInfo;
+import org.openecomp.mso.adapters.vdu.PluginAction;
+import org.openecomp.mso.adapters.vdu.VduArtifact;
+import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType;
+import org.openecomp.mso.adapters.vdu.VduInstance;
+import org.openecomp.mso.adapters.vdu.VduModelInfo;
+import org.openecomp.mso.adapters.vdu.VduStateType;
+import org.openecomp.mso.adapters.vdu.VduStatus;
+import org.openecomp.mso.cloud.CloudConfig;
+import org.openecomp.mso.cloud.CloudIdentity;
+import org.openecomp.mso.cloud.CloudSite;
+import org.openecomp.mso.cloudify.beans.DeploymentInfo;
+import org.openecomp.mso.cloudify.beans.DeploymentStatus;
+import org.openecomp.mso.cloudify.v3.client.Cloudify;
+import org.openecomp.mso.cloudify.v3.model.AzureConfig;
+import org.openecomp.mso.cloudify.v3.model.OpenstackConfig;
+import org.openecomp.mso.openstack.exceptions.MsoException;
+
+public class MsoCloudifyUtilsTest2 {
+
+ @Test
+ public void instantiateVduTest() throws MsoException {
+ VduInstance expected = new VduInstance();
+ expected.setVduInstanceId("id");
+ expected.setVduInstanceName("id");
+ VduStatus status = new VduStatus();
+ status.setState(VduStateType.INSTANTIATED);
+ status.setLastAction(new PluginAction(null, null, null));
+ expected.setStatus(status);
+
+ MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class);
+ CloudSite site = new CloudSite();
+ Optional<CloudSite> opSite = Optional.ofNullable(site);
+ CloudConfig config = Mockito.mock(CloudConfig.class);
+ cloudify.cloudConfig = config;
+ Cloudify cloudifyClient = new Cloudify("cloudSite");
+ CloudInfo cloudInfo = new CloudInfo();
+ cloudInfo.setCloudSiteId("cloudSiteId");
+ cloudInfo.setTenantId("tenantId");
+ VduModelInfo vduModel = new VduModelInfo();
+ vduModel.setModelCustomizationUUID("blueprintId");
+ vduModel.setTimeoutMinutes(1);
+ VduArtifact artifact = new VduArtifact();
+ artifact.setName("name");
+ artifact.setType(ArtifactType.MAIN_TEMPLATE);
+ byte[] content = new byte[1];
+ artifact.setContent(content);
+ List<VduArtifact> artifacts = new ArrayList<>();
+ artifacts.add(artifact);
+ vduModel.setArtifacts(artifacts);
+ DeploymentInfo deployment = new DeploymentInfo();
+ deployment.setId("id");
+ deployment.setStatus(DeploymentStatus.INSTALLED);
+ Map<String, byte[]> blueprintFiles = new HashMap<>();
+ blueprintFiles.put(artifact.getName(), artifact.getContent());
+ String instanceName = "instanceName";
+ Map<String, Object> inputs = new HashMap<>();
+ boolean rollbackOnFailure = true;
+
+ when(config.getCloudSite(cloudInfo.getCloudSiteId())).thenReturn(opSite);
+ doReturn(false).when(cloudify).isBlueprintLoaded(cloudInfo.getCloudSiteId(),
+ vduModel.getModelCustomizationUUID());
+ doReturn(cloudifyClient).when(cloudify).getCloudifyClient(site);
+ doReturn(true).when(cloudify).uploadBlueprint(cloudifyClient, vduModel.getModelCustomizationUUID(),
+ artifact.getName(), blueprintFiles);
+ doReturn(deployment).when(cloudify).createAndInstallDeployment(cloudInfo.getCloudSiteId(),
+ cloudInfo.getTenantId(), instanceName, vduModel.getModelCustomizationUUID(), inputs, true,
+ vduModel.getTimeoutMinutes(), rollbackOnFailure);
+
+ VduInstance actual = cloudify.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure);
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void queryVduTest() throws MsoException {
+ VduInstance expected = new VduInstance();
+ expected.setVduInstanceId("id");
+ expected.setVduInstanceName("id");
+ VduStatus status = new VduStatus();
+ status.setState(VduStateType.INSTANTIATED);
+ status.setLastAction(new PluginAction(null, null, null));
+ expected.setStatus(status);
+
+ CloudInfo cloudInfo = new CloudInfo();
+ cloudInfo.setCloudSiteId("cloudSiteId");
+ cloudInfo.setTenantId("tenantId");
+ DeploymentInfo deployment = new DeploymentInfo();
+ deployment.setId("id");
+ deployment.setStatus(DeploymentStatus.INSTALLED);
+ String instanceId = "instanceId";
+
+ MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class);
+
+ doReturn(deployment).when(cloudify).queryDeployment(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(),
+ instanceId);
+
+ VduInstance actual = cloudify.queryVdu(cloudInfo, instanceId);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void deleteVduTest() throws MsoException {
+ VduInstance expected = new VduInstance();
+ expected.setVduInstanceId("id");
+ expected.setVduInstanceName("id");
+ VduStatus status = new VduStatus();
+ status.setState(VduStateType.DELETING);
+ status.setLastAction(new PluginAction("deleting", null, null));
+ expected.setStatus(status);
+
+ CloudInfo cloudInfo = new CloudInfo();
+ cloudInfo.setCloudSiteId("cloudSiteId");
+ cloudInfo.setTenantId("tenantId");
+ String instanceId = "instanceId";
+ int timeoutMinutes = 1;
+ DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class);
+ deployment.setId("id");
+ deployment.setStatus(DeploymentStatus.CREATED);
+ when(deployment.getId()).thenReturn("id");
+ when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED);
+ when(deployment.getLastAction()).thenReturn("deleting");
+ MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class);
+ doReturn(deployment).when(cloudify).uninstallAndDeleteDeployment(cloudInfo.getCloudSiteId(),
+ cloudInfo.getTenantId(), instanceId, timeoutMinutes);
+
+ VduInstance actual = cloudify.deleteVdu(cloudInfo, instanceId, timeoutMinutes);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void deploymentInfoToVduInstanceTest() {
+ VduInstance expected = new VduInstance();
+ expected.setVduInstanceId("id");
+ expected.setVduInstanceName("id");
+ VduStatus status = new VduStatus();
+ status.setState(VduStateType.DELETING);
+ status.setLastAction(new PluginAction("deleting", null, null));
+ expected.setStatus(status);
+
+ DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class);
+ deployment.setId("id");
+ deployment.setStatus(DeploymentStatus.CREATED);
+ when(deployment.getId()).thenReturn("id");
+ when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED);
+ when(deployment.getLastAction()).thenReturn("deleting");
+
+ MsoCloudifyUtils cloudify = new MsoCloudifyUtils();
+
+ VduInstance actual = cloudify.deploymentInfoToVduInstance(deployment);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void deploymentStatusToVduStatusTest() {
+ VduStatus expected = new VduStatus();
+ expected.setState(VduStateType.DELETING);
+ expected.setLastAction(new PluginAction("deleting", null, null));
+
+ DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class);
+ deployment.setId("id");
+ deployment.setStatus(DeploymentStatus.CREATED);
+ when(deployment.getId()).thenReturn("id");
+ when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED);
+ when(deployment.getLastAction()).thenReturn("deleting");
+
+ MsoCloudifyUtils cloudify = new MsoCloudifyUtils();
+
+ VduStatus actual = cloudify.deploymentStatusToVduStatus(deployment);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void getOpenstackConfigTest() {
+ OpenstackConfig expected = new OpenstackConfig();
+ expected.setRegion("regionId");
+ expected.setAuthUrl("identityUrl");
+ expected.setUsername("msoId");
+ expected.setPassword("msoPass");
+ expected.setTenantName("tenantId");
+
+ MsoCloudifyUtils cloudify = new MsoCloudifyUtils();
+ CloudSite cloudSite = Mockito.mock(CloudSite.class);
+ CloudIdentity cloudIdentity = Mockito.mock(CloudIdentity.class);
+ when(cloudSite.getIdentityService()).thenReturn(cloudIdentity);
+ when(cloudSite.getRegionId()).thenReturn("regionId");
+ when(cloudIdentity.getIdentityUrl()).thenReturn("identityUrl");
+ when(cloudIdentity.getMsoId()).thenReturn("msoId");
+ when(cloudIdentity.getMsoPass()).thenReturn("msoPass");
+ String tenantId = "tenantId";
+ OpenstackConfig actual = cloudify.getOpenstackConfig(cloudSite, tenantId);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void getAzureConfigTest() {
+ AzureConfig expected = new AzureConfig();
+ expected.setSubscriptionId("subscriptionId");
+ expected.setTenantId("tenantId");
+ expected.setClientId("msoId");
+ expected.setClientSecret("msoPass");
+
+ MsoCloudifyUtils cloudify = new MsoCloudifyUtils();
+ CloudSite cloudSite = Mockito.mock(CloudSite.class);
+ CloudIdentity cloudIdentity = Mockito.mock(CloudIdentity.class);
+ when(cloudSite.getIdentityService()).thenReturn(cloudIdentity);
+ when(cloudIdentity.getAdminTenant()).thenReturn("subscriptionId");
+ when(cloudIdentity.getMsoId()).thenReturn("msoId");
+ when(cloudIdentity.getMsoPass()).thenReturn("msoPass");
+ String tenantId = "tenantId";
+ AzureConfig actual = cloudify.getAzureConfig(cloudSite, tenantId);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java new file mode 100644 index 0000000000..c50ffb03ef --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest.java @@ -0,0 +1,221 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 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.openstack.utils; + + +import com.woorea.openstack.heat.Heat; +import com.woorea.openstack.heat.model.Stack; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.openecomp.mso.cloud.CloudConfigFactory; +import org.openecomp.mso.cloud.CloudSite; +import org.openecomp.mso.openstack.beans.HeatStatus; +import org.openecomp.mso.openstack.beans.StackInfo; +import org.openecomp.mso.openstack.exceptions.MsoException; +import org.openecomp.mso.openstack.exceptions.MsoTenantNotFound; +import org.openecomp.mso.properties.MsoPropertiesFactory; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.doReturn; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MsoHeatUtils.class}) + + +public class MsoHeatUtilsTest { + + @Mock + + StackInfo stackInfo; + + @Mock + + MsoPropertiesFactory msoPropertiesFactory; + + @Mock + + CloudConfigFactory cloudConfigFactory; + + @Mock + + Heat heatClient; + + @Mock + + CloudSite cloudSite; + + @Test(expected = NullPointerException.class) + public void testCreateStack() throws MsoException + { + + MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory)); + Map<String,String>metadata=new HashMap<>(); + metadata.put("1", "value"); + mht.createStack("cloudSiteId", + "tenantId", + "stackName", + "heatTemplate", + metadata, + true, + 1); + doReturn(mht.createStack("cloudSiteId", + "tenantId", + "stackName", + "heatTemplate", + metadata, + true, + 1, + null, null, + null, + true)); + + } + + @Test(expected = NullPointerException.class) + public void testCreateStackOne() throws MsoException + { + MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory)); + Map<String,String>metadata=new HashMap<>(); + metadata.put("1", "value"); + mht.createStack("cloudSiteId", + "tenantId", + "stackName", + "heatTemplate", + metadata, + true, + 1, + "env"); + doReturn(mht.createStack("cloudSiteId", + "tenantId", + "stackName", + "heatTemplate", + metadata, + true, + 1, + "env", null, + null, + true)); + } + + @Test(expected = NullPointerException.class) + public void testCreateStackTwo() throws MsoException + { + MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory)); + Map<String,String>metadata=new HashMap<>(); + metadata.put("1", "value"); + Map<String,Object>fileMap=new HashMap<>(); + fileMap.put("2", "value"); + mht.createStack("cloudSiteId", + "tenantId", + "stackName", + "heatTemplate", + metadata, + true, + 1, + "env", + fileMap); + doReturn(mht.createStack("cloudSiteId", + "tenantId", + "stackName", + "heatTemplate", + metadata, + true, + 1, + "env", fileMap, + null, + true)); + } + + @Test(expected = NullPointerException.class) + public void testCreateStackThree() throws MsoException + { + MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory)); + Map<String,String>metadata=new HashMap<>(); + metadata.put("1", "value"); + Map<String,Object>fileMap=new HashMap<>(); + fileMap.put("2", "value"); + Map<String,Object>heatFileMap=new HashMap<>(); + heatFileMap.put("3", "value"); + mht.createStack("cloudSiteId", + "tenantId", + "stackName", + "heatTemplate", + metadata, + true, + 1, + "env", + fileMap, + heatFileMap); + doReturn(mht.createStack("cloudSiteId", + "tenantId", + "stackName", + "heatTemplate", + metadata, + true, + 1, + "env", fileMap, + heatFileMap, + true)); + } + + @Test(expected = NullPointerException.class) + + + public void testqueryStack() throws MsoException + { + MsoHeatUtils mht = PowerMockito.spy(new MsoHeatUtils("msoPropID" ,msoPropertiesFactory,cloudConfigFactory)); + + mht.queryStack("cloudSiteId","tenantId","stackName"); + + try { + heatClient = mht.getHeatClient (cloudSite, "tenantId"); + assertNotNull(heatClient); + + } catch (MsoTenantNotFound e) { + doReturn(new StackInfo ("stackName", HeatStatus.NOTFOUND)); + } catch (MsoException me) { + + me.addContext ("QueryStack"); + throw me; + } + + Stack heatStack = mht.queryHeatStack (heatClient, "stackName"); + + assertNull(heatStack); + StackInfo stackInfo = new StackInfo ("stackName", HeatStatus.NOTFOUND); + doReturn(stackInfo); + + assertNotNull(heatStack); + doReturn(new StackInfo (heatStack)); + + + + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java new file mode 100644 index 0000000000..a0ab8e6b11 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java @@ -0,0 +1,169 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 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.openecomp.mso.openstack.utils;
+
+import static com.shazam.shazamcrest.MatcherAssert.assertThat;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.mso.adapters.vdu.CloudInfo;
+import org.openecomp.mso.adapters.vdu.PluginAction;
+import org.openecomp.mso.adapters.vdu.VduArtifact;
+import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType;
+import org.openecomp.mso.adapters.vdu.VduInstance;
+import org.openecomp.mso.adapters.vdu.VduModelInfo;
+import org.openecomp.mso.adapters.vdu.VduStateType;
+import org.openecomp.mso.adapters.vdu.VduStatus;
+import org.openecomp.mso.cloud.CloudConfig;
+import org.openecomp.mso.cloud.CloudSite;
+import org.openecomp.mso.cloudify.beans.DeploymentInfo;
+import org.openecomp.mso.cloudify.beans.DeploymentStatus;
+import org.openecomp.mso.cloudify.utils.MsoCloudifyUtils;
+import org.openecomp.mso.openstack.beans.HeatStatus;
+import org.openecomp.mso.openstack.beans.StackInfo;
+import org.openecomp.mso.openstack.exceptions.MsoException;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+public class MsoHeatUtilsTest2 {
+
+ @Test
+ public void instantiateVduTest() throws MsoException, JsonProcessingException {
+ VduInstance expected = new VduInstance();
+ expected.setVduInstanceId("canonicalName");
+ expected.setVduInstanceName("name");
+ VduStatus status = new VduStatus();
+ status.setState(VduStateType.INSTANTIATED);
+ status.setLastAction((new PluginAction("create", "complete", "")));
+ expected.setStatus(status);
+
+ MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class);
+ CloudSite site = new CloudSite();
+ Optional<CloudSite> opSite = Optional.ofNullable(site);
+ CloudConfig config = Mockito.mock(CloudConfig.class);
+ heatUtils.cloudConfig = config;
+ CloudInfo cloudInfo = new CloudInfo();
+ cloudInfo.setCloudSiteId("cloudSiteId");
+ cloudInfo.setTenantId("tenantId");
+ VduModelInfo vduModel = new VduModelInfo();
+ vduModel.setModelCustomizationUUID("blueprintId");
+ vduModel.setTimeoutMinutes(1);
+ VduArtifact artifact = new VduArtifact();
+ artifact.setName("name");
+ artifact.setType(ArtifactType.MAIN_TEMPLATE);
+ byte[] content = new byte[1];
+ artifact.setContent(content);
+ List<VduArtifact> artifacts = new ArrayList<>();
+ artifacts.add(artifact);
+ vduModel.setArtifacts(artifacts);
+ Map<String, byte[]> blueprintFiles = new HashMap<>();
+ blueprintFiles.put(artifact.getName(), artifact.getContent());
+ String instanceName = "instanceName";
+ Map<String, Object> inputs = new HashMap<>();
+ boolean rollbackOnFailure = true;
+ String heatTemplate = new String(artifact.getContent());
+ when(config.getCloudSite(cloudInfo.getCloudSiteId())).thenReturn(opSite);
+ Map<String, Object> nestedTemplates = new HashMap<String, Object>();
+ Map<String, Object> files = new HashMap<String, Object>();
+
+ StackInfo stackInfo = new StackInfo();
+ stackInfo.setCanonicalName("canonicalName");
+ stackInfo.setName("name");
+ stackInfo.setStatus(HeatStatus.CREATED);
+
+ doReturn(stackInfo).when(heatUtils).createStack(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(),
+ instanceName, heatTemplate, inputs, true, vduModel.getTimeoutMinutes(), null, nestedTemplates, files,
+ rollbackOnFailure);
+
+ VduInstance actual = heatUtils.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void queryVduTest() throws MsoException, JsonProcessingException {
+ VduInstance expected = new VduInstance();
+ expected.setVduInstanceId("canonicalName");
+ expected.setVduInstanceName("name");
+ VduStatus status = new VduStatus();
+ status.setState(VduStateType.INSTANTIATED);
+ status.setLastAction((new PluginAction("create", "complete", "")));
+ expected.setStatus(status);
+
+ CloudInfo cloudInfo = new CloudInfo();
+ cloudInfo.setCloudSiteId("cloudSiteId");
+ cloudInfo.setTenantId("tenantId");
+ String instanceId = "instanceId";
+
+ StackInfo stackInfo = new StackInfo();
+ stackInfo.setCanonicalName("canonicalName");
+ stackInfo.setName("name");
+ stackInfo.setStatus(HeatStatus.CREATED);
+
+ MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class);
+
+ doReturn(stackInfo).when(heatUtils).queryStack(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(), instanceId);
+
+ VduInstance actual = heatUtils.queryVdu(cloudInfo, instanceId);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+ @Test
+ public void deleteVduTest() throws MsoException {
+ VduInstance expected = new VduInstance();
+ expected.setVduInstanceId("canonicalName");
+ expected.setVduInstanceName("name");
+ VduStatus status = new VduStatus();
+ status.setState(VduStateType.DELETED);
+ expected.setStatus(status);
+
+ CloudInfo cloudInfo = new CloudInfo();
+ cloudInfo.setCloudSiteId("cloudSiteId");
+ cloudInfo.setTenantId("tenantId");
+ String instanceId = "instanceId";
+
+ StackInfo stackInfo = new StackInfo();
+ stackInfo.setCanonicalName("canonicalName");
+ stackInfo.setName("name");
+ stackInfo.setStatus(HeatStatus.NOTFOUND);
+
+ int timeoutInMinutes = 1;
+
+ MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class);
+
+ doReturn(stackInfo).when(heatUtils).deleteStack( cloudInfo.getTenantId(), cloudInfo.getCloudSiteId(), instanceId, true);
+
+ VduInstance actual = heatUtils.deleteVdu(cloudInfo, instanceId, timeoutInMinutes);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+
+}
diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoAdapterExceptionTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoAdapterExceptionTest.java new file mode 100644 index 0000000000..738fe9e4d9 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoAdapterExceptionTest.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoAdapterExceptionTest { + MsoAdapterException msoAdapterException = new MsoAdapterException("test"); + MsoAdapterException msoAdapterExceptionThr = new MsoAdapterException("test" , new Throwable()); +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudIdentityNotFoundTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudIdentityNotFoundTest.java new file mode 100644 index 0000000000..4027aa6342 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudIdentityNotFoundTest.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoCloudIdentityNotFoundTest { + MsoCloudIdentityNotFound msoCloudIdentityNotFound = new MsoCloudIdentityNotFound(); + MsoCloudIdentityNotFound msoCloudIdentityNotFoundStr = new MsoCloudIdentityNotFound("test"); + public String str = msoCloudIdentityNotFound.toString(); +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFoundTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFoundTest.java new file mode 100644 index 0000000000..cac02152e0 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFoundTest.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoCloudSiteNotFoundTest { + MsoCloudSiteNotFound msoCloudSiteNotFound = new MsoCloudSiteNotFound(); + MsoCloudSiteNotFound msoCloudSiteNotFoundStr = new MsoCloudSiteNotFound("test"); + public String str = msoCloudSiteNotFoundStr.toString(); + +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoIOExceptionTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoIOExceptionTest.java new file mode 100644 index 0000000000..d1f4db778e --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoIOExceptionTest.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoIOExceptionTest { + MsoIOException msoIOException = new MsoIOException("test"); + MsoIOException msoIOExceptionTh = new MsoIOException("test" , new Throwable()); + public String str = msoIOException.toString(); +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExistsTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExistsTest.java new file mode 100644 index 0000000000..c5217e4933 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExistsTest.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoNetworkAlreadyExistsTest { + MsoNetworkAlreadyExists msoNetworkAlreadyExists = new MsoNetworkAlreadyExists("test","test","test"); +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFoundTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFoundTest.java new file mode 100644 index 0000000000..ea74efcf42 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFoundTest.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoNetworkNotFoundTest { + MsoNetworkNotFound msoNetworkNotFound =new MsoNetworkNotFound("test","test","test"); +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackExceptionTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackExceptionTest.java new file mode 100644 index 0000000000..58cea958df --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackExceptionTest.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoOpenstackExceptionTest { + MsoOpenstackException msoOpenstackException= new MsoOpenstackException(404,"test","test"); + MsoOpenstackException msoOpenstackExceptionEx= new MsoOpenstackException(404,"test","test",new Exception()); + public String str = msoOpenstackException.toString(); + +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExistsTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExistsTest.java new file mode 100644 index 0000000000..f36ddfe7a1 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExistsTest.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoStackAlreadyExistsTest { + MsoStackAlreadyExists msoStackAlreadyExists = new MsoStackAlreadyExists("test","test","test"); +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFoundTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFoundTest.java new file mode 100644 index 0000000000..e422c04fcc --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFoundTest.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoStackNotFoundTest { + MsoStackNotFound msoStackNotFound = new MsoStackNotFound("test","test","test"); +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExistsTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExistsTest.java new file mode 100644 index 0000000000..d9e83063d1 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExistsTest.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoTenantAlreadyExistsTest { + MsoTenantAlreadyExists msoTenantAlreadyExists = new MsoTenantAlreadyExists("test","test"); +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFoundTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFoundTest.java new file mode 100644 index 0000000000..a8dd6c6afb --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFoundTest.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.openstack.exceptions; + +public class MsoTenantNotFoundTest { + MsoTenantNotFound msoTenantNotFound = new MsoTenantNotFound("test","test"); +} diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionTest.java new file mode 100644 index 0000000000..365c9abcf5 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryExceptionTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.catalogdb.catalogrest; + +import org.junit.Test; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; + +public class CatalogQueryExceptionTest { + @Test + public void catalogQueryExceptionConstructor(){ + CatalogQueryException messageCatalogQueryException = new CatalogQueryException("TestMessage"); + assertNotNull(messageCatalogQueryException.getMessage()); + assertEquals("TestMessage",messageCatalogQueryException.getMessage()); + + CatalogQueryException paramsCatalogQueryException = new CatalogQueryException("TestMessage",CatalogQueryExceptionCategory.INTERNAL,true,"messageID"); + assertParams(paramsCatalogQueryException); + + CatalogQueryException defaultCatalogQueryException = new CatalogQueryException(); + defaultCatalogQueryException.setCategory(CatalogQueryExceptionCategory.INTERNAL); + defaultCatalogQueryException.setMessage("TestMessage"); + defaultCatalogQueryException.setRolledBack(true); + defaultCatalogQueryException.setMessageId("messageID"); + assertParams(defaultCatalogQueryException); + } + + private void assertParams(CatalogQueryException paramsCatalogQueryException) { + assertNotNull(paramsCatalogQueryException.getMessage()); + assertEquals("TestMessage",paramsCatalogQueryException.getMessage()); + assertNotNull(paramsCatalogQueryException.getCategory()); + assertEquals(CatalogQueryExceptionCategory.INTERNAL,paramsCatalogQueryException.getCategory()); + assertNotNull(paramsCatalogQueryException.getRolledBack()); + assertEquals(true,paramsCatalogQueryException.getRolledBack()); + assertNotNull(paramsCatalogQueryException.getMessageId()); + assertEquals("messageID",paramsCatalogQueryException.getMessageId()); + } +} diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTestException.java b/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTestException.java new file mode 100644 index 0000000000..994ce5dbb3 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTestException.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 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.requestsdb; + +import org.junit.Test; + +public class HealthCheckHandlerTestException { + + @Test(expected = NullPointerException.class) + public void testHealthCheckSiteNameNull() { + + HealthCheckHandler hcH = new HealthCheckHandler(); + hcH.healthcheck("request"); + } +} + + diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java index 5e3f79add6..c3949a6a79 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java @@ -20,6 +20,11 @@ package org.openecomp.mso.adapters.sdnc; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; @@ -74,14 +79,14 @@ public class ObjectFactoryTest { fail (); } String marshalled = writer.toString (); - assert(marshalled.contains ("<RequestId>reqid</RequestId>")); + assertThat(marshalled, containsString("<RequestId>reqid</RequestId>")); InputStream inputStream = new ByteArrayInputStream(marshalled.getBytes(Charset.forName("UTF-8"))); try { RequestHeader res2 = (RequestHeader) jaxbUnmarshaller.unmarshal (inputStream); - assert(res2.getCallbackUrl ().equals ("callback")); - assert(res2.getMsoAction ().equals ("action")); - assert(res2.getSvcOperation ().equals ("op")); + assertEquals("callback", res2.getCallbackUrl ()); + assertEquals("action", res2.getMsoAction ()); + assertEquals("op", res2.getSvcOperation ()); } catch (JAXBException e) { e.printStackTrace(); fail(); @@ -95,6 +100,14 @@ public class ObjectFactoryTest { public final void testCreateSDNCAdapterResponse () { ObjectFactory of = new ObjectFactory (); SDNCAdapterResponse ar = of.createSDNCAdapterResponse (); - assert (ar != null); + assertNotNull(ar); } + + @Test + public final void testCreateSDNCAdapterRequest () { + ObjectFactory of = new ObjectFactory (); + SDNCAdapterRequest ar = of.createSDNCAdapterRequest (); + assertNotNull(ar); + } + } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java index fa96b7983e..b9d88406f9 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java @@ -21,6 +21,9 @@ package org.openecomp.mso.adapters.sdnc; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.junit.BeforeClass; import org.junit.Test; import org.openecomp.mso.adapters.sdnc.SDNCAdapterRequest; @@ -46,9 +49,9 @@ public class SDNCAdapterRequestTest { public final void testtoString(){ ((SDNCAdapterRequest) sd).setRequestData("data"); ((SDNCAdapterRequest) sd).setRequestHeader(rh); - assert (((SDNCAdapterRequest) sd).getRequestData()!= null) ; - assert(((SDNCAdapterRequest) sd).getRequestData().equals("data")); - assert(((SDNCAdapterRequest) sd).getRequestHeader().equals(rh)); + assertNotNull(((SDNCAdapterRequest) sd).getRequestData()) ; + assertEquals("data", ((SDNCAdapterRequest) sd).getRequestData()); + assertEquals(rh, ((SDNCAdapterRequest) sd).getRequestHeader()); } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/CallbackHeaderTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/CallbackHeaderTest.java index 88d2b950b9..39518e2081 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/CallbackHeaderTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/CallbackHeaderTest.java @@ -20,8 +20,10 @@ package org.openecomp.mso.adapters.sdnc.client; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.junit.Test; -import org.openecomp.mso.adapters.sdnc.client.CallbackHeader; public class CallbackHeaderTest { @@ -32,16 +34,16 @@ public class CallbackHeaderTest { cb.setRequestId("413658f4-7f42-482e-b834-23a5c15657da-1474471336781"); cb.setResponseCode("200"); cb.setResponseMessage("OK"); - assert (cb.getRequestId() != null); - assert (cb.getResponseCode() != null); - assert (cb.getResponseMessage() != null); - assert (cb.getRequestId().equals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781")); - assert (cb.getResponseCode().equals("200")); - assert (cb.getResponseMessage().equals("OK")); + assertNotNull(cb.getRequestId()); + assertNotNull(cb.getResponseCode()); + assertNotNull(cb.getResponseMessage()); + assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", cb.getRequestId()); + assertEquals("200", cb.getResponseCode()); + assertEquals("OK", cb.getResponseMessage()); } @Test public void testtoString() { - assert (cb.toString() != null); + assertNotNull(cb.toString()); } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java index 63aa49cf54..ecffd1c5ad 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java @@ -21,6 +21,9 @@ package org.openecomp.mso.adapters.sdnc.client; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.junit.Test; import org.openecomp.mso.adapters.sdnc.client.CallbackHeader; import org.openecomp.mso.adapters.sdnc.client.SDNCAdapterCallbackRequest; @@ -35,17 +38,18 @@ public class SDNCAdapterCallbackRequestTest { { sdc.setCallbackHeader(ch); sdc.setRequestData("data"); - assert(sdc.getCallbackHeader()!=null); - assert(sdc.getRequestData()!=null); - assert(sdc.getCallbackHeader().equals(ch)); - assert(sdc.getRequestData().equals("data")); + assertNotNull(sdc.getCallbackHeader()); + assertNotNull(sdc.getRequestData()); + assertEquals(ch, sdc.getCallbackHeader()); + assertEquals("data", sdc.getRequestData()); } @Test public void testtoString() { - assert(ch.toString()!=null); + assertNotNull(ch.toString()); + assertNotNull(sdc.toString()); } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java index 17ba0d22f8..72b11708e6 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java @@ -20,6 +20,8 @@ package org.openecomp.mso.adapters.sdnc.impl; +import static org.junit.Assert.*; + import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; @@ -54,18 +56,31 @@ public class RequestTunablesTest { @Test public final void testRequestTunables () { RequestTunables rt = new RequestTunables (null, null, "op", null,msoPropertiesFactory); - assert(rt.getReqId ().length ()==0); + assertEquals(0, rt.getReqId ().length ()); rt = new RequestTunables ("reqId", "msoAction", null, "query",msoPropertiesFactory); rt.setTunables (); System.out.println(rt.toString ()); // assert (rt.getReqMethod ().equals ("toto")); - assert (rt.getTimeout () != null); - assert (rt.getAction ().equals ("query")); - assert (rt.getMsoAction ().equals ("msoAction")); - assert (rt.getHeaderName ().equals ("sdnc-request-header")); - assert (rt.getOperation ().length () == 0); - assert (rt.getAsyncInd ().equals ("N")); - assert (rt.getReqId ().equals ("reqId")); + assertNotNull(rt.getTimeout ()); + assertEquals("query", rt.getAction ()); + assertEquals("msoAction", rt.getMsoAction ()); + assertEquals("sdnc-request-header", rt.getHeaderName ()); + assertEquals(0, rt.getOperation ().length ()); + assertEquals("N", rt.getAsyncInd ()); + assertEquals("reqId", rt.getReqId ()); + } + + @Test + public final void testRequestTunablesSet() { + RequestTunables rt = new RequestTunables("reqId", "gammainternet", "service-configuration-operation", "changeactivate", msoPropertiesFactory); + rt.setTunables (); + assertNotNull(rt.getTimeout ()); + assertEquals("changeactivate", rt.getAction ()); + assertEquals("gammainternet", rt.getMsoAction ()); + assertEquals("sdnc-request-header", rt.getHeaderName ()); + assertEquals("service-configuration-operation", rt.getOperation ()); + assertEquals("N", rt.getAsyncInd ()); + assertEquals("reqId", rt.getReqId ()); } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCResponseTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCResponseTest.java index f8867ae4f8..f9c885f0eb 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCResponseTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCResponseTest.java @@ -43,7 +43,7 @@ public class SDNCResponseTest { @Test public void testtoString() { - assert(sdncresponse.toString()!=null); + assertNotNull(sdncresponse.toString()); } }
\ No newline at end of file diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java index 275c2acd14..77d22e44df 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java @@ -20,6 +20,8 @@ package org.openecomp.mso.adapters.sdnc.util; +import static org.junit.Assert.assertEquals; + import java.util.UUID; import org.junit.Test; @@ -35,8 +37,8 @@ public class SDNCRequestIdUtilTest { String postfixedRequestId = originalRequestId + "-1466203712068"; String postfixedRequestId2 = originalRequestId + "-1466203712068-2"; - assert(SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId).equals(originalRequestId)); - assert(SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId2).equals(postfixedRequestId2)); + assertEquals(originalRequestId, SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId)); + assertEquals(postfixedRequestId2, SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId2)); } diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vdu/mapper/VfModuleCustomizationToVduMapper.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vdu/mapper/VfModuleCustomizationToVduMapper.java new file mode 100644 index 0000000000..22d988f4e4 --- /dev/null +++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vdu/mapper/VfModuleCustomizationToVduMapper.java @@ -0,0 +1,174 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 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.openecomp.mso.adapters.vdu.mapper;
+
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.mso.adapters.vdu.VduArtifact;
+import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType;
+import org.openecomp.mso.adapters.vdu.VduModelInfo;
+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.VfModuleCustomization;
+import org.openecomp.mso.logger.MsoLogger;
+import org.springframework.stereotype.Component;
+
+@Component
+public class VfModuleCustomizationToVduMapper {
+
+ private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
+
+ public VduModelInfo mapVfModuleCustomizationToVdu(VfModuleCustomization vfModuleCustom) throws Exception {
+ CatalogDatabase db = CatalogDatabase.getInstance();
+ VduModelInfo vduModel = new VduModelInfo();
+ vduModel.setModelCustomizationUUID(vfModuleCustom.getModelCustomizationUuid());
+ try {
+ // Map the cloud templates, attached files, and environment file
+ mapCloudTemplates(
+ db.getHeatTemplateByArtifactUuid(vfModuleCustom.getVfModule().getHeatTemplateArtifactUUId()),
+ vduModel);
+ mapCloudFiles(vfModuleCustom, vduModel);
+ mapEnvironment(db.getHeatEnvironmentByArtifactUuid(vfModuleCustom.getHeatEnvironmentArtifactUuid()),
+ vduModel);
+ } catch (Exception e) {
+ LOGGER.debug("unhandled exception in mapVfModuleCustomizationToVdu", e);
+ throw new Exception("Exception during mapVfModuleCustomizationToVdu " + e.getMessage());
+ } finally {
+ // Make sure DB session is closed
+ db.close();
+ }
+
+ return vduModel;
+ }
+
+ public VduModelInfo mapVfModuleCustVolumeToVdu(VfModuleCustomization vfModuleCustom) throws Exception {
+ CatalogDatabase db = CatalogDatabase.getInstance();
+ VduModelInfo vduModel = new VduModelInfo();
+ vduModel.setModelCustomizationUUID(vfModuleCustom.getModelCustomizationUuid());
+ try {
+ // Map the cloud templates, attached files, and environment file
+ mapCloudTemplates(
+ db.getHeatTemplateByArtifactUuid(vfModuleCustom.getVfModule().getVolHeatTemplateArtifactUUId()),
+ vduModel);
+ mapCloudFiles(vfModuleCustom, vduModel);
+ mapEnvironment(db.getHeatEnvironmentByArtifactUuid(vfModuleCustom.getVolEnvironmentArtifactUuid()),
+ vduModel);
+ } catch (Exception e) {
+ LOGGER.debug("unhandled exception in mapVfModuleCustVolumeToVdu", e);
+ throw new Exception("Exception during mapVfModuleCustVolumeToVdu " + e.getMessage());
+ } finally {
+ // Make sure DB session is closed
+ db.close();
+ }
+
+ return vduModel;
+ }
+
+ private void mapCloudTemplates(HeatTemplate heatTemplate, VduModelInfo vduModel) throws Exception {
+ // TODO: These catalog objects will be refactored to be
+ // non-Heat-specific
+ CatalogDatabase db = CatalogDatabase.getInstance();
+ try {
+ List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
+
+ // Main template. Also set the VDU timeout based on the main
+ // template.
+ vduArtifacts.add(mapHeatTemplateToVduArtifact(heatTemplate, ArtifactType.MAIN_TEMPLATE));
+ vduModel.setTimeoutMinutes(heatTemplate.getTimeoutMinutes());
+
+ // Nested templates
+ Map<String,Object> nestedTemplates = db.getNestedTemplates(heatTemplate.getArtifactUuid());
+ if (nestedTemplates != null) {
+ for (String name : nestedTemplates.keySet()) {
+ String body = (String) nestedTemplates.get(name);
+ VduArtifact vduArtifact = new VduArtifact(name, body.getBytes(), ArtifactType.NESTED_TEMPLATE);
+ vduArtifacts.add(vduArtifact);
+ }
+ }
+
+ } catch (Exception e) {
+ LOGGER.debug("unhandled exception in mapCloudTemplates", e);
+ throw new Exception("Exception during mapCloudTemplates " + e.getMessage());
+ } finally {
+ // Make sure DB session is closed
+ db.close();
+ }
+ }
+
+ private VduArtifact mapHeatTemplateToVduArtifact(HeatTemplate heatTemplate, ArtifactType artifactType) {
+ VduArtifact vduArtifact = new VduArtifact();
+ vduArtifact.setName(heatTemplate.getTemplateName());
+ vduArtifact.setContent(heatTemplate.getHeatTemplate().getBytes());
+ vduArtifact.setType(artifactType);
+ return vduArtifact;
+ }
+
+ private void mapCloudFiles(VfModuleCustomization vfModuleCustom, VduModelInfo vduModel) throws Exception {
+ // TODO: These catalog objects will be refactored to be
+ // non-Heat-specific
+ CatalogDatabase db = CatalogDatabase.getInstance();
+
+ try{
+ Map <String, HeatFiles> heatFiles = db.getHeatFilesForVfModule(vfModuleCustom.getVfModuleModelUuid());
+ if (heatFiles != null) {
+ for (HeatFiles heatFile: heatFiles.values()) {
+ mapCloudFileToVduArtifact(heatFile, ArtifactType.TEXT_FILE);
+ }
+ }
+ } catch (Exception e) {
+ LOGGER.debug("unhandled exception in mapCloudFiles", e);
+ throw new Exception("Exception during mapCloudFiles " + e.getMessage());
+ } finally {
+ // Make sure DB session is closed
+ db.close();
+ }
+
+ }
+
+ private VduArtifact mapCloudFileToVduArtifact(HeatFiles heatFile, ArtifactType artifactType) {
+ VduArtifact vduArtifact = new VduArtifact();
+ vduArtifact.setName(heatFile.getFileName());
+ vduArtifact.setContent(heatFile.getFileBody().getBytes());
+ vduArtifact.setType(artifactType);
+ return vduArtifact;
+ }
+
+ private void mapEnvironment(HeatEnvironment heatEnvironment, VduModelInfo vduModel) {
+ // TODO: These catalog objects will be refactored to be
+ // non-Heat-specific
+ if (heatEnvironment != null) {
+ List<VduArtifact> vduArtifacts = vduModel.getArtifacts();
+ vduArtifacts.add(mapEnvironmentFileToVduArtifact(heatEnvironment));
+ }
+ }
+
+ private VduArtifact mapEnvironmentFileToVduArtifact(HeatEnvironment heatEnv) {
+ VduArtifact vduArtifact = new VduArtifact();
+ vduArtifact.setName(heatEnv.getName());
+ vduArtifact.setContent(heatEnv.getEnvironment().getBytes());
+ vduArtifact.setType(ArtifactType.ENVIRONMENT);
+ return vduArtifact;
+ }
+
+}
\ No newline at end of file diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java index 1db4c9f77a..32720e53db 100644 --- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java +++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImpl.java @@ -75,22 +75,23 @@ 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; + CloudConfigFactory cloudConfigFactory = new CloudConfigFactory(); + protected CloudConfig cloudConfig = null; - MsoPropertiesFactory msoPropertiesFactory=new MsoPropertiesFactory(); + MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - private static final String MSO_PROP_VNF_ADAPTER = "MSO_PROP_VNF_ADAPTER"; + 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 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() { @@ -99,267 +100,268 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { /** * 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; + this.msoPropertiesFactory = msoPropFactory; + this.cloudConfigFactory = cloudConfigFact; } /** * 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"); + 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. - * + * <p> * 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. - * + * <p> * 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. - * + * <p> * 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. - * + * <p> * 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 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 + * 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 <String, String> inputs, - Boolean failIfExists, - Boolean backout, - MsoRequest msoRequest, - Holder <String> vnfId, - Holder <Map <String, String>> outputs, - Holder <VnfRollback> rollback) throws VnfException { - // Create a hook here to catch shortcut createVf requests: - if (requestType != null) { - if (requestType.startsWith("VFMOD")) { - LOGGER.debug("Calling createVfModule from createVnf -- requestType=" + requestType); - String newRequestType = requestType.substring(5); - String vfVolGroupHeatStackId = ""; - String vfBaseHeatStackId = ""; - try { - if (volumeGroupHeatStackId != null) { - vfVolGroupHeatStackId = volumeGroupHeatStackId.substring(0, volumeGroupHeatStackId.lastIndexOf("|")); - vfBaseHeatStackId = volumeGroupHeatStackId.substring(volumeGroupHeatStackId.lastIndexOf("|")+1); - } - } catch (Exception e) { - // might be ok - both are just blank - LOGGER.debug("ERROR trying to parse the volumeGroupHeatStackId " + volumeGroupHeatStackId,e); - } - this.createVfModule(cloudSiteId, - tenantId, - vnfType, - vnfVersion, - vnfName, - newRequestType, - vfVolGroupHeatStackId, - vfBaseHeatStackId, + public void createVnf(String cloudSiteId, + String tenantId, + String vnfType, + String vnfVersion, + String vnfName, + String requestType, + String volumeGroupHeatStackId, + Map<String, String> inputs, + Boolean failIfExists, + Boolean backout, + MsoRequest msoRequest, + Holder<String> vnfId, + Holder<Map<String, String>> outputs, + Holder<VnfRollback> rollback) throws VnfException { + // Create a hook here to catch shortcut createVf requests: + if (requestType != null) { + if (requestType.startsWith("VFMOD")) { + LOGGER.debug("Calling createVfModule from createVnf -- requestType=" + requestType); + String newRequestType = requestType.substring(5); + String vfVolGroupHeatStackId = ""; + String vfBaseHeatStackId = ""; + try { + if (volumeGroupHeatStackId != null) { + vfVolGroupHeatStackId = volumeGroupHeatStackId.substring(0, volumeGroupHeatStackId.lastIndexOf("|")); + vfBaseHeatStackId = volumeGroupHeatStackId.substring(volumeGroupHeatStackId.lastIndexOf("|") + 1); + } + } catch (Exception e) { + // might be ok - both are just blank + LOGGER.debug("ERROR trying to parse the volumeGroupHeatStackId " + volumeGroupHeatStackId, e); + } + this.createVfModule(cloudSiteId, + tenantId, + vnfType, + vnfVersion, + vnfName, + newRequestType, + vfVolGroupHeatStackId, + vfBaseHeatStackId, null, - inputs, - failIfExists, - backout, - msoRequest, - vnfId, - outputs, - rollback); - return; - } - } - // createVf will know if the requestType starts with "X" that it's the "old" way - StringBuilder newRequestTypeSb = new StringBuilder("X"); - String vfVolGroupHeatStackId = ""; - String vfBaseHeatStackId = ""; - if (requestType != null) { - newRequestTypeSb.append(requestType); - } - this.createVfModule(cloudSiteId, - tenantId, - vnfType, - vnfVersion, - vnfName, - newRequestTypeSb.toString(), - vfVolGroupHeatStackId, - vfBaseHeatStackId, - null, - inputs, - failIfExists, - backout, - msoRequest, - vnfId, - outputs, - rollback); - // End createVf shortcut + inputs, + failIfExists, + backout, + msoRequest, + vnfId, + outputs, + rollback); + return; + } + } + // createVf will know if the requestType starts with "X" that it's the "old" way + StringBuilder newRequestTypeSb = new StringBuilder("X"); + String vfVolGroupHeatStackId = ""; + String vfBaseHeatStackId = ""; + if (requestType != null) { + newRequestTypeSb.append(requestType); } + this.createVfModule(cloudSiteId, + tenantId, + vnfType, + vnfVersion, + vnfName, + newRequestTypeSb.toString(), + vfVolGroupHeatStackId, + vfBaseHeatStackId, + null, + inputs, + failIfExists, + backout, + msoRequest, + vnfId, + outputs, + rollback); + // End createVf shortcut + } @Override - public void updateVnf (String cloudSiteId, - String tenantId, - String vnfType, - String vnfVersion, - String vnfName, - String requestType, - String volumeGroupHeatStackId, - Map <String, String> inputs, - MsoRequest msoRequest, - Holder <Map <String, String>> outputs, - Holder <VnfRollback> rollback) throws VnfException { - // As of 1707 - this method should no longer be called - MsoLogger.setLogContext (msoRequest.getRequestId (), msoRequest.getServiceInstanceId ()); - MsoLogger.setServiceName ("UpdateVnf"); - LOGGER.debug("UpdateVnf called?? This should not be called any longer - update vfModule"); + public void updateVnf(String cloudSiteId, + String tenantId, + String vnfType, + String vnfVersion, + String vnfName, + String requestType, + String volumeGroupHeatStackId, + Map<String, String> inputs, + MsoRequest msoRequest, + Holder<Map<String, String>> outputs, + Holder<VnfRollback> rollback) throws VnfException { + // As of 1707 - this method should no longer be called + MsoLogger.setLogContext(msoRequest.getRequestId(), msoRequest.getServiceInstanceId()); + MsoLogger.setServiceName("UpdateVnf"); + LOGGER.debug("UpdateVnf called?? This should not be called any longer - update vfModule"); } /** * This is the "Query VNF" web service implementation. * It will look up a VNF by name or ID in the specified cloud and tenant. - * + * <p> * The method returns an indicator that the VNF exists, its Openstack internal * ID, its status, and the set of outputs (from when the stack was created). * * @param cloudSiteId CLLI code of the cloud site in which to query - * @param tenantId Openstack tenant identifier - * @param vnfName VNF Name or Openstack ID - * @param msoRequest Request tracking information for logs - * @param vnfExists Flag reporting the result of the query - * @param vnfId Holder for output VNF Openstack ID - * @param outputs Holder for Map of VNF outputs from heat (assigned IPs, etc) + * @param tenantId Openstack tenant identifier + * @param vnfName VNF Name or Openstack ID + * @param msoRequest Request tracking information for logs + * @param vnfExists Flag reporting the result of the query + * @param vnfId Holder for output VNF Openstack ID + * @param outputs Holder for Map of VNF outputs from heat (assigned IPs, etc) */ @Override - public void queryVnf (String cloudSiteId, - String tenantId, - String vnfName, - MsoRequest msoRequest, - Holder <Boolean> vnfExists, - Holder <String> vnfId, - Holder <VnfStatus> status, - Holder <Map <String, String>> outputs) throws VnfException { - MsoLogger.setLogContext (msoRequest); - MsoLogger.setServiceName ("QueryVnf"); - LOGGER.debug ("Querying VNF " + vnfName + " in " + cloudSiteId + "/" + tenantId); + public void queryVnf(String cloudSiteId, + String tenantId, + String vnfName, + MsoRequest msoRequest, + Holder<Boolean> vnfExists, + Holder<String> vnfId, + Holder<VnfStatus> status, + Holder<Map<String, String>> outputs) throws VnfException { + MsoLogger.setLogContext(msoRequest); + MsoLogger.setServiceName("QueryVnf"); + LOGGER.debug("Querying VNF " + vnfName + " in " + cloudSiteId + "/" + tenantId); // Will capture execution time for metrics - long startTime = System.currentTimeMillis (); + long startTime = System.currentTimeMillis(); - MsoHeatUtils heat = new MsoHeatUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory); + MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory); StackInfo heatStack = null; - long subStartTime = System.currentTimeMillis (); + long subStartTime = System.currentTimeMillis(); try { - heatStack = heat.queryStack (cloudSiteId, tenantId, vnfName); - LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryStack", vnfName); + heatStack = heat.queryStack(cloudSiteId, tenantId, vnfName); + LOGGER.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryStack", vnfName); } catch (MsoException me) { - me.addContext ("QueryVNF"); + me.addContext("QueryVNF"); // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException String error = "Query VNF: " + vnfName + " in " + cloudSiteId + "/" + tenantId + ": " + me; - LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", vnfName); - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "QueryVNF", MsoLogger.ErrorCode.DataError, "Exception - queryStack", me); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); + LOGGER.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", vnfName); + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "QueryVNF", MsoLogger.ErrorCode.DataError, "Exception - queryStack", me); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); } // Populate the outputs based on the returned Stack information // - if (heatStack == null || heatStack.getStatus () == HeatStatus.NOTFOUND) { + if (heatStack == null || heatStack.getStatus() == HeatStatus.NOTFOUND) { // Not Found vnfExists.value = Boolean.FALSE; status.value = VnfStatus.NOTFOUND; vnfId.value = null; outputs.value = new HashMap<>(); // Return as an empty map - LOGGER.debug ("VNF " + vnfName + " not found"); + LOGGER.debug("VNF " + vnfName + " not found"); } else { vnfExists.value = Boolean.TRUE; - status.value = stackStatusToVnfStatus (heatStack.getStatus ()); - vnfId.value = heatStack.getCanonicalName (); - outputs.value = copyStringOutputs (heatStack.getOutputs ()); + status.value = stackStatusToVnfStatus(heatStack.getStatus()); + vnfId.value = heatStack.getCanonicalName(); + outputs.value = copyStringOutputs(heatStack.getOutputs()); - LOGGER.debug ("VNF " + vnfName + " found, ID = " + vnfId.value); + LOGGER.debug("VNF " + vnfName + " found, ID = " + vnfId.value); } - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully query VNF"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully query VNF"); } /** * This is the "Delete VNF" web service implementation. * It will delete a VNF by name or ID in the specified cloud and tenant. - * + * <p> * The method has no outputs. * * @param cloudSiteId CLLI code of the cloud site in which to delete - * @param tenantId Openstack tenant identifier - * @param vnfName VNF Name or Openstack ID - * @param msoRequest Request tracking information for logs + * @param tenantId Openstack tenant identifier + * @param vnfName VNF Name or Openstack ID + * @param msoRequest Request tracking information for logs */ @Override - public void deleteVnf (String cloudSiteId, - String tenantId, - String vnfName, - MsoRequest msoRequest) throws VnfException { - MsoLogger.setLogContext (msoRequest); - MsoLogger.setServiceName ("DeleteVnf"); - LOGGER.debug ("Deleting VNF " + vnfName + " in " + cloudSiteId + "/" + tenantId); + public void deleteVnf(String cloudSiteId, + String tenantId, + String vnfName, + MsoRequest msoRequest) throws VnfException { + MsoLogger.setLogContext(msoRequest); + MsoLogger.setServiceName("DeleteVnf"); + LOGGER.debug("Deleting VNF " + vnfName + " in " + cloudSiteId + "/" + tenantId); // Will capture execution time for metrics - long startTime = System.currentTimeMillis (); + long startTime = System.currentTimeMillis(); - MsoHeatUtils heat = new MsoHeatUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory); + MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory); // Use the MsoHeatUtils to delete the stack. Set the polling flag to true. // The possible outcomes of deleteStack are a StackInfo object with status // of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException // could be thrown. - long subStartTime = System.currentTimeMillis (); + long subStartTime = System.currentTimeMillis(); try { - heat.deleteStack (tenantId, cloudSiteId, vnfName, true); - LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "DeleteStack", vnfName); + heat.deleteStack(tenantId, cloudSiteId, vnfName, true); + LOGGER.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "DeleteStack", vnfName); } catch (MsoException me) { - me.addContext ("DeleteVNF"); + me.addContext("DeleteVNF"); // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException String error = "Delete VNF: " + vnfName + " in " + cloudSiteId + "/" + tenantId + ": " + me; - LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "DeleteStack", vnfName); - LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "DeleteVNF", MsoLogger.ErrorCode.DataError, "Exception - DeleteVNF", me); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); + LOGGER.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "DeleteStack", vnfName); + LOGGER.error(MessageEnum.RA_DELETE_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "DeleteVNF", MsoLogger.ErrorCode.DataError, "Exception - DeleteVNF", me); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); } // On success, nothing is returned. - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully delete VNF"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully delete VNF"); } /** @@ -369,49 +371,49 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { * operation to undo the creation. */ @Override - public void rollbackVnf (VnfRollback rollback) throws VnfException { - long startTime = System.currentTimeMillis (); - MsoLogger.setServiceName ("RollbackVnf"); - // rollback may be null (e.g. if stack already existed when Create was called) + public void rollbackVnf(VnfRollback rollback) throws VnfException { + long startTime = System.currentTimeMillis(); + MsoLogger.setServiceName("RollbackVnf"); + // rollback may be null (e.g. if stack already existed when Create was called) if (rollback == null) { - LOGGER.info (MessageEnum.RA_ROLLBACK_NULL, "OpenStack", "rollbackVnf"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Rollback request content is null"); + LOGGER.info(MessageEnum.RA_ROLLBACK_NULL, "OpenStack", "rollbackVnf"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Rollback request content is null"); return; } // Get the elements of the VnfRollback object for easier access - String cloudSiteId = rollback.getCloudSiteId (); - String tenantId = rollback.getTenantId (); - String vnfId = rollback.getVnfId (); + String cloudSiteId = rollback.getCloudSiteId(); + String tenantId = rollback.getTenantId(); + String vnfId = rollback.getVnfId(); - MsoLogger.setLogContext (rollback.getMsoRequest()); + MsoLogger.setLogContext(rollback.getMsoRequest()); - LOGGER.debug ("Rolling Back VNF " + vnfId + " in " + cloudSiteId + "/" + tenantId); + LOGGER.debug("Rolling Back VNF " + vnfId + " in " + cloudSiteId + "/" + tenantId); - MsoHeatUtils heat = new MsoHeatUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory); + MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory); // Use the MsoHeatUtils to delete the stack. Set the polling flag to true. // The possible outcomes of deleteStack are a StackInfo object with status // of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException // could be thrown. - long subStartTime = System.currentTimeMillis (); + long subStartTime = System.currentTimeMillis(); try { - heat.deleteStack (tenantId, cloudSiteId, vnfId, true); - LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "DeleteStack", null); + heat.deleteStack(tenantId, cloudSiteId, vnfId, true); + LOGGER.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "DeleteStack", null); } catch (MsoException me) { // Failed to rollback the Stack due to an openstack exception. // Convert to a generic VnfException - me.addContext ("RollbackVNF"); + me.addContext("RollbackVNF"); String error = "Rollback VNF: " + vnfId + " in " + cloudSiteId + "/" + tenantId + ": " + me; - LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "DeleteStack", null); - LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vnfId, cloudSiteId, tenantId, "OpenStack", "DeleteStack", MsoLogger.ErrorCode.DataError, "Exception - DeleteStack", me); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); + LOGGER.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "DeleteStack", null); + LOGGER.error(MessageEnum.RA_DELETE_VNF_ERR, vnfId, cloudSiteId, tenantId, "OpenStack", "DeleteStack", MsoLogger.ErrorCode.DataError, "Exception - DeleteStack", me); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); } - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully roll back VNF"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully roll back VNF"); } - private VnfStatus stackStatusToVnfStatus (HeatStatus stackStatus) { + private VnfStatus stackStatusToVnfStatus(HeatStatus stackStatus) { switch (stackStatus) { case CREATED: return VnfStatus.ACTIVE; @@ -424,50 +426,50 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } } - private Map <String, String> copyStringOutputs (Map <String, Object> stackOutputs) { - Map <String, String> stringOutputs = new HashMap <> (); - for (Map.Entry<String,Object> entry : stackOutputs.entrySet ()) { + private Map<String, String> copyStringOutputs(Map<String, Object> stackOutputs) { + Map<String, String> stringOutputs = new HashMap<>(); + for (Map.Entry<String, Object> entry : stackOutputs.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value instanceof String) { - stringOutputs.put (key, (String) value); - } else if (value instanceof Integer) { - try { - String str = "" + value; - stringOutputs.put(key, str); - } catch (Exception e) { - LOGGER.debug("Unable to add " + key + " to outputs",e); - } + stringOutputs.put(key, (String) value); + } else if (value instanceof Integer) { + try { + String str = "" + value; + stringOutputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("Unable to add " + key + " to outputs", e); + } } else if (value instanceof JsonNode) { - try { - //String str = this.convertNode((JsonNode) value); - String str = value.toString(); - stringOutputs.put(key, str); - } catch (Exception e) { - LOGGER.debug("Unable to add " + key + " to outputs - exception converting JsonNode",e); - } + try { + //String str = this.convertNode((JsonNode) value); + String str = value.toString(); + stringOutputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("Unable to add " + key + " to outputs - exception converting JsonNode", e); + } } else if (value instanceof java.util.LinkedHashMap) { - try { - //String str = JSON_MAPPER.writeValueAsString(value); - String str = value.toString(); - stringOutputs.put(key, str); - } catch (Exception e) { - LOGGER.debug("Unable to add " + key + " to outputs - exception converting LinkedHashMap",e); - } + try { + //String str = JSON_MAPPER.writeValueAsString(value); + String str = value.toString(); + stringOutputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("Unable to add " + key + " to outputs - exception converting LinkedHashMap", e); + } } else { - try { - String str = value.toString(); - stringOutputs.put(key, str); - } catch (Exception e) { - LOGGER.debug("Unable to add " + key + " to outputs - unable to call .toString() " + e.getMessage(),e); - } + try { + String str = value.toString(); + stringOutputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("Unable to add " + key + " to outputs - unable to call .toString() " + e.getMessage(), e); + } } } return stringOutputs; } - private Map <String, Object> copyStringInputs (Map <String, String> stringInputs) { - return new HashMap <> (stringInputs); + private Map<String, Object> copyStringInputs(Map<String, String> stringInputs) { + return new HashMap<>(stringInputs); } private boolean callHeatbridge(String heatStackId) { @@ -484,7 +486,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { boolean wait = p.waitFor(waitTimeMs, TimeUnit.MILLISECONDS); LOGGER.debug(" HeatBridgeMain.py returned " + wait + " with code " + p.exitValue()); - return wait && p.exitValue()==0; + return wait && p.exitValue() == 0; } catch (IOException e) { LOGGER.debug(" HeatBridgeMain.py failed with IO Exception! " + e); return false; @@ -502,34 +504,32 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { StringBuilder sb = new StringBuilder(optionalName == null ? "\ninputs" : "\n" + optionalName); if (inputs == null) { sb.append("\tNULL"); - } - else if (inputs.size() < 1) { + } else if (inputs.size() < 1) { sb.append("\tEMPTY"); } else { - for (Map.Entry<String,Object> entry : inputs.entrySet()) { + for (Map.Entry<String, Object> entry : inputs.entrySet()) { String outputString; String str = entry.getKey(); Object value = entry.getValue(); try { outputString = value.toString(); } catch (Exception e) { - LOGGER.debug("Exception :",e); + LOGGER.debug("Exception :", e); outputString = "Unable to call toString() on the value for " + str; } sb.append("\t\nitem ").append(i++).append(": '").append(str).append("'='").append(outputString) - .append("'"); + .append("'"); } } LOGGER.debug(sb.toString()); } - + private void sendMapToDebug(Map<String, String> inputs) { int i = 0; StringBuilder sb = new StringBuilder("inputs:"); if (inputs == null) { sb.append("\tNULL"); - } - else if (inputs.size() < 1) { + } else if (inputs.size() < 1) { sb.append("\tEMPTY"); } else { for (String str : inputs.keySet()) { @@ -545,7 +545,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { final String json = JSON_MAPPER.writeValueAsString(obj); return json; } catch (Exception e) { - LOGGER.debug("Error converting json to string " + e.getMessage(),e); + LOGGER.debug("Error converting json to string " + e.getMessage(), e); } return "[Error converting json to string]"; } @@ -560,14 +560,14 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { Object obj = objectMap.get(key); if (obj instanceof String) { stringMap.put(key, (String) objectMap.get(key)); - } else if (obj instanceof JsonNode ){ + } else if (obj instanceof JsonNode) { // This is a bit of mess - but I think it's the least impacting // let's convert it BACK to a string - then it will get converted back later try { String str = this.convertNode((JsonNode) obj); stringMap.put(key, str); } catch (Exception e) { - LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for JsonNode "+ key,e); + LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for JsonNode " + key, e); //okay in this instance - only string values (fqdn) are expected to be needed } } else if (obj instanceof java.util.LinkedHashMap) { @@ -576,21 +576,21 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { String str = JSON_MAPPER.writeValueAsString(obj); stringMap.put(key, str); } catch (Exception e) { - LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for LinkedHashMap "+ key,e); - } - } else if (obj instanceof Integer) { - try { - String str = "" + obj; - stringMap.put(key, str); - } catch (Exception e) { - LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for Integer "+ key,e); + LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for LinkedHashMap " + key, e); + } + } else if (obj instanceof Integer) { + try { + String str = "" + obj; + stringMap.put(key, str); + } catch (Exception e) { + LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for Integer " + key, e); } } else { try { - String str = obj.toString(); + String str = obj.toString(); stringMap.put(key, str); } catch (Exception e) { - LOGGER.debug("DANGER WILL ROBINSON: unable to convert value "+ key + " (" + e.getMessage() + ")",e); + LOGGER.debug("DANGER WILL ROBINSON: unable to convert value " + key + " (" + e.getMessage() + ")", e); } } } @@ -601,24 +601,24 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { @Override public void createVfModule(String cloudSiteId, - String tenantId, - String vnfType, - String vnfVersion, - String vnfName, - String requestType, - String volumeGroupHeatStackId, - String baseVfHeatStackId, - String modelCustomizationUuid, - Map <String, String> inputs, - Boolean failIfExists, - Boolean backout, - MsoRequest msoRequest, - Holder <String> vnfId, - Holder <Map <String, String>> outputs, - Holder <VnfRollback> rollback) throws VnfException { - String vfModuleName = vnfName; - String vfModuleType = vnfType; - String vfVersion = vnfVersion; + String tenantId, + String vnfType, + String vnfVersion, + String vnfName, + String requestType, + String volumeGroupHeatStackId, + String baseVfHeatStackId, + String modelCustomizationUuid, + Map<String, String> inputs, + Boolean failIfExists, + Boolean backout, + MsoRequest msoRequest, + Holder<String> vnfId, + Holder<Map<String, String>> outputs, + Holder<VnfRollback> rollback) throws VnfException { + String vfModuleName = vnfName; + String vfModuleType = vnfType; + String vfVersion = vnfVersion; String mcu = modelCustomizationUuid; boolean useMCUuid = false; if (mcu != null && !mcu.isEmpty()) { @@ -631,50 +631,60 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { useMCUuid = true; } } - MsoLogger.setLogContext (msoRequest); - MsoLogger.setServiceName ("CreateVfModule"); - String requestTypeString = ""; + MsoLogger.setLogContext(msoRequest); + MsoLogger.setServiceName("CreateVfModule"); + String requestTypeString = ""; if (requestType != null && !"".equals(requestType)) { - requestTypeString = requestType; + requestTypeString = requestType; } String nestedStackId = null; if (volumeGroupHeatStackId != null && !"".equals(volumeGroupHeatStackId)) { - if (!"null".equalsIgnoreCase(volumeGroupHeatStackId)) { - nestedStackId = volumeGroupHeatStackId; - } + if (!"null".equalsIgnoreCase(volumeGroupHeatStackId)) { + nestedStackId = volumeGroupHeatStackId; + } } String nestedBaseStackId = null; if (baseVfHeatStackId != null && !"".equals(baseVfHeatStackId)) { - if (!"null".equalsIgnoreCase(baseVfHeatStackId)) { - nestedBaseStackId = baseVfHeatStackId; - } + if (!"null".equalsIgnoreCase(baseVfHeatStackId)) { + nestedBaseStackId = baseVfHeatStackId; + } } if (inputs == null) { - // Create an empty set of inputs - inputs = new HashMap<>(); - LOGGER.debug("inputs == null - setting to empty"); + // Create an empty set of inputs + inputs = new HashMap<>(); + LOGGER.debug("inputs == null - setting to empty"); } else { - this.sendMapToDebug(inputs); + this.sendMapToDebug(inputs); } //This method will also handle doing things the "old" way - i.e., just orchestrate a VNF boolean oldWay = false; if (requestTypeString.startsWith("X")) { - oldWay = true; - LOGGER.debug("orchestrating a VNF - *NOT* a module!"); - requestTypeString = requestTypeString.substring(1); + oldWay = true; + LOGGER.debug("orchestrating a VNF - *NOT* a module!"); + requestTypeString = requestTypeString.substring(1); } // 1607 - let's parse out the request type we're being sent boolean isBaseRequest = false; boolean isVolumeRequest = false; if (requestTypeString.startsWith("VOLUME")) { - isVolumeRequest = true; + isVolumeRequest = true; } LOGGER.debug("requestTypeString = " + requestTypeString + ", nestedStackId = " + nestedStackId + ", nestedBaseStackId = " + nestedBaseStackId); + + // TODO(sshank): Figure out the body format to be sent from Groovy. + String hpaEnviromnentString = ""; + // Something similar to the following: + /* + if requestTypeString.substring(?) != "" { + hpaEnviromnentString = requestTypeString.substring(?) + } + */ + // Will capture execution time for metrics - long startTime = System.currentTimeMillis (); + long startTime = System.currentTimeMillis(); // Build a default rollback object (no actions performed) VnfRollback vfRollback = new VnfRollback(); @@ -691,169 +701,169 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { callHeatbridge(baseVfHeatStackId); // First, look up to see if the VF already exists. - MsoHeatUtils heat = new MsoHeatUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory); + MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory); StackInfo heatStack = null; - long subStartTime1 = System.currentTimeMillis (); + long subStartTime1 = System.currentTimeMillis(); try { - heatStack = heat.queryStack (cloudSiteId, tenantId, vfModuleName); - LOGGER.recordMetricEvent (subStartTime1, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryStack", vfModuleName); + heatStack = heat.queryStack(cloudSiteId, tenantId, vfModuleName); + LOGGER.recordMetricEvent(subStartTime1, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryStack", vfModuleName); } catch (MsoException me) { - String error = "Create VF Module: Query " + vfModuleName + " in " + cloudSiteId + "/" + tenantId + ": " + me ; - LOGGER.recordMetricEvent (subStartTime1, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", vfModuleName); - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Exception - queryStack", me); + String error = "Create VF Module: Query " + vfModuleName + " in " + cloudSiteId + "/" + tenantId + ": " + me; + LOGGER.recordMetricEvent(subStartTime1, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", vfModuleName); + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Exception - queryStack", me); // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException - me.addContext ("CreateVFModule"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); + me.addContext("CreateVFModule"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); } // New with 1607 - more precise handling/messaging if the stack already exists - if (heatStack != null && !(heatStack.getStatus () == HeatStatus.NOTFOUND)) { - // INIT, CREATED, NOTFOUND, FAILED, BUILDING, DELETING, UNKNOWN, UPDATING, UPDATED - HeatStatus status = heatStack.getStatus(); - if (status == HeatStatus.INIT || status == HeatStatus.BUILDING || status == HeatStatus.DELETING || status == HeatStatus.UPDATING) { - // fail - it's in progress - return meaningful error + if (heatStack != null && !(heatStack.getStatus() == HeatStatus.NOTFOUND)) { + // INIT, CREATED, NOTFOUND, FAILED, BUILDING, DELETING, UNKNOWN, UPDATING, UPDATED + HeatStatus status = heatStack.getStatus(); + if (status == HeatStatus.INIT || status == HeatStatus.BUILDING || status == HeatStatus.DELETING || status == HeatStatus.UPDATING) { + // fail - it's in progress - return meaningful error String error = "Create VF: Stack " + vfModuleName + " already exists and has status " + status.toString() + " in " + cloudSiteId + "/" + tenantId + "; please wait for it to complete, or fix manually."; - LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); - throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName ()); - } - if (status == HeatStatus.FAILED) { - // fail - it exists and is in a FAILED state + LOGGER.error(MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + throw new VnfAlreadyExists(vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName()); + } + if (status == HeatStatus.FAILED) { + // fail - it exists and is in a FAILED state String error = "Create VF: Stack " + vfModuleName + " already exists and is in FAILED state in " + cloudSiteId + "/" + tenantId + "; requires manual intervention."; - LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists and is in FAILED state"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); - throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName ()); - } - if (status == HeatStatus.UNKNOWN || status == HeatStatus.UPDATED) { - // fail - it exists and is in a FAILED state + LOGGER.error(MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists and is in FAILED state"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + throw new VnfAlreadyExists(vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName()); + } + if (status == HeatStatus.UNKNOWN || status == HeatStatus.UPDATED) { + // fail - it exists and is in a FAILED state String error = "Create VF: Stack " + vfModuleName + " already exists and has status " + status.toString() + " in " + cloudSiteId + "/" + tenantId + "; requires manual intervention."; - LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists and is in UPDATED or UNKNOWN state"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); - throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName ()); - } - if (status == HeatStatus.CREATED) { - // fail - it exists - if (failIfExists != null && failIfExists) { - String error = "Create VF: Stack " + vfModuleName + " already exists in " + cloudSiteId + "/" + tenantId; - LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); - throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName ()); - } else { - LOGGER.debug ("Found Existing stack, status=" + heatStack.getStatus ()); - // Populate the outputs from the existing stack. - vnfId.value = heatStack.getCanonicalName (); - outputs.value = copyStringOutputs (heatStack.getOutputs ()); - rollback.value = vfRollback; // Default rollback - no updates performed - } - } - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create VF Module"); + LOGGER.error(MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists and is in UPDATED or UNKNOWN state"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + throw new VnfAlreadyExists(vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName()); + } + if (status == HeatStatus.CREATED) { + // fail - it exists + if (failIfExists != null && failIfExists) { + String error = "Create VF: Stack " + vfModuleName + " already exists in " + cloudSiteId + "/" + tenantId; + LOGGER.error(MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.DataError, "Stack " + vfModuleName + " already exists"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + throw new VnfAlreadyExists(vfModuleName, cloudSiteId, tenantId, heatStack.getCanonicalName()); + } else { + LOGGER.debug("Found Existing stack, status=" + heatStack.getStatus()); + // Populate the outputs from the existing stack. + vnfId.value = heatStack.getCanonicalName(); + outputs.value = copyStringOutputs(heatStack.getOutputs()); + rollback.value = vfRollback; // Default rollback - no updates performed + } + } + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create VF Module"); return; } // handle a nestedStackId if sent- this one would be for the volume - so applies to both Vf and Vnf StackInfo nestedHeatStack = null; - long subStartTime2 = System.currentTimeMillis (); + long subStartTime2 = System.currentTimeMillis(); Map<String, Object> nestedVolumeOutputs = null; if (nestedStackId != null) { - try { - LOGGER.debug("Querying for nestedStackId = " + nestedStackId); - nestedHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedStackId); - LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryStack", vfModuleName); - } catch (MsoException me) { - // Failed to query the Stack due to an openstack exception. - // Convert to a generic VnfException - me.addContext ("CreateVFModule"); - String error = "Create VFModule: Attached heatStack ID Query " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ; - LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", vfModuleName); - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.BusinessProcesssError, "MsoException trying to query nested stack", me); - LOGGER.debug("ERROR trying to query nested stack= " + error); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); - } - if (nestedHeatStack == null || nestedHeatStack.getStatus() == HeatStatus.NOTFOUND) { - String error = "Create VFModule: Attached heatStack ID DOES NOT EXIST " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ; - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "queryStack", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Attached heatStack ID DOES NOT EXIST"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); - LOGGER.debug(error); - throw new VnfException (error, MsoExceptionCategory.USERDATA); - } else { - LOGGER.debug("Found nested volume heat stack - copying values to inputs *later*"); - //this.sendMapToDebug(inputs); - nestedVolumeOutputs = nestedHeatStack.getOutputs(); - this.sendMapToDebug(nestedVolumeOutputs, "volumeStackOutputs"); - //TODO - //heat.copyStringOutputsToInputs(inputs, nestedHeatStack.getOutputs(), false); - //this.sendMapToDebug(inputs); - } + try { + LOGGER.debug("Querying for nestedStackId = " + nestedStackId); + nestedHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedStackId); + LOGGER.recordMetricEvent(subStartTime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryStack", vfModuleName); + } catch (MsoException me) { + // Failed to query the Stack due to an openstack exception. + // Convert to a generic VnfException + me.addContext("CreateVFModule"); + String error = "Create VFModule: Attached heatStack ID Query " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me; + LOGGER.recordMetricEvent(subStartTime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", vfModuleName); + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "queryStack", MsoLogger.ErrorCode.BusinessProcesssError, "MsoException trying to query nested stack", me); + LOGGER.debug("ERROR trying to query nested stack= " + error); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); + } + if (nestedHeatStack == null || nestedHeatStack.getStatus() == HeatStatus.NOTFOUND) { + String error = "Create VFModule: Attached heatStack ID DOES NOT EXIST " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR"; + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "queryStack", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Attached heatStack ID DOES NOT EXIST"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + LOGGER.debug(error); + throw new VnfException(error, MsoExceptionCategory.USERDATA); + } else { + LOGGER.debug("Found nested volume heat stack - copying values to inputs *later*"); + //this.sendMapToDebug(inputs); + nestedVolumeOutputs = nestedHeatStack.getOutputs(); + this.sendMapToDebug(nestedVolumeOutputs, "volumeStackOutputs"); + //TODO + //heat.copyStringOutputsToInputs(inputs, nestedHeatStack.getOutputs(), false); + //this.sendMapToDebug(inputs); + } } // handle a nestedBaseStackId if sent- this is the stack ID of the base. Should be null for VNF requests StackInfo nestedBaseHeatStack = null; - long subStartTime3 = System.currentTimeMillis (); + long subStartTime3 = System.currentTimeMillis(); Map<String, Object> baseStackOutputs = null; if (nestedBaseStackId != null) { - try { - LOGGER.debug("Querying for nestedBaseStackId = " + nestedBaseStackId); - nestedBaseHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedBaseStackId); - LOGGER.recordMetricEvent (subStartTime3, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryStack", vfModuleName); - } catch (MsoException me) { - // Failed to query the Stack due to an openstack exception. - // Convert to a generic VnfException - me.addContext ("CreateVFModule"); - String error = "Create VFModule: Attached baseHeatStack ID Query " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ; - LOGGER.recordMetricEvent (subStartTime3, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", vfModuleName); - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.BusinessProcesssError, "MsoException trying to query nested base stack", me); - LOGGER.debug("ERROR trying to query nested base stack= " + error); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); - } - if (nestedBaseHeatStack == null || nestedBaseHeatStack.getStatus() == HeatStatus.NOTFOUND) { - String error = "Create VFModule: Attached base heatStack ID DOES NOT EXIST " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ; - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Attached base heatStack ID DOES NOT EXIST"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); - LOGGER.debug(error); - throw new VnfException (error, MsoExceptionCategory.USERDATA); - } else { - LOGGER.debug("Found nested base heat stack - these values will be copied to inputs *later*"); - //this.sendMapToDebug(inputs); - baseStackOutputs = nestedBaseHeatStack.getOutputs(); - this.sendMapToDebug(baseStackOutputs, "baseStackOutputs"); - //TODO - //heat.copyStringOutputsToInputs(inputs, nestedBaseHeatStack.getOutputs(), false); - //this.sendMapToDebug(inputs); - } + try { + LOGGER.debug("Querying for nestedBaseStackId = " + nestedBaseStackId); + nestedBaseHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedBaseStackId); + LOGGER.recordMetricEvent(subStartTime3, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryStack", vfModuleName); + } catch (MsoException me) { + // Failed to query the Stack due to an openstack exception. + // Convert to a generic VnfException + me.addContext("CreateVFModule"); + String error = "Create VFModule: Attached baseHeatStack ID Query " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me; + LOGGER.recordMetricEvent(subStartTime3, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", vfModuleName); + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.BusinessProcesssError, "MsoException trying to query nested base stack", me); + LOGGER.debug("ERROR trying to query nested base stack= " + error); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); + } + if (nestedBaseHeatStack == null || nestedBaseHeatStack.getStatus() == HeatStatus.NOTFOUND) { + String error = "Create VFModule: Attached base heatStack ID DOES NOT EXIST " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR"; + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Attached base heatStack ID DOES NOT EXIST"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + LOGGER.debug(error); + throw new VnfException(error, MsoExceptionCategory.USERDATA); + } else { + LOGGER.debug("Found nested base heat stack - these values will be copied to inputs *later*"); + //this.sendMapToDebug(inputs); + baseStackOutputs = nestedBaseHeatStack.getOutputs(); + this.sendMapToDebug(baseStackOutputs, "baseStackOutputs"); + //TODO + //heat.copyStringOutputsToInputs(inputs, nestedBaseHeatStack.getOutputs(), false); + //this.sendMapToDebug(inputs); + } } // Ready to deploy the new VNF try (CatalogDatabase db = CatalogDatabase.getInstance()) { // Retrieve the VF - VfModule vf = null; - VnfResource vnfResource = null; - VfModuleCustomization vfmc = null; - LOGGER.debug("version: " + vfVersion); + VfModule vf = null; + VnfResource vnfResource = null; + VfModuleCustomization vfmc = null; + LOGGER.debug("version: " + vfVersion); if (useMCUuid) { - // 1707 - db refactoring - vfmc = db.getVfModuleCustomizationByModelCustomizationId(mcu); - vf = vfmc != null ? vfmc.getVfModule() : null; + // 1707 - db refactoring + vfmc = db.getVfModuleCustomizationByModelCustomizationId(mcu); + vf = vfmc != null ? vfmc.getVfModule() : null; // 1702 - this will be the new way going forward. We find the vf by mcu - otherwise, code is the same. - //vf = db.getVfModuleByModelCustomizationUuid(mcu); + //vf = db.getVfModuleByModelCustomizationUuid(mcu); if (vf == null) { LOGGER.debug("Unable to find vfModuleCust with modelCustomizationUuid=" + mcu); String error = - "Create vfModule error: Unable to find vfModuleCust with modelCustomizationUuid=" + mcu; + "Create vfModule error: Unable to find vfModuleCust with modelCustomizationUuid=" + mcu; LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, - "VF Module ModelCustomizationUuid", modelCustomizationUuid, "OpenStack", "", - MsoLogger.ErrorCode.DataError, - "Create VF Module: Unable to find vfModule with modelCustomizationUuid=" + mcu); + "VF Module ModelCustomizationUuid", modelCustomizationUuid, "OpenStack", "", + MsoLogger.ErrorCode.DataError, + "Create VF Module: Unable to find vfModule with modelCustomizationUuid=" + mcu); LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, - error); + error); throw new VnfException(error, MsoExceptionCategory.USERDATA); } else { - LOGGER.debug("Found vfModuleCust entry " + vfmc.toString()); + LOGGER.debug("Found vfModuleCust entry " + vfmc.toString()); } if (vf.isBase()) { isBaseRequest = true; @@ -862,27 +872,26 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { LOGGER.debug("This is *not* a BASE VF request!"); if (!isVolumeRequest && nestedBaseStackId == null) { LOGGER.debug( - "DANGER WILL ROBINSON! This is unexpected - no nestedBaseStackId with this non-base request"); + "DANGER WILL ROBINSON! This is unexpected - no nestedBaseStackId with this non-base request"); } } - } - else { // This is to support gamma only - get info from vnf_resource table - if (vfVersion != null && !vfVersion.isEmpty()) { - vnfResource = db.getVnfResource(vnfType, vnfVersion); - } else { - vnfResource = db.getVnfResource(vnfType); - } - if (vnfResource == null) { - String error = "Create VNF: Unknown VNF Type: " + vnfType; - LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "VNF Type", - vnfType, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Create VNF: Unknown VNF Type"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); - throw new VnfException(error, MsoExceptionCategory.USERDATA); - } - LOGGER.debug("Got VNF module definition from Catalog: " - + vnfResource.toString()); - } - // By here - we have either a vf or vnfResource + } else { // This is to support gamma only - get info from vnf_resource table + if (vfVersion != null && !vfVersion.isEmpty()) { + vnfResource = db.getVnfResource(vnfType, vnfVersion); + } else { + vnfResource = db.getVnfResource(vnfType); + } + if (vnfResource == null) { + String error = "Create VNF: Unknown VNF Type: " + vnfType; + LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "VNF Type", + vnfType, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Create VNF: Unknown VNF Type"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + throw new VnfException(error, MsoExceptionCategory.USERDATA); + } + LOGGER.debug("Got VNF module definition from Catalog: " + + vnfResource.toString()); + } + // By here - we have either a vf or vnfResource //1607 - Add version check // First - see if it's in the VnfResource record @@ -894,7 +903,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { vnfResource = db.getVnfResourceByModelUuid(vnfResourceModelUuid); if (vnfResource == null) { LOGGER.debug( - "Unable to find vnfResource at " + vnfResourceModelUuid + " will not error for now..."); + "Unable to find vnfResource at " + vnfResourceModelUuid + " will not error for now..."); } } } @@ -939,25 +948,25 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { equalToMax = aicV.isTheSameVersion(maxVersionVnf); } catch (Exception e) { LOGGER.debug("An exception occured while trying to test AIC Version " + e.getMessage() - + " - will default to not check", e); + + " - will default to not check", e); doNotTest = true; } if (!doNotTest) { if ((moreThanMin || equalToMin) // aic >= min - && (equalToMax || !(moreThanMax))) { //aic <= max + && (equalToMax || !(moreThanMax))) { //aic <= max LOGGER.debug("VNF Resource " + vnfResource.getModelName() + ", ModelUuid=" + vnfResource - .getModelUuid() + " VersionMin=" + minVersionVnf + " VersionMax:" + maxVersionVnf - + " supported on Cloud: " + cloudSiteOpt.get().getId() + " with AIC_Version:" - + cloudSiteOpt.get().getAic_version()); + .getModelUuid() + " VersionMin=" + minVersionVnf + " VersionMax:" + maxVersionVnf + + " supported on Cloud: " + cloudSiteOpt.get().getId() + " with AIC_Version:" + + cloudSiteOpt.get().getAic_version()); } else { // ERROR String error = - "VNF Resource type: " + vnfResource.getModelName() + ", ModelUuid=" + vnfResource - .getModelUuid() + " VersionMin=" + minVersionVnf + " VersionMax:" - + maxVersionVnf + " NOT supported on Cloud: " + cloudSiteOpt.get().getId() - + " with AIC_Version:" + cloudSiteOpt.get().getAic_version(); + "VNF Resource type: " + vnfResource.getModelName() + ", ModelUuid=" + vnfResource + .getModelUuid() + " VersionMin=" + minVersionVnf + " VersionMax:" + + maxVersionVnf + " NOT supported on Cloud: " + cloudSiteOpt.get().getId() + + " with AIC_Version:" + cloudSiteOpt.get().getAic_version(); LOGGER.error(MessageEnum.RA_CONFIG_EXC, error, "OpenStack", "", - MsoLogger.ErrorCode.BusinessProcesssError, "Exception - setVersion"); + MsoLogger.ErrorCode.BusinessProcesssError, "Exception - setVersion"); LOGGER.debug(error); throw new VnfException(error, MsoExceptionCategory.USERDATA); } @@ -970,7 +979,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } } else { LOGGER.debug( - "AIC Version not set in VNF_Resource - this is expected thru 1607 - do not error here - not checked."); + "AIC Version not set in VNF_Resource - this is expected thru 1607 - do not error here - not checked."); } // End Version check 1607 @@ -978,49 +987,49 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // with VNF_RESOURCE - we use the old methods. //Integer heatTemplateId = null; //Integer heatEnvtId = null; - + String heatTemplateArtifactUuid = null; String heatEnvironmentArtifactUuid = null; - if (!oldWay) { - if (isVolumeRequest) { - heatTemplateArtifactUuid = vf.getVolHeatTemplateArtifactUUId(); - heatEnvironmentArtifactUuid = vfmc.getVolEnvironmentArtifactUuid(); - } else { - heatTemplateArtifactUuid = vf.getHeatTemplateArtifactUUId(); - heatEnvironmentArtifactUuid = vfmc.getHeatEnvironmentArtifactUuid(); - } - } else { - if (isVolumeRequest) { - LOGGER.debug("DANGER WILL ROBINSON! This should never apply - a VNF Request (gamma only now) *and* a volume request?"); - } else { - heatTemplateArtifactUuid = vnfResource.getTemplateId(); - heatEnvironmentArtifactUuid = null; - } - } - // By the time we get here - heatTemplateId and heatEnvtId should be populated (or null) - HeatTemplate heatTemplate = null; - if (heatTemplateArtifactUuid == null || "".equals(heatTemplateArtifactUuid)) { - String error = "Create: No Heat Template ID defined in catalog database for " + vnfType + ", reqType=" + requestTypeString; - LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Template ID", vnfType, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Create: No Heat Template ID defined in catalog database"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); - alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, - MsoAlarmLogger.CRITICAL, error); - throw new VnfException(error, MsoExceptionCategory.INTERNAL); - } else { - heatTemplate = db.getHeatTemplateByArtifactUuidRegularQuery(heatTemplateArtifactUuid); - } - if (heatTemplate == null) { - String error = "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid; - LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, - "Heat Template ID", - String.valueOf(heatTemplateArtifactUuid), "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); - alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, - MsoAlarmLogger.CRITICAL, error); - throw new VnfException(error, MsoExceptionCategory.INTERNAL); - } - LOGGER.debug("Got HEAT Template from DB"); + if (!oldWay) { + if (isVolumeRequest) { + heatTemplateArtifactUuid = vf.getVolHeatTemplateArtifactUUId(); + heatEnvironmentArtifactUuid = vfmc.getVolEnvironmentArtifactUuid(); + } else { + heatTemplateArtifactUuid = vf.getHeatTemplateArtifactUUId(); + heatEnvironmentArtifactUuid = vfmc.getHeatEnvironmentArtifactUuid(); + } + } else { + if (isVolumeRequest) { + LOGGER.debug("DANGER WILL ROBINSON! This should never apply - a VNF Request (gamma only now) *and* a volume request?"); + } else { + heatTemplateArtifactUuid = vnfResource.getTemplateId(); + heatEnvironmentArtifactUuid = null; + } + } + // By the time we get here - heatTemplateId and heatEnvtId should be populated (or null) + HeatTemplate heatTemplate = null; + if (heatTemplateArtifactUuid == null || "".equals(heatTemplateArtifactUuid)) { + String error = "Create: No Heat Template ID defined in catalog database for " + vnfType + ", reqType=" + requestTypeString; + LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Template ID", vnfType, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Create: No Heat Template ID defined in catalog database"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, + MsoAlarmLogger.CRITICAL, error); + throw new VnfException(error, MsoExceptionCategory.INTERNAL); + } else { + heatTemplate = db.getHeatTemplateByArtifactUuidRegularQuery(heatTemplateArtifactUuid); + } + if (heatTemplate == null) { + String error = "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid; + LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, + "Heat Template ID", + String.valueOf(heatTemplateArtifactUuid), "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, + MsoAlarmLogger.CRITICAL, error); + throw new VnfException(error, MsoExceptionCategory.INTERNAL); + } + LOGGER.debug("Got HEAT Template from DB"); HeatEnvironment heatEnvironment = null; String heatEnvironmentString = null; @@ -1030,13 +1039,13 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { heatEnvironment = db.getHeatEnvironmentByArtifactUuid(heatEnvironmentArtifactUuid); if (heatEnvironment == null) { String error = "Create VFModule: undefined Heat Environment. VFModule=" + vfModuleType - + ", Environment ID=" - + heatEnvironmentArtifactUuid; + + ", Environment ID=" + + heatEnvironmentArtifactUuid; LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Environment ID", - String.valueOf(heatEnvironmentArtifactUuid), "OpenStack", "getHeatEnvironment", - MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: undefined Heat Environment"); + String.valueOf(heatEnvironmentArtifactUuid), "OpenStack", "getHeatEnvironment", + MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: undefined Heat Environment"); LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, - error); + error); // Alarm on this error, configuration must be fixed alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error); @@ -1044,7 +1053,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } else { LOGGER.debug("Got Heat Environment from DB: " + heatEnvironment.toString()); heatEnvironmentString = heatEnvironment - .getEnvironment(); //this.parseEnvironment (heatEnvironment.getEnvironment ()); + .getEnvironment(); //this.parseEnvironment (heatEnvironment.getEnvironment ()); LOGGER.debug("after parsing: " + heatEnvironmentString); } } else { @@ -1053,7 +1062,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // 1510 - Add the files: for nested templates *if* there are any LOGGER.debug("In MsoVnfAdapterImpl, createVfModule about to call db.getNestedTemplates avec templateId=" - + heatTemplate.getArtifactUuid()); + + heatTemplate.getArtifactUuid()); Map<String, Object> nestedTemplates = db.getNestedTemplates(heatTemplate.getArtifactUuid()); Map<String, Object> nestedTemplatesChecked = new HashMap<>(); if (nestedTemplates != null) { @@ -1075,69 +1084,69 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // 1510 - Also add the files: for any get_files associated with this vnf_resource_id // *if* there are any Map<String, HeatFiles> heatFiles = null; - Map<String, Object> heatFilesObjects = new HashMap<>(); + Map<String, Object> heatFilesObjects = new HashMap<>(); // Add ability to turn on adding get_files with volume requests (by property). boolean addGetFilesOnVolumeReq = false; try { - String propertyString = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_VNF_ADAPTER).getProperty(MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ, null); - if ("true".equalsIgnoreCase(propertyString) || "y".equalsIgnoreCase(propertyString)) { - addGetFilesOnVolumeReq = true; - LOGGER.debug("AddGetFilesOnVolumeReq - setting to true! " + propertyString); - } + String propertyString = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_VNF_ADAPTER).getProperty(MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ, null); + if ("true".equalsIgnoreCase(propertyString) || "y".equalsIgnoreCase(propertyString)) { + addGetFilesOnVolumeReq = true; + LOGGER.debug("AddGetFilesOnVolumeReq - setting to true! " + propertyString); + } } catch (Exception e) { - LOGGER.debug("An error occured trying to get property " + MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ + " - default to false", e); - } - - if (!isVolumeRequest || addGetFilesOnVolumeReq) { - if (oldWay) { - LOGGER.debug("In MsoVnfAdapterImpl createVfModule, this should not happen - old way is gamma only - no heat files!"); - //heatFiles = db.getHeatFiles(vnfResource.getId()); - } else { - // 1607 - now use VF_MODULE_TO_HEAT_FILES table - LOGGER.debug("In MsoVnfAdapterImpl createVfModule, about to call db.getHeatFilesForVfModule avec vfModuleId=" - + vf.getModelUUID()); - heatFiles = db - .getHeatFilesForVfModule(vf.getModelUUID()); - } - if (heatFiles != null) { - // add these to stack - to be done in createStack - // here, we will map them to Map<String, Object> from - // Map<String, HeatFiles> - // this will match the nested templates format - LOGGER.debug("Contents of heatFiles - to be added to files: on stack:"); - - for (Map.Entry<String, HeatFiles> entry : heatFiles.entrySet()) { - String heatFileName = entry.getKey(); - HeatFiles value = entry.getValue(); - if (heatFileName.startsWith("_ERROR|")) { - // This means there was an invalid entry in VF_MODULE_TO_HEAT_FILES table - the heat file it pointed to could not be found. - String heatFileId = heatFileName.substring(heatFileName.lastIndexOf("|")+1); - String error = "Create: No HEAT_FILES entry in catalog database for " + vfModuleType + " at HEAT_FILES index=" + heatFileId; - LOGGER.debug(error); - LOGGER.error (MessageEnum.RA_VNF_UNKNOWN_PARAM, "HEAT_FILES entry not found at " + heatFileId, vfModuleType, "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError, "HEAT_FILES entry not found"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); - // Alarm on this error, configuration must be fixed - alarmLogger.sendAlarm (MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error); - throw new VnfException (error, MsoExceptionCategory.INTERNAL); - } - String heatFileBody = value.getFileBody(); - String heatFileNameChecked = heatFileName; - LOGGER.debug(heatFileNameChecked + " -> " - + heatFileBody); - heatFilesObjects.put(heatFileNameChecked, heatFileBody); - } - } else { - LOGGER.debug("No heat files found -nothing to do here"); - heatFilesObjects = null; - } - } else { - LOGGER.debug("Volume request - DO NOT CHECK for HEAT_FILES"); - } + LOGGER.debug("An error occured trying to get property " + MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ + " - default to false", e); + } + + if (!isVolumeRequest || addGetFilesOnVolumeReq) { + if (oldWay) { + LOGGER.debug("In MsoVnfAdapterImpl createVfModule, this should not happen - old way is gamma only - no heat files!"); + //heatFiles = db.getHeatFiles(vnfResource.getId()); + } else { + // 1607 - now use VF_MODULE_TO_HEAT_FILES table + LOGGER.debug("In MsoVnfAdapterImpl createVfModule, about to call db.getHeatFilesForVfModule avec vfModuleId=" + + vf.getModelUUID()); + heatFiles = db + .getHeatFilesForVfModule(vf.getModelUUID()); + } + if (heatFiles != null) { + // add these to stack - to be done in createStack + // here, we will map them to Map<String, Object> from + // Map<String, HeatFiles> + // this will match the nested templates format + LOGGER.debug("Contents of heatFiles - to be added to files: on stack:"); + + for (Map.Entry<String, HeatFiles> entry : heatFiles.entrySet()) { + String heatFileName = entry.getKey(); + HeatFiles value = entry.getValue(); + if (heatFileName.startsWith("_ERROR|")) { + // This means there was an invalid entry in VF_MODULE_TO_HEAT_FILES table - the heat file it pointed to could not be found. + String heatFileId = heatFileName.substring(heatFileName.lastIndexOf("|") + 1); + String error = "Create: No HEAT_FILES entry in catalog database for " + vfModuleType + " at HEAT_FILES index=" + heatFileId; + LOGGER.debug(error); + LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "HEAT_FILES entry not found at " + heatFileId, vfModuleType, "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError, "HEAT_FILES entry not found"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + // Alarm on this error, configuration must be fixed + alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error); + throw new VnfException(error, MsoExceptionCategory.INTERNAL); + } + String heatFileBody = value.getFileBody(); + String heatFileNameChecked = heatFileName; + LOGGER.debug(heatFileNameChecked + " -> " + + heatFileBody); + heatFilesObjects.put(heatFileNameChecked, heatFileBody); + } + } else { + LOGGER.debug("No heat files found -nothing to do here"); + heatFilesObjects = null; + } + } else { + LOGGER.debug("Volume request - DO NOT CHECK for HEAT_FILES"); + } // Check that required parameters have been supplied StringBuilder missingParams = null; - List <String> paramList = new ArrayList <> (); + List<String> paramList = new ArrayList<>(); // New for 1510 - consult the PARAM_ALIAS field to see if we've been // supplied an alias. Only check if we don't find it initially. @@ -1147,11 +1156,11 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { boolean checkRequiredParameters = true; try { String propertyString = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_VNF_ADAPTER) - .getProperty(MsoVnfAdapterImpl.CHECK_REQD_PARAMS, null); + .getProperty(MsoVnfAdapterImpl.CHECK_REQD_PARAMS, null); if ("false".equalsIgnoreCase(propertyString) || "n".equalsIgnoreCase(propertyString)) { checkRequiredParameters = false; LOGGER.debug("CheckRequiredParameters is FALSE. Will still check but then skip blocking..." - + MsoVnfAdapterImpl.CHECK_REQD_PARAMS); + + MsoVnfAdapterImpl.CHECK_REQD_PARAMS); } } catch (Exception e) { // No problem - default is true @@ -1164,47 +1173,54 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { MsoHeatEnvironmentEntry mhee = null; if (heatEnvironmentString != null && heatEnvironmentString.contains("parameters:")) { //LOGGER.debug ("Have an Environment argument with a parameters: section - will bypass checking for valid params - but will still check for aliases"); - LOGGER.debug("Enhanced environment checking enabled - 1604"); + LOGGER.debug("Enhanced environment checking enabled - 1604"); StringBuilder sb = new StringBuilder(heatEnvironmentString); //LOGGER.debug("About to create MHEE with " + sb); mhee = new MsoHeatEnvironmentEntry(sb); + + // sshank: hpaEnviromnentString is obtained from requestTypeString above. + if (hpaEnviromnentString != null && hpaEnviromnentString.contains("parameters:")) { + StringBuilder hpasb = new StringBuilder(hpaEnviromnentString); + mhee.setHPAParameters(hpasb); + } + StringBuilder sb2 = new StringBuilder("\nHeat Template Parameters:\n"); for (HeatTemplateParam parm : heatTemplate.getParameters()) { - sb2.append("\t" + parm.getParamName() + ", required=" + parm.isRequired()); + sb2.append("\t" + parm.getParamName() + ", required=" + parm.isRequired()); } if (!mhee.isValid()) { - sb2.append("Environment says it's not valid! " + mhee.getErrorString()); + sb2.append("Environment says it's not valid! " + mhee.getErrorString()); } else { - sb2.append("\nEnvironment:"); + sb2.append("\nEnvironment:"); sb2.append(mhee); } LOGGER.debug(sb2.toString()); } else { - LOGGER.debug("NO ENVIRONMENT for this entry"); + LOGGER.debug("NO ENVIRONMENT for this entry"); } // New with 1707 - all variables converted to their native object types HashMap<String, Object> goldenInputs = null; - + LOGGER.debug("Now handle the inputs....first convert"); ArrayList<String> parameterNames = new ArrayList<>(); HashMap<String, String> aliasToParam = new HashMap<>(); StringBuilder sb = new StringBuilder("\nTemplate Parameters:\n"); int cntr = 0; - try { - for (HeatTemplateParam htp : heatTemplate.getParameters()) { - sb.append("param[" + cntr++ + "]=" + htp.getParamName()); - parameterNames.add(htp.getParamName()); - if (htp.getParamAlias() != null && !"".equals(htp.getParamAlias())) { - aliasToParam.put(htp.getParamAlias(), htp.getParamName()); - sb.append(" ** (alias=" + htp.getParamAlias() + ")"); - } - sb.append("\n"); - } - LOGGER.debug(sb.toString()); + try { + for (HeatTemplateParam htp : heatTemplate.getParameters()) { + sb.append("param[" + cntr++ + "]=" + htp.getParamName()); + parameterNames.add(htp.getParamName()); + if (htp.getParamAlias() != null && !"".equals(htp.getParamAlias())) { + aliasToParam.put(htp.getParamAlias(), htp.getParamName()); + sb.append(" ** (alias=" + htp.getParamAlias() + ")"); + } + sb.append("\n"); + } + LOGGER.debug(sb.toString()); } catch (Exception e) { - LOGGER.debug("??An exception occurred trying to go through Parameter Names " + e.getMessage(),e); + LOGGER.debug("??An exception occurred trying to go through Parameter Names " + e.getMessage(), e); } - // Step 1 - convert what we got as inputs (Map<String, String>) to a + // Step 1 - convert what we got as inputs (Map<String, String>) to a // Map<String, Object> - where the object matches the param type identified in the template // This will also not copy over params that aren't identified in the template goldenInputs = heat.convertInputMap(inputs, heatTemplate); @@ -1218,18 +1234,18 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { for (HeatTemplateParam parm : heatTemplate.getParameters()) { LOGGER.debug("Parameter:'" + parm.getParamName() - + "', isRequired=" - + parm.isRequired() - + ", alias=" - + parm.getParamAlias()); + + "', isRequired=" + + parm.isRequired() + + ", alias=" + + parm.getParamAlias()); if (parm.isRequired() && (goldenInputs == null || !goldenInputs.containsKey(parm.getParamName()))) { // The check for an alias was moved to the method in MsoHeatUtils - when we converted the Map<String, String> to Map<String, Object> LOGGER.debug("**Parameter " + parm.getParamName() - + " is required and not in the inputs...check environment"); + + " is required and not in the inputs...check environment"); if (mhee != null && mhee.containsParameter(parm.getParamName())) { LOGGER.debug("Required parameter " + parm.getParamName() - + " appears to be in environment - do not count as missing"); + + " appears to be in environment - do not count as missing"); } else { LOGGER.debug("adding to missing parameters list: " + parm.getParamName()); if (missingParams == null) { @@ -1246,9 +1262,9 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // Problem - missing one or more required parameters String error = "Create VFModule: Missing Required inputs: " + missingParams; LOGGER.error(MessageEnum.RA_MISSING_PARAM, missingParams.toString(), "OpenStack", "", - MsoLogger.ErrorCode.DataError, "Create VFModule: Missing Required inputs"); + MsoLogger.ErrorCode.DataError, "Create VFModule: Missing Required inputs"); LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, - error); + error); throw new VnfException(error, MsoExceptionCategory.USERDATA); } else { LOGGER.debug("found missing parameters - but checkRequiredParameters is false - will not block"); @@ -1256,13 +1272,13 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } else { LOGGER.debug("No missing parameters found - ok to proceed"); } - // We can now remove the recreating of the ENV with only legit params - that check is done for us, + // We can now remove the recreating of the ENV with only legit params - that check is done for us, // and it causes problems with json that has arrays String newEnvironmentString = null; if (mhee != null) { newEnvironmentString = mhee.getRawEntry().toString(); } - + // "Fix" the template if it has CR/LF (getting this from Oracle) String template = heatTemplate.getHeatTemplate(); template = template.replaceAll("\r\n", "\n"); @@ -1281,50 +1297,50 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { LOGGER.debug("heat is not null!!"); } heatStack = heat.createStack(cloudSiteId, - tenantId, - vfModuleName, - template, - goldenInputs, - true, - heatTemplate.getTimeoutMinutes(), - newEnvironmentString, - nestedTemplatesChecked, - heatFilesObjects, - backout.booleanValue()); + tenantId, + vfModuleName, + template, + goldenInputs, + true, + heatTemplate.getTimeoutMinutes(), + newEnvironmentString, + nestedTemplatesChecked, + heatFilesObjects, + backout.booleanValue()); LOGGER - .recordMetricEvent(createStackStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "Successfully received response from Open Stack", "OpenStack", "CreateStack", vfModuleName); + .recordMetricEvent(createStackStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully received response from Open Stack", "OpenStack", "CreateStack", vfModuleName); } catch (MsoException me) { me.addContext("CreateVFModule"); String error = "Create VF Module " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + me; LOGGER.recordMetricEvent(createStackStarttime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "CreateStack", vfModuleName); + MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "CreateStack", vfModuleName); LOGGER.error(MessageEnum.RA_CREATE_VNF_ERR, vfModuleType, cloudSiteId, tenantId, "OpenStack", "", - MsoLogger.ErrorCode.DataError, "MsoException - createStack", me); + MsoLogger.ErrorCode.DataError, "MsoException - createStack", me); LOGGER - .recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, - error); + .recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, + error); throw new VnfException(me); } catch (NullPointerException npe) { String error = "Create VFModule " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + npe; LOGGER.recordMetricEvent(createStackStarttime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "CreateStack", vfModuleName); + MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "CreateStack", vfModuleName); LOGGER.error(MessageEnum.RA_CREATE_VNF_ERR, vfModuleType, cloudSiteId, tenantId, "OpenStack", "", - MsoLogger.ErrorCode.DataError, "NullPointerException - createStack", npe); + MsoLogger.ErrorCode.DataError, "NullPointerException - createStack", npe); LOGGER - .recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, - error); + .recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, + error); LOGGER.debug("NULL POINTER EXCEPTION at heat.createStack"); //npe.addContext ("CreateVNF"); throw new VnfException("NullPointerException during heat.createStack"); } catch (Exception e) { LOGGER.recordMetricEvent(createStackStarttime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.CommunicationError, "Exception while creating stack with OpenStack", - "OpenStack", "CreateStack", vfModuleName); + MsoLogger.ResponseCode.CommunicationError, "Exception while creating stack with OpenStack", + "OpenStack", "CreateStack", vfModuleName); LOGGER.debug("unhandled exception at heat.createStack", e); LOGGER - .recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, - "Exception while creating stack with OpenStack"); + .recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, + "Exception while creating stack with OpenStack"); throw new VnfException("Exception during heat.createStack! " + e.getMessage()); } } catch (Exception e) { @@ -1336,30 +1352,30 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // Reach this point if createStack is successful. // Populate remaining rollback info and response parameters. - vfRollback.setVnfId (heatStack.getCanonicalName ()); - vfRollback.setVnfCreated (true); + vfRollback.setVnfId(heatStack.getCanonicalName()); + vfRollback.setVnfCreated(true); - vnfId.value = heatStack.getCanonicalName (); - outputs.value = copyStringOutputs (heatStack.getOutputs ()); + vnfId.value = heatStack.getCanonicalName(); + outputs.value = copyStringOutputs(heatStack.getOutputs()); rollback.value = vfRollback; - LOGGER.debug ("VF Module " + vfModuleName + " successfully created"); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create VF Module"); + LOGGER.debug("VF Module " + vfModuleName + " successfully created"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create VF Module"); } @Override - public void deleteVfModule (String cloudSiteId, - String tenantId, - String vnfName, - MsoRequest msoRequest, - Holder <Map <String, String>> outputs) throws VnfException { - MsoLogger.setLogContext (msoRequest); - MsoLogger.setServiceName ("DeleteVf"); - LOGGER.debug ("Deleting VF " + vnfName + " in " + cloudSiteId + "/" + tenantId); + public void deleteVfModule(String cloudSiteId, + String tenantId, + String vnfName, + MsoRequest msoRequest, + Holder<Map<String, String>> outputs) throws VnfException { + MsoLogger.setLogContext(msoRequest); + MsoLogger.setServiceName("DeleteVf"); + LOGGER.debug("Deleting VF " + vnfName + " in " + cloudSiteId + "/" + tenantId); // Will capture execution time for metrics - long startTime = System.currentTimeMillis (); + long startTime = System.currentTimeMillis(); - MsoHeatUtils heat = new MsoHeatUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory); + MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory); // 1702 capture the output parameters on a delete // so we'll need to query first @@ -1369,12 +1385,12 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } catch (MsoException me) { // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException - me.addContext ("DeleteVFModule"); + me.addContext("DeleteVFModule"); String error = "Delete VFModule: Query to get outputs: " + vnfName + " in " + cloudSiteId + "/" + tenantId + ": " + me; - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", null); - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - QueryStack", me); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", null); + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - QueryStack", me); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); } // call method which handles the conversion from Map<String,Object> to Map<String,String> for our expected Object types outputs.value = this.convertMapStringObjectToStringString(stackOutputs); @@ -1383,57 +1399,57 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // The possible outcomes of deleteStack are a StackInfo object with status // of NOTFOUND (on success) or FAILED (on error). Also, MsoOpenstackException // could be thrown. - long subStartTime = System.currentTimeMillis (); + long subStartTime = System.currentTimeMillis(); try { - heat.deleteStack (tenantId, cloudSiteId, vnfName, true); - LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "DeleteStack", vnfName); + heat.deleteStack(tenantId, cloudSiteId, vnfName, true); + LOGGER.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "DeleteStack", vnfName); } catch (MsoException me) { - me.addContext ("DeleteVNF"); + me.addContext("DeleteVNF"); // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException String error = "Delete VF: " + vnfName + " in " + cloudSiteId + "/" + tenantId + ": " + me; - LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "DeleteStack", vnfName); - LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "DeleteStack", MsoLogger.ErrorCode.DataError, "Exception - deleteStack", me); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); + LOGGER.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "DeleteStack", vnfName); + LOGGER.error(MessageEnum.RA_DELETE_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "DeleteStack", MsoLogger.ErrorCode.DataError, "Exception - deleteStack", me); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); } // On success, nothing is returned. - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully delete VF"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully delete VF"); } @Override - public void updateVfModule (String cloudSiteId, - String tenantId, - String vnfType, - String vnfVersion, - String vnfName, - String requestType, - String volumeGroupHeatStackId, - String baseVfHeatStackId, - String vfModuleStackId, - String modelCustomizationUuid, - Map <String, String> inputs, - MsoRequest msoRequest, - Holder <Map <String, String>> outputs, - Holder <VnfRollback> rollback) throws VnfException { + public void updateVfModule(String cloudSiteId, + String tenantId, + String vnfType, + String vnfVersion, + String vnfName, + String requestType, + String volumeGroupHeatStackId, + String baseVfHeatStackId, + String vfModuleStackId, + String modelCustomizationUuid, + Map<String, String> inputs, + MsoRequest msoRequest, + Holder<Map<String, String>> outputs, + Holder<VnfRollback> rollback) throws VnfException { String vfModuleName = vnfName; String vfModuleType = vnfType; String methodName = "updateVfModule"; - MsoLogger.setLogContext (msoRequest.getRequestId (), msoRequest.getServiceInstanceId ()); + MsoLogger.setLogContext(msoRequest.getRequestId(), msoRequest.getServiceInstanceId()); String serviceName = VNF_ADAPTER_SERVICE_NAME + methodName; - MsoLogger.setServiceName (serviceName); + MsoLogger.setServiceName(serviceName); String strInit = "updateVfModule: cloudSiteId=" + cloudSiteId + - ",tenantId=" + tenantId + - ",vnfType=" + vnfType + - ",vnfVersion=" + vnfVersion + - ",vnfName=" + vnfName + - ",requestType=" + requestType + - ",volumeGroupHeatStackId=" + volumeGroupHeatStackId + - ",baseVfHeatStackId=" + baseVfHeatStackId + - ",vfModuleStackId=" + vfModuleStackId + - ",modelCustomizationUuid=" + modelCustomizationUuid; + ",tenantId=" + tenantId + + ",vnfType=" + vnfType + + ",vnfVersion=" + vnfVersion + + ",vnfName=" + vnfName + + ",requestType=" + requestType + + ",volumeGroupHeatStackId=" + volumeGroupHeatStackId + + ",baseVfHeatStackId=" + baseVfHeatStackId + + ",vfModuleStackId=" + vfModuleStackId + + ",modelCustomizationUuid=" + modelCustomizationUuid; LOGGER.debug(strInit); String mcu = modelCustomizationUuid; @@ -1449,52 +1465,52 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } } - String requestTypeString = ""; + String requestTypeString = ""; if (requestType != null && !"".equals(requestType)) { - requestTypeString = requestType; + requestTypeString = requestType; } String nestedStackId = null; if (volumeGroupHeatStackId != null && !"".equals(volumeGroupHeatStackId)) { - if (!"null".equalsIgnoreCase(volumeGroupHeatStackId)) { - nestedStackId = volumeGroupHeatStackId; - } + if (!"null".equalsIgnoreCase(volumeGroupHeatStackId)) { + nestedStackId = volumeGroupHeatStackId; + } } String nestedBaseStackId = null; if (baseVfHeatStackId != null && !"".equals(baseVfHeatStackId)) { - if (!"null".equalsIgnoreCase(baseVfHeatStackId)) { - nestedBaseStackId = baseVfHeatStackId; - } + if (!"null".equalsIgnoreCase(baseVfHeatStackId)) { + nestedBaseStackId = baseVfHeatStackId; + } } if (inputs == null) { - // Create an empty set of inputs - inputs = new HashMap<>(); - LOGGER.debug("inputs == null - setting to empty"); + // Create an empty set of inputs + inputs = new HashMap<>(); + LOGGER.debug("inputs == null - setting to empty"); } else { - this.sendMapToDebug(inputs); + this.sendMapToDebug(inputs); } boolean isBaseRequest = false; boolean isVolumeRequest = false; if (requestTypeString.startsWith("VOLUME")) { - isVolumeRequest = true; + isVolumeRequest = true; } if (vfModuleName == null || "".equals(vfModuleName.trim())) { - if (vfModuleStackId != null) { - vfModuleName = this.getVfModuleNameFromModuleStackId(vfModuleStackId); - } + if (vfModuleStackId != null) { + vfModuleName = this.getVfModuleNameFromModuleStackId(vfModuleStackId); + } } - LOGGER.debug ("Updating VFModule: " + vfModuleName + " of type " + vfModuleType + "in " + cloudSiteId + "/" + tenantId); + LOGGER.debug("Updating VFModule: " + vfModuleName + " of type " + vfModuleType + "in " + cloudSiteId + "/" + tenantId); LOGGER.debug("requestTypeString = " + requestTypeString + ", nestedVolumeStackId = " + nestedStackId + ", nestedBaseStackId = " + nestedBaseStackId); // Will capture execution time for metrics - long startTime = System.currentTimeMillis (); + long startTime = System.currentTimeMillis(); // Build a default rollback object (no actions performed) - VnfRollback vfRollback = new VnfRollback (); - vfRollback.setCloudSiteId (cloudSiteId); - vfRollback.setTenantId (tenantId); - vfRollback.setMsoRequest (msoRequest); + VnfRollback vfRollback = new VnfRollback(); + vfRollback.setCloudSiteId(cloudSiteId); + vfRollback.setTenantId(tenantId); + vfRollback.setMsoRequest(msoRequest); vfRollback.setRequestType(requestTypeString); vfRollback.setVolumeGroupHeatStackId(volumeGroupHeatStackId); vfRollback.setBaseGroupHeatStackId(baseVfHeatStackId); @@ -1503,113 +1519,113 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { vfRollback.setModelCustomizationUuid(mcu); // First, look up to see if the VNF already exists. - MsoHeatUtils heat = new MsoHeatUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory); - MsoHeatUtilsWithUpdate heatU = new MsoHeatUtilsWithUpdate (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory); + MsoHeatUtils heat = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory); + MsoHeatUtilsWithUpdate heatU = new MsoHeatUtilsWithUpdate(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory); StackInfo heatStack = null; - long queryStackStarttime = System.currentTimeMillis (); + long queryStackStarttime = System.currentTimeMillis(); LOGGER.debug("UpdateVfModule - querying for " + vfModuleName); try { - heatStack = heat.queryStack (cloudSiteId, tenantId, vfModuleName); - LOGGER.recordMetricEvent (queryStackStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", "QueryStack", null); + heatStack = heat.queryStack(cloudSiteId, tenantId, vfModuleName); + LOGGER.recordMetricEvent(queryStackStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", "QueryStack", null); } catch (MsoException me) { // Failed to query the Stack due to an openstack exception. // Convert to a generic VnfException - me.addContext ("UpdateVFModule"); + me.addContext("UpdateVFModule"); String error = "Update VFModule: Query " + vfModuleName + " in " + cloudSiteId + "/" + tenantId + ": " + me; - LOGGER.recordMetricEvent (queryStackStarttime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", null); - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - QueryStack", me); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); + LOGGER.recordMetricEvent(queryStackStarttime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", null); + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - QueryStack", me); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); } //TODO - do we need to check for the other status possibilities? - if (heatStack == null || heatStack.getStatus () == HeatStatus.NOTFOUND) { + if (heatStack == null || heatStack.getStatus() == HeatStatus.NOTFOUND) { // Not Found String error = "Update VF: Stack " + vfModuleName + " does not exist in " + cloudSiteId + "/" + tenantId; - LOGGER.error (MessageEnum.RA_VNF_NOT_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, error); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); - throw new VnfNotFound (cloudSiteId, tenantId, vfModuleName); + LOGGER.error(MessageEnum.RA_VNF_NOT_EXIST, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, error); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + throw new VnfNotFound(cloudSiteId, tenantId, vfModuleName); } else { - LOGGER.debug ("Found Existing stack, status=" + heatStack.getStatus ()); + LOGGER.debug("Found Existing stack, status=" + heatStack.getStatus()); // Populate the outputs from the existing stack. - outputs.value = copyStringOutputs (heatStack.getOutputs ()); + outputs.value = copyStringOutputs(heatStack.getOutputs()); rollback.value = vfRollback; // Default rollback - no updates performed } // 1604 Cinder Volume support - handle a nestedStackId if sent (volumeGroupHeatStackId): StackInfo nestedHeatStack = null; - long queryStackStarttime2 = System.currentTimeMillis (); + long queryStackStarttime2 = System.currentTimeMillis(); Map<String, Object> nestedVolumeOutputs = null; if (nestedStackId != null) { - try { - LOGGER.debug("Querying for nestedStackId = " + nestedStackId); - nestedHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedStackId); - LOGGER.recordMetricEvent (queryStackStarttime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", "QueryStack", null); - } catch (MsoException me) { - // Failed to query the Stack due to an openstack exception. - // Convert to a generic VnfException - me.addContext ("UpdateVFModule"); - String error = "Update VF: Attached heatStack ID Query " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ; - LOGGER.recordMetricEvent (queryStackStarttime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", null); - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - " + error, me); - LOGGER.debug("ERROR trying to query nested stack= " + error); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); - } - if (nestedHeatStack == null || nestedHeatStack.getStatus() == HeatStatus.NOTFOUND) { - MsoLogger.setServiceName (serviceName); - String error = "Update VFModule: Attached volume heatStack ID DOES NOT EXIST " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ; - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, error); - LOGGER.debug(error); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); - throw new VnfException (error, MsoExceptionCategory.USERDATA); - } else { - LOGGER.debug("Found nested heat stack - copying values to inputs *later*"); - nestedVolumeOutputs = nestedHeatStack.getOutputs(); - //this.sendMapToDebug(inputs); - this.sendMapToDebug(nestedVolumeOutputs, "volumeStackOutputs"); - //TODO - heat.copyStringOutputsToInputs(inputs, nestedHeatStack.getOutputs(), false); - //this.sendMapToDebug(inputs); - } + try { + LOGGER.debug("Querying for nestedStackId = " + nestedStackId); + nestedHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedStackId); + LOGGER.recordMetricEvent(queryStackStarttime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", "QueryStack", null); + } catch (MsoException me) { + // Failed to query the Stack due to an openstack exception. + // Convert to a generic VnfException + me.addContext("UpdateVFModule"); + String error = "Update VF: Attached heatStack ID Query " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me; + LOGGER.recordMetricEvent(queryStackStarttime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", null); + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - " + error, me); + LOGGER.debug("ERROR trying to query nested stack= " + error); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); + } + if (nestedHeatStack == null || nestedHeatStack.getStatus() == HeatStatus.NOTFOUND) { + MsoLogger.setServiceName(serviceName); + String error = "Update VFModule: Attached volume heatStack ID DOES NOT EXIST " + nestedStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR"; + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vnfName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, error); + LOGGER.debug(error); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + throw new VnfException(error, MsoExceptionCategory.USERDATA); + } else { + LOGGER.debug("Found nested heat stack - copying values to inputs *later*"); + nestedVolumeOutputs = nestedHeatStack.getOutputs(); + //this.sendMapToDebug(inputs); + this.sendMapToDebug(nestedVolumeOutputs, "volumeStackOutputs"); + //TODO + heat.copyStringOutputsToInputs(inputs, nestedHeatStack.getOutputs(), false); + //this.sendMapToDebug(inputs); + } } // handle a nestedBaseStackId if sent - this is the stack ID of the base. StackInfo nestedBaseHeatStack = null; Map<String, Object> baseStackOutputs = null; if (nestedBaseStackId != null) { - long queryStackStarttime3 = System.currentTimeMillis (); - try { - LOGGER.debug("Querying for nestedBaseStackId = " + nestedBaseStackId); - nestedBaseHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedBaseStackId); - LOGGER.recordMetricEvent (queryStackStarttime3, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", "QueryStack", null); - } catch (MsoException me) { - // Failed to query the Stack due to an openstack exception. - // Convert to a generic VnfException - me.addContext ("UpdateVfModule"); - String error = "Update VFModule: Attached baseHeatStack ID Query " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me ; - LOGGER.recordMetricEvent (queryStackStarttime3, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", null); - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - " + error, me); - LOGGER.debug("ERROR trying to query nested base stack= " + error); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); - throw new VnfException (me); - } - if (nestedBaseHeatStack == null || nestedBaseHeatStack.getStatus() == HeatStatus.NOTFOUND) { - MsoLogger.setServiceName (serviceName); - String error = "Update VFModule: Attached base heatStack ID DOES NOT EXIST " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ; - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, error); - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); - LOGGER.debug(error); - throw new VnfException (error, MsoExceptionCategory.USERDATA); - } else { - LOGGER.debug("Found nested base heat stack - copying values to inputs *later*"); - baseStackOutputs = nestedBaseHeatStack.getOutputs(); - //this.sendMapToDebug(inputs); - this.sendMapToDebug(baseStackOutputs, "baseStackOutputs"); - //TODO - heat.copyStringOutputsToInputs(inputs, nestedBaseHeatStack.getOutputs(), false); - //this.sendMapToDebug(inputs); - } + long queryStackStarttime3 = System.currentTimeMillis(); + try { + LOGGER.debug("Querying for nestedBaseStackId = " + nestedBaseStackId); + nestedBaseHeatStack = heat.queryStack(cloudSiteId, tenantId, nestedBaseStackId); + LOGGER.recordMetricEvent(queryStackStarttime3, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", "QueryStack", null); + } catch (MsoException me) { + // Failed to query the Stack due to an openstack exception. + // Convert to a generic VnfException + me.addContext("UpdateVfModule"); + String error = "Update VFModule: Attached baseHeatStack ID Query " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + ": " + me; + LOGGER.recordMetricEvent(queryStackStarttime3, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryStack", null); + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, "Exception - " + error, me); + LOGGER.debug("ERROR trying to query nested base stack= " + error); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException(me); + } + if (nestedBaseHeatStack == null || nestedBaseHeatStack.getStatus() == HeatStatus.NOTFOUND) { + MsoLogger.setServiceName(serviceName); + String error = "Update VFModule: Attached base heatStack ID DOES NOT EXIST " + nestedBaseStackId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR"; + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, error, "OpenStack", "QueryStack", MsoLogger.ErrorCode.DataError, error); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + LOGGER.debug(error); + throw new VnfException(error, MsoExceptionCategory.USERDATA); + } else { + LOGGER.debug("Found nested base heat stack - copying values to inputs *later*"); + baseStackOutputs = nestedBaseHeatStack.getOutputs(); + //this.sendMapToDebug(inputs); + this.sendMapToDebug(baseStackOutputs, "baseStackOutputs"); + //TODO + heat.copyStringOutputsToInputs(inputs, nestedBaseHeatStack.getOutputs(), false); + //this.sendMapToDebug(inputs); + } } // Ready to deploy the new VNF @@ -1620,36 +1636,36 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { try (CatalogDatabase db = CatalogDatabase.getInstance()) { // Retrieve the VF definition VnfResource vnfResource = null; - VfModule vf = null; - VfModuleCustomization vfmc = null; + VfModule vf = null; + VfModuleCustomization vfmc = null; if (useMCUuid) { - //vf = db.getVfModuleByModelCustomizationUuid(mcu); - vfmc = db.getVfModuleCustomizationByModelCustomizationId(mcu); - vf = vfmc != null ? vfmc.getVfModule() : null; + //vf = db.getVfModuleByModelCustomizationUuid(mcu); + vfmc = db.getVfModuleCustomizationByModelCustomizationId(mcu); + vf = vfmc != null ? vfmc.getVfModule() : null; if (vf == null) { LOGGER.debug("Unable to find a vfModule matching modelCustomizationUuid=" + mcu); } - } else { - LOGGER.debug("1707 and later - MUST PROVIDE Model Customization UUID!"); + } else { + LOGGER.debug("1707 and later - MUST PROVIDE Model Customization UUID!"); } if (vf == null) { String error = "Update VfModule: unable to find vfModule with modelCustomizationUuid=" + mcu; LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "VF Module Type", vfModuleType, "OpenStack", "", - MsoLogger.ErrorCode.DataError, error); + MsoLogger.ErrorCode.DataError, error); LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataError, error); throw new VnfException(error, MsoExceptionCategory.USERDATA); } LOGGER.debug("Got VF module definition from Catalog: " + vf.toString()); if (vf.isBase()) { - isBaseRequest = true; - LOGGER.debug("This a BASE update request"); + isBaseRequest = true; + LOGGER.debug("This a BASE update request"); } else { LOGGER.debug("This is *not* a BASE VF update request"); if (!isVolumeRequest && nestedBaseStackId == null) { LOGGER.debug("This is unexpected - no nestedBaseStackId with this non-base request"); } } - + //1607 - Add version check // First - see if it's in the VnfResource record // if we have a vf Module - then we have to query to get the VnfResource record. @@ -1659,7 +1675,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { vnfResource = db.getVnfResourceByModelUuid(vnfResourceModelUuid); if (vnfResource == null) { LOGGER - .debug("Unable to find vnfResource at " + vnfResourceModelUuid + " will not error for now..."); + .debug("Unable to find vnfResource at " + vnfResourceModelUuid + " will not error for now..."); } } String minVersionVnf = null; @@ -1692,34 +1708,34 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { if (cloudSiteOpt.isPresent()) { aicV.setVersion(cloudSiteOpt.get().getAic_version()); if ((aicV.isMoreRecentThan(minVersionVnf) || aicV.isTheSameVersion(minVersionVnf)) // aic >= min - && (aicV.isTheSameVersion(maxVersionVnf) || !(aicV - .isMoreRecentThan(maxVersionVnf)))) { //aic <= max + && (aicV.isTheSameVersion(maxVersionVnf) || !(aicV + .isMoreRecentThan(maxVersionVnf)))) { //aic <= max LOGGER.debug("VNF Resource " + vnfResource.getModelName() + " VersionMin=" + minVersionVnf - + " VersionMax:" + maxVersionVnf + " supported on Cloud: " + cloudSiteOpt.get().getId() - + " with AIC_Version:" + cloudSiteOpt.get().getAic_version()); + + " VersionMax:" + maxVersionVnf + " supported on Cloud: " + cloudSiteOpt.get().getId() + + " with AIC_Version:" + cloudSiteOpt.get().getAic_version()); } else { // ERROR String error = - "VNF Resource type: " + vnfResource.getModelName() + " VersionMin=" + minVersionVnf - + " VersionMax:" + maxVersionVnf + " NOT supported on Cloud: " + cloudSiteOpt.get() - .getId() + " with AIC_Version:" + cloudSiteOpt.get().getAic_version(); + "VNF Resource type: " + vnfResource.getModelName() + " VersionMin=" + minVersionVnf + + " VersionMax:" + maxVersionVnf + " NOT supported on Cloud: " + cloudSiteOpt.get() + .getId() + " with AIC_Version:" + cloudSiteOpt.get().getAic_version(); LOGGER.error(MessageEnum.RA_CONFIG_EXC, error, "OpenStack", "", - MsoLogger.ErrorCode.BusinessProcesssError, "Exception - setVersion"); + MsoLogger.ErrorCode.BusinessProcesssError, "Exception - setVersion"); LOGGER.debug(error); throw new VnfException(error, MsoExceptionCategory.USERDATA); } } // let this error out downstream to avoid introducing uncertainty at this stage } else { - LOGGER.debug("cloudConfig is NULL - cannot check cloud site version"); + LOGGER.debug("cloudConfig is NULL - cannot check cloud site version"); } - } else { - LOGGER.debug("AIC Version not set in VNF_Resource - do not error for now - not checked."); + } else { + LOGGER.debug("AIC Version not set in VNF_Resource - do not error for now - not checked."); } - // End Version check 1607 - - String heatTemplateArtifactUuid = null; - String heatEnvironmentArtifactUuid = null; + // End Version check 1607 + + String heatTemplateArtifactUuid = null; + String heatEnvironmentArtifactUuid = null; HeatTemplate heatTemplate = null; if (isVolumeRequest) { @@ -1731,14 +1747,14 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } if (heatTemplateArtifactUuid == null) { String error = - "UpdateVF: No Heat Template ID defined in catalog database for " + vfModuleType + ", reqType=" - + requestTypeString; + "UpdateVF: No Heat Template ID defined in catalog database for " + vfModuleType + ", reqType=" + + requestTypeString; LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Template ID", vfModuleType, "OpenStack", "", - MsoLogger.ErrorCode.DataError, error); + MsoLogger.ErrorCode.DataError, error); LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, - error); + error); alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, - MsoAlarmLogger.CRITICAL, error); + MsoAlarmLogger.CRITICAL, error); throw new VnfException(error, MsoExceptionCategory.INTERNAL); } else { heatTemplate = db.getHeatTemplateByArtifactUuidRegularQuery(heatTemplateArtifactUuid); @@ -1746,18 +1762,18 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { if (heatTemplate == null) { String error = "Update VNF: undefined Heat Template. VF=" - + vfModuleType + ", heat template id = " + heatTemplateArtifactUuid; + + vfModuleType + ", heat template id = " + heatTemplateArtifactUuid; LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, - "Heat Template ID", - String.valueOf(heatTemplateArtifactUuid), "OpenStack", "", MsoLogger.ErrorCode.DataError, error); + "Heat Template ID", + String.valueOf(heatTemplateArtifactUuid), "OpenStack", "", MsoLogger.ErrorCode.DataError, error); LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, - error); + error); // Alarm on this error, configuration must be fixed alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, - MsoAlarmLogger.CRITICAL, error); + MsoAlarmLogger.CRITICAL, error); - throw new VnfException(error, MsoExceptionCategory.INTERNAL); - } + throw new VnfException(error, MsoExceptionCategory.INTERNAL); + } LOGGER.debug("Got HEAT Template from DB: " + heatTemplate.toString()); @@ -1771,13 +1787,13 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { if (heatEnvironment == null) { String error = "Update VNF: undefined Heat Environment. VF=" + vfModuleType - + ", Environment ID=" - + heatEnvironmentArtifactUuid; + + ", Environment ID=" + + heatEnvironmentArtifactUuid; LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Environment ID", - String.valueOf(heatEnvironmentArtifactUuid), "OpenStack", "", MsoLogger.ErrorCode.DataError, - error); + String.valueOf(heatEnvironmentArtifactUuid), "OpenStack", "", MsoLogger.ErrorCode.DataError, + error); LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, - error); + error); // Alarm on this error, configuration must be fixed alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error); @@ -1785,7 +1801,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } else { LOGGER.debug("Got Heat Environment from DB: " + heatEnvironment.toString()); heatEnvironmentString = heatEnvironment - .getEnvironment(); //this.parseEnvironment (heatEnvironment.getEnvironment ()); + .getEnvironment(); //this.parseEnvironment (heatEnvironment.getEnvironment ()); LOGGER.debug("After parsing: " + heatEnvironmentString); } } else { @@ -1793,7 +1809,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { } LOGGER.debug("In MsoVnfAdapterImpl, about to call db.getNestedTemplates avec templateId=" - + heatTemplate.getArtifactUuid()); + + heatTemplate.getArtifactUuid()); Map<String, Object> nestedTemplates = db.getNestedTemplates(heatTemplate.getArtifactUuid()); Map<String, Object> nestedTemplatesChecked = new HashMap<>(); if (nestedTemplates != null) { @@ -1815,7 +1831,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // Also add the files: for any get_files associated with this VfModule // *if* there are any LOGGER.debug("In MsoVnfAdapterImpl.updateVfModule, about to call db.getHeatFiles avec vfModuleId=" - + vf.getModelUUID()); + + vf.getModelUUID()); Map<String, HeatFiles> heatFiles = null; // Map <String, HeatFiles> heatFiles = db.getHeatFiles (vnf.getId ()); @@ -1825,21 +1841,21 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { boolean addGetFilesOnVolumeReq = false; try { String propertyString = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_VNF_ADAPTER) - .getProperty(MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ, null); + .getProperty(MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ, null); if ("true".equalsIgnoreCase(propertyString) || "y".equalsIgnoreCase(propertyString)) { addGetFilesOnVolumeReq = true; LOGGER.debug("AddGetFilesOnVolumeReq - setting to true! " + propertyString); } } catch (Exception e) { LOGGER.debug("An error occured trying to get property " + MsoVnfAdapterImpl.ADD_GET_FILES_ON_VOLUME_REQ - + " - default to false", e); + + " - default to false", e); } if (!isVolumeRequest || addGetFilesOnVolumeReq) { LOGGER.debug( - "In MsoVnfAdapterImpl updateVfModule, about to call db.getHeatFilesForVfModule avec vfModuleId=" - + vf.getModelUUID()); + "In MsoVnfAdapterImpl updateVfModule, about to call db.getHeatFilesForVfModule avec vfModuleId=" + + vf.getModelUUID()); - heatFiles = db.getHeatFilesForVfModule(vf.getModelUUID()); + heatFiles = db.getHeatFilesForVfModule(vf.getModelUUID()); if (heatFiles != null) { // add these to stack - to be done in createStack // here, we will map them to Map<String, Object> from Map<String, HeatFiles> @@ -1853,13 +1869,13 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // This means there was an invalid entry in VF_MODULE_TO_HEAT_FILES table - the heat file it pointed to could not be found. String heatFileId = heatFileName.substring(heatFileName.lastIndexOf("|") + 1); String error = "Create: No HEAT_FILES entry in catalog database for " + vfModuleType - + " at HEAT_FILES index=" + heatFileId; + + " at HEAT_FILES index=" + heatFileId; LOGGER.debug(error); LOGGER - .error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "HEAT_FILES entry not found at " + heatFileId, - vfModuleType, "OpenStack", "", MsoLogger.ErrorCode.DataError, error); + .error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "HEAT_FILES entry not found at " + heatFileId, + vfModuleType, "OpenStack", "", MsoLogger.ErrorCode.DataError, error); LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.DataNotFound, error); + MsoLogger.ResponseCode.DataNotFound, error); // Alarm on this error, configuration must be fixed alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error); throw new VnfException(error, MsoExceptionCategory.INTERNAL); @@ -1887,11 +1903,11 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { boolean checkRequiredParameters = true; try { String propertyString = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_VNF_ADAPTER) - .getProperty(MsoVnfAdapterImpl.CHECK_REQD_PARAMS, null); + .getProperty(MsoVnfAdapterImpl.CHECK_REQD_PARAMS, null); if ("false".equalsIgnoreCase(propertyString) || "n".equalsIgnoreCase(propertyString)) { checkRequiredParameters = false; LOGGER.debug("CheckRequiredParameters is FALSE. Will still check but then skip blocking..." - + MsoVnfAdapterImpl.CHECK_REQD_PARAMS); + + MsoVnfAdapterImpl.CHECK_REQD_PARAMS); } } catch (Exception e) { // No problem - default is true @@ -1909,17 +1925,17 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { mhee = new MsoHeatEnvironmentEntry(sb); StringBuilder sb2 = new StringBuilder("\nHeat Template Parameters:\n"); for (HeatTemplateParam parm : heatTemplate.getParameters()) { - sb2.append("\t" + parm.getParamName() + ", required=" + parm.isRequired()); + sb2.append("\t" + parm.getParamName() + ", required=" + parm.isRequired()); } if (!mhee.isValid()) { - sb2.append("Environment says it's not valid! " + mhee.getErrorString()); + sb2.append("Environment says it's not valid! " + mhee.getErrorString()); } else { - sb2.append("\nEnvironment:"); + sb2.append("\nEnvironment:"); sb2.append(mhee); } LOGGER.debug(sb2.toString()); } else { - LOGGER.debug("NO ENVIRONMENT for this entry"); + LOGGER.debug("NO ENVIRONMENT for this entry"); } // New for 1607 - support params of json type @@ -1928,14 +1944,14 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { for (HeatTemplateParam parm : heatTemplate.getParameters()) { LOGGER.debug("Parameter:'" + parm.getParamName() - + "', isRequired=" - + parm.isRequired() - + ", alias=" - + parm.getParamAlias()); + + "', isRequired=" + + parm.isRequired() + + ", alias=" + + parm.getParamAlias()); // handle json String parameterType = parm.getParamType(); if (parameterType == null || "".equals(parameterType.trim())) { - parameterType = "String"; + parameterType = "String"; } JsonNode jsonNode = null; if ("json".equalsIgnoreCase(parameterType) && inputs != null) { @@ -1998,10 +2014,10 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { String alias = parm.getParamAlias(); String value = inputs.get(alias); LOGGER.debug("*Found an Alias: paramName=" + realParamName - + ",alias=" - + alias - + ",value=" - + value); + + ",alias=" + + alias + + ",value=" + + value); inputs.remove(alias); inputs.put(realParamName, value); LOGGER.debug(alias + " entry removed from inputs, added back using " + realParamName); @@ -2010,7 +2026,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { else if (mhee != null && mhee.containsParameter(parm.getParamName())) { LOGGER.debug("Required parameter " + parm.getParamName() - + " appears to be in environment - do not count as missing"); + + " appears to be in environment - do not count as missing"); } else { LOGGER.debug("adding to missing parameters list: " + parm.getParamName()); if (missingParams == null) { @@ -2027,9 +2043,9 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { if (checkRequiredParameters) { String error = "Update VNF: Missing Required inputs: " + missingParams; LOGGER.error(MessageEnum.RA_MISSING_PARAM, missingParams.toString(), "OpenStack", "", - MsoLogger.ErrorCode.DataError, error); + MsoLogger.ErrorCode.DataError, error); LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, - error); + error); throw new VnfException(error, MsoExceptionCategory.USERDATA); } else { LOGGER.debug("found missing parameters - but checkRequiredParameters is false - will not block"); @@ -2052,23 +2068,23 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { extraParams.removeAll(paramList); if (!extraParams.isEmpty()) { LOGGER.warn(MessageEnum.RA_VNF_EXTRA_PARAM, vnfType, extraParams.toString(), "OpenStack", "", - MsoLogger.ErrorCode.DataError, "Extra params"); + MsoLogger.ErrorCode.DataError, "Extra params"); inputs.keySet().removeAll(extraParams); } } // 1607 - when we get here - we have clean inputs. Create inputsTwo in case we have json Map<String, Object> inputsTwo = null; if (hasJson && jsonParams.size() > 0) { - inputsTwo = new HashMap<>(); - for (Map.Entry<String, String> entry : inputs.entrySet()) { - String keyParamName = entry.getKey(); - String value = entry.getValue(); - if (jsonParams.containsKey(keyParamName)) { - inputsTwo.put(keyParamName, jsonParams.get(keyParamName)); - } else { - inputsTwo.put(keyParamName, value); - } - } + inputsTwo = new HashMap<>(); + for (Map.Entry<String, String> entry : inputs.entrySet()) { + String keyParamName = entry.getKey(); + String value = entry.getValue(); + if (jsonParams.containsKey(keyParamName)) { + inputsTwo.put(keyParamName, jsonParams.get(keyParamName)); + } else { + inputsTwo.put(keyParamName, value); + } + } } // "Fix" the template if it has CR/LF (getting this from Oracle) @@ -2082,45 +2098,45 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { try { if (!hasJson) { heatStack = heatU.updateStack(cloudSiteId, - tenantId, - vfModuleName, - template, - copyStringInputs(inputs), - true, - heatTemplate.getTimeoutMinutes(), - newEnvironmentString, - //heatEnvironmentString, - nestedTemplatesChecked, - heatFilesObjects); + tenantId, + vfModuleName, + template, + copyStringInputs(inputs), + true, + heatTemplate.getTimeoutMinutes(), + newEnvironmentString, + //heatEnvironmentString, + nestedTemplatesChecked, + heatFilesObjects); LOGGER.recordMetricEvent(updateStackStarttime, MsoLogger.StatusCode.COMPLETE, - MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", - "UpdateStack", null); + MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", + "UpdateStack", null); } else { heatStack = heatU.updateStack(cloudSiteId, - tenantId, - vfModuleName, - template, - inputsTwo, - true, - heatTemplate.getTimeoutMinutes(), - newEnvironmentString, - //heatEnvironmentString, - nestedTemplatesChecked, - heatFilesObjects); + tenantId, + vfModuleName, + template, + inputsTwo, + true, + heatTemplate.getTimeoutMinutes(), + newEnvironmentString, + //heatEnvironmentString, + nestedTemplatesChecked, + heatFilesObjects); LOGGER.recordMetricEvent(updateStackStarttime, MsoLogger.StatusCode.COMPLETE, - MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", - "UpdateStack", null); - } + MsoLogger.ResponseCode.Suc, "Successfully receive response from Open Stack", "OpenStack", + "UpdateStack", null); + } } catch (MsoException me) { me.addContext("UpdateVFModule"); String error = "Update VFModule " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + me; LOGGER.recordMetricEvent(updateStackStarttime, MsoLogger.StatusCode.ERROR, - MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "UpdateStack", null); + MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "UpdateStack", null); LOGGER.error(MessageEnum.RA_UPDATE_VNF_ERR, vfModuleType, cloudSiteId, tenantId, "OpenStack", "", - MsoLogger.ErrorCode.DataError, "Exception - " + error, me); + MsoLogger.ErrorCode.DataError, "Exception - " + error, me); LOGGER - .recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, - error); + .recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, + error); throw new VnfException(me); } } @@ -2128,30 +2144,30 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter { // Reach this point if updateStack is successful. // Populate remaining rollback info and response parameters. - vfRollback.setVnfId (heatStack.getCanonicalName ()); - vfRollback.setVnfCreated (true); + vfRollback.setVnfId(heatStack.getCanonicalName()); + vfRollback.setVnfCreated(true); - outputs.value = copyStringOutputs (heatStack.getOutputs ()); + outputs.value = copyStringOutputs(heatStack.getOutputs()); rollback.value = vfRollback; - LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully update VF Module"); + LOGGER.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully update VF Module"); } private String getVfModuleNameFromModuleStackId(String vfModuleStackId) { - // expected format of vfModuleStackId is "MSOTEST51-vSAMP3_base_module-0/1fc1f86c-7b35-447f-99a6-c23ec176ae24" - // before the "/" is the vfModuleName and after the "/" is the heat stack id in Openstack - if (vfModuleStackId == null) - return null; - int index = vfModuleStackId.lastIndexOf('/'); - if (index <= 0) - return null; - String vfModuleName = null; - try { - vfModuleName = vfModuleStackId.substring(0, index); - } catch (Exception e) { - LOGGER.debug("Exception", e); - vfModuleName = null; - } - return vfModuleName; + // expected format of vfModuleStackId is "MSOTEST51-vSAMP3_base_module-0/1fc1f86c-7b35-447f-99a6-c23ec176ae24" + // before the "/" is the vfModuleName and after the "/" is the heat stack id in Openstack + if (vfModuleStackId == null) + return null; + int index = vfModuleStackId.lastIndexOf('/'); + if (index <= 0) + return null; + String vfModuleName = null; + try { + vfModuleName = vfModuleStackId.substring(0, index); + } catch (Exception e) { + LOGGER.debug("Exception", e); + vfModuleName = null; + } + return vfModuleName; } } diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfPluginAdapterImpl.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfPluginAdapterImpl.java new file mode 100644 index 0000000000..0a0747a98d --- /dev/null +++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/MsoVnfPluginAdapterImpl.java @@ -0,0 +1,1239 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 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========================================================= + */ + +/** + * This VNF Adapter implementation is based on the VDU Plugin model. It assumes that each + * VF Module definition in the MSO catalog is expressed via a set of template and/or file + * artifacts that are appropriate for some specific sub-orchestrator that provides an + * implementation of the VduPlugin interface. This adapter handles all of the common + * VF Module logic, including: + * - catalog lookups for artifact retrieval + * - parameter filtering and validation + * - base and volume module queries + * - rollback logic + * - logging and error handling + * + * Then based on the orchestration mode of the VNF, it will invoke different VDU plug-ins + * to perform the low level instantiations, deletions, and queries. At this time, the + * set of available plug-ins is hard-coded, though in the future a dynamic selection + * is expected (e.g. via a service-provider interface). + */ +package org.openecomp.mso.adapters.vnf; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +import javax.jws.WebService; +import javax.xml.ws.Holder; + +import org.openecomp.mso.adapters.vdu.CloudInfo; +import org.openecomp.mso.adapters.vdu.VduException; +import org.openecomp.mso.adapters.vdu.VduInstance; +import org.openecomp.mso.adapters.vdu.VduModelInfo; +import org.openecomp.mso.adapters.vdu.VduPlugin; +import org.openecomp.mso.adapters.vdu.VduStateType; +import org.openecomp.mso.adapters.vdu.VduStatus; +import org.openecomp.mso.adapters.vdu.mapper.VfModuleCustomizationToVduMapper; +import org.openecomp.mso.adapters.vnf.exceptions.VnfAlreadyExists; +import org.openecomp.mso.adapters.vnf.exceptions.VnfException; +import org.openecomp.mso.cloud.CloudConfig; +import org.openecomp.mso.cloud.CloudConfigFactory; +import org.openecomp.mso.cloud.CloudSite; +import org.openecomp.mso.cloudify.utils.MsoCloudifyUtils; +import org.openecomp.mso.db.catalog.CatalogDatabase; +import org.openecomp.mso.db.catalog.beans.HeatEnvironment; +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.VnfRollback; +import org.openecomp.mso.openstack.beans.VnfStatus; +import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; +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.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 MsoVnfPluginAdapterImpl implements MsoVnfAdapter { + + CloudConfigFactory cloudConfigFactory = new CloudConfigFactory(); + protected CloudConfig cloudConfig = cloudConfigFactory.getCloudConfig(); + protected MsoHeatUtils heatUtils; + protected VfModuleCustomizationToVduMapper vduMapper; + protected MsoCloudifyUtils cloudifyUtils; + + MsoPropertiesFactory msoPropertiesFactory=new MsoPropertiesFactory(); + + private static final String MSO_PROP_VNF_ADAPTER = "MSO_PROP_VNF_ADAPTER"; + private static final String MSO_CONFIGURATION_ERROR = "MsoConfigurationError"; + 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 ObjectMapper JSON_MAPPER = new ObjectMapper(); + + /** + * 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 Plugin Adapter"); + } + + /** + * DO NOT use that constructor to instantiate this class, the msoPropertiesfactory will be NULL. + * @see MsoVnfPluginAdapterImpl#MsoVnfAdapterImpl(MsoPropertiesFactory, CloudConfigFactory) + */ + public MsoVnfPluginAdapterImpl() { + + } + + /** + * This constructor MUST be used if this class is called with the new operator. + * @param msoPropFactory + */ + public MsoVnfPluginAdapterImpl(MsoPropertiesFactory msoPropFactory, CloudConfigFactory cloudConfigFact) { + this.msoPropertiesFactory = msoPropFactory; + this.cloudConfigFactory = cloudConfigFact; + heatUtils = new MsoHeatUtils(MSO_PROP_VNF_ADAPTER, msoPropertiesFactory, cloudConfigFactory); + vduMapper = new VfModuleCustomizationToVduMapper(); + cloudifyUtils = new MsoCloudifyUtils (MSO_PROP_VNF_ADAPTER, msoPropertiesFactory,cloudConfigFactory); + } + + /** + * This is the "Create VNF" web service implementation. + * This function is now unsupported and will return an error. + * + */ + @Override + public void createVnf (String cloudSiteId, + String tenantId, + String vnfType, + String vnfVersion, + String vnfName, + String requestType, + String volumeGroupHeatStackId, + Map <String, String> inputs, + Boolean failIfExists, + Boolean backout, + MsoRequest msoRequest, + Holder <String> vnfId, + Holder <Map <String, String>> outputs, + Holder <VnfRollback> rollback) + throws VnfException + { + // This operation is no longer supported at the VNF level. The adapter is only called to deploy modules. + LOGGER.debug ("CreateVNF command attempted but not supported"); + throw new VnfException ("CreateVNF: Unsupported command", MsoExceptionCategory.USERDATA); + } + + /** + * This is the "Update VNF" web service implementation. + * This function is now unsupported and will return an error. + * + */ + @Override + public void updateVnf (String cloudSiteId, + String tenantId, + String vnfType, + String vnfVersion, + String vnfName, + String requestType, + String volumeGroupHeatStackId, + Map <String, String> inputs, + MsoRequest msoRequest, + Holder <Map <String, String>> outputs, + Holder <VnfRollback> rollback) + throws VnfException + { + // This operation is no longer supported at the VNF level. The adapter is only called to deploy modules. + LOGGER.debug ("UpdateVNF command attempted but not supported"); + throw new VnfException ("UpdateVNF: Unsupported command", MsoExceptionCategory.USERDATA); + } + + /** + * This is the "Query VNF" web service implementation. + * + * This really should be QueryVfModule, but nobody ever changed it. + * + * The method returns an indicator that the VNF exists, along with its status and outputs. + * The input "vnfName" will also be reflected back as its ID. + * + * @param cloudSiteId CLLI code of the cloud site in which to query + * @param tenantId Openstack tenant identifier + * @param vnfNameOrId VNF Name or ID to query + * @param msoRequest Request tracking information for logs + * @param vnfExists Flag reporting the result of the query + * @param vnfId Holder for output VNF ID + * @param outputs Holder for Map of outputs from the deployed VF Module (assigned IPs, etc) + */ + @Override + public void queryVnf (String cloudSiteId, + String tenantId, + String vnfNameOrId, + MsoRequest msoRequest, + Holder <Boolean> vnfExists, + Holder <String> vnfId, + Holder <VnfStatus> status, + Holder <Map <String, String>> outputs) + throws VnfException + { + MsoLogger.setLogContext (msoRequest); + MsoLogger.setServiceName ("QueryVnf"); + LOGGER.debug ("Querying VNF " + vnfNameOrId + " in " + cloudSiteId + "/" + tenantId); + + // Will capture execution time for metrics + long startTime = System.currentTimeMillis (); + long subStartTime = System.currentTimeMillis (); + + VduInstance vduInstance = null; + CloudInfo cloudInfo = new CloudInfo(cloudSiteId, tenantId, null); + + VduPlugin vduPlugin = getVduPlugin(cloudSiteId); + + try { + vduInstance = vduPlugin.queryVdu(cloudInfo, vnfNameOrId); + LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received VDU Query response", "VDU", "QueryVDU", vnfNameOrId); + } + catch (VduException e) { + // Failed to query the VDU due to a plugin exception. + e.addContext ("QueryVNF"); + String error = "Query VNF (VDU): " + vnfNameOrId + " in " + cloudSiteId + "/" + tenantId + ": " + e; + LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "QueryVNF", vnfNameOrId); + LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vnfNameOrId, cloudSiteId, tenantId, "VDU", "QueryVNF", MsoLogger.ErrorCode.DataError, "Exception - queryVDU", e); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException (e); + } + + if (vduInstance != null && vduInstance.getStatus().getState() != VduStateType.NOTFOUND) { + vnfExists.value = Boolean.TRUE; + status.value = vduStatusToVnfStatus(vduInstance); + vnfId.value = vduInstance.getVduInstanceId(); + outputs.value = copyStringOutputs (vduInstance.getOutputs ()); + + LOGGER.debug ("VNF " + vnfNameOrId + " found, ID = " + vnfId.value); + } + else { + vnfExists.value = Boolean.FALSE; + status.value = VnfStatus.NOTFOUND; + vnfId.value = null; + outputs.value = new HashMap <String, String> (); // Return as an empty map + + LOGGER.debug ("VNF " + vnfNameOrId + " not found"); + } + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully query VNF"); + return; + } + + + /** + * This is the "Delete VNF" web service implementation. + * This function is now unsupported and will return an error. + * + */ + @Override + public void deleteVnf (String cloudSiteId, + String tenantId, + String vnfName, + MsoRequest msoRequest) throws VnfException { + MsoLogger.setLogContext (msoRequest); + MsoLogger.setServiceName ("DeleteVnf"); + + // This operation is no longer supported at the VNF level. The adapter is only called to deploy modules. + LOGGER.debug ("DeleteVNF command attempted but not supported"); + throw new VnfException ("DeleteVNF: Unsupported command", MsoExceptionCategory.USERDATA); + } + + /** + * This web service endpoint will rollback a previous Create VNF operation. + * A rollback object is returned to the client in a successful creation + * response. The client can pass that object as-is back to the rollbackVnf + * operation to undo the creation. + * + * TODO: This should be rollbackVfModule and/or rollbackVolumeGroup, + * but APIs were apparently never updated. + */ + @Override + public void rollbackVnf (VnfRollback rollback) throws VnfException { + long startTime = System.currentTimeMillis (); + MsoLogger.setServiceName ("RollbackVnf"); + // rollback may be null (e.g. if stack already existed when Create was called) + if (rollback == null) { + LOGGER.info (MessageEnum.RA_ROLLBACK_NULL, "OpenStack", "rollbackVnf"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Rollback request content is null"); + return; + } + + // Don't rollback if nothing was done originally + if (!rollback.getVnfCreated()) { + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Rollback VF Module - nothing to roll back"); + return; + } + + // Get the elements of the VnfRollback object for easier access + String cloudSiteId = rollback.getCloudSiteId (); + String tenantId = rollback.getTenantId (); + CloudInfo cloudInfo = new CloudInfo (cloudSiteId, tenantId, null); + + String vfModuleId = rollback.getVfModuleStackId (); + + MsoLogger.setLogContext (rollback.getMsoRequest()); + + LOGGER.debug ("Rolling Back VF Module " + vfModuleId + " in " + cloudSiteId + "/" + tenantId); + + VduInstance vduInstance = null; + + // Use the VduPlugin to delete the VF Module. + VduPlugin vduPlugin = getVduPlugin(cloudSiteId); + + long subStartTime = System.currentTimeMillis (); + try { + // TODO: Get a reasonable timeout. Use a global property, or store the creation timeout in rollback object and use that. + vduInstance = vduPlugin.deleteVdu(cloudInfo, vfModuleId, 5); + + LOGGER.debug("Rolled back VDU instantiation: " + vduInstance.getVduInstanceId()); + LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from VDU Plugin", "VDU", "DeleteVdu", null); + } + catch (VduException ve) { + // Failed to rollback the VF Module due to a plugin exception. + // Convert to a generic VnfException + ve.addContext ("RollbackVFModule"); + String error = "Rollback VF Module: " + vfModuleId + " in " + cloudSiteId + "/" + tenantId + ": " + ve; + LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "DeleteVdu", null); + LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vfModuleId, cloudSiteId, tenantId, "VDU", "DeleteVdu", MsoLogger.ErrorCode.DataError, "Exception - DeleteVdu", ve); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException (ve); + } + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully roll back VF Module"); + return; + } + + + private VnfStatus vduStatusToVnfStatus (VduInstance vdu) { + // Determine the status based on last action & status + // DeploymentInfo object should be enhanced to report a better status internally. + VduStatus vduStatus = vdu.getStatus(); + VduStateType status = vduStatus.getState(); + + if (status == null) { + return VnfStatus.UNKNOWN; + } + else if (status == VduStateType.NOTFOUND) { + return VnfStatus.NOTFOUND; + } + else if (status == VduStateType.INSTANTIATED) { + return VnfStatus.ACTIVE; + } + else if (status == VduStateType.FAILED) { + return VnfStatus.FAILED; + } + + return VnfStatus.UNKNOWN; + } + + /* + * Normalize an input value to an Object, based on the target parameter type. + * If the type is not recognized, it will just be returned unchanged (as a string). + */ + private Object convertInputValue (String inputValue, HeatTemplateParam templateParam) + { + String type = templateParam.getParamType(); + LOGGER.debug("Parameter: " + templateParam.getParamName() + " is of type " + type); + + if (type.equalsIgnoreCase("number")) { + try { + return Integer.valueOf(inputValue); + } + catch (Exception e) { + LOGGER.debug("Unable to convert " + inputValue + " to an integer!"); + return null; + } + } else if (type.equalsIgnoreCase("json")) { + try { + JsonNode jsonNode = new ObjectMapper().readTree(inputValue); + return jsonNode; + } + catch (Exception e) { + LOGGER.debug("Unable to convert " + inputValue + " to a JsonNode!"); + return null; + } + } else if (type.equalsIgnoreCase("boolean")) { + return new Boolean(inputValue); + } + + // Nothing else matched. Return the original string + return inputValue; + } + + private Map <String, String> copyStringOutputs (Map <String, Object> stackOutputs) { + Map <String, String> stringOutputs = new HashMap <> (); + for (String key : stackOutputs.keySet ()) { + if (stackOutputs.get (key) instanceof String) { + stringOutputs.put (key, (String) stackOutputs.get (key)); + } else if (stackOutputs.get(key) instanceof Integer) { + try { + String str = "" + stackOutputs.get(key); + stringOutputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("Unable to add " + key + " to outputs"); + } + } else if (stackOutputs.get(key) instanceof JsonNode) { + try { + String str = this.convertNode((JsonNode) stackOutputs.get(key)); + stringOutputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("Unable to add " + key + " to outputs - exception converting JsonNode"); + } + } else if (stackOutputs.get(key) instanceof java.util.LinkedHashMap) { + try { + String str = JSON_MAPPER.writeValueAsString(stackOutputs.get(key)); + stringOutputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("Unable to add " + key + " to outputs - exception converting LinkedHashMap"); + } + } else { + try { + String str = stackOutputs.get(key).toString(); + stringOutputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("Unable to add " + key + " to outputs - unable to call .toString() " + e.getMessage()); + } + } + } + return stringOutputs; + } + + + private void sendMapToDebug(Map<String, Object> inputs, String optionalName) { + int i = 0; + StringBuilder sb = new StringBuilder(optionalName == null ? "\ninputs" : "\n" + optionalName); + if (inputs == null) { + sb.append("\tNULL"); + } + else if (inputs.size() < 1) { + sb.append("\tEMPTY"); + } else { + for (String str : inputs.keySet()) { + String outputString; + try { + outputString = inputs.get(str).toString(); + } catch (Exception e) { + outputString = "Unable to call toString() on the value for " + str; + } + sb.append("\t\nitem " + i++ + ": '" + str + "'='" + outputString + "'"); + } + } + LOGGER.debug(sb.toString()); + return; + } + + private void sendMapToDebug(Map<String, String> inputs) { + int i = 0; + StringBuilder sb = new StringBuilder("inputs:"); + if (inputs == null) { + sb.append("\tNULL"); + } + else if (inputs.size() < 1) { + sb.append("\tEMPTY"); + } else { + for (String str : inputs.keySet()) { + sb.append("\titem " + i++ + ": " + str + "=" + inputs.get(str)); + } + } + LOGGER.debug(sb.toString()); + return; + } + + private String convertNode(final JsonNode node) { + try { + final Object obj = JSON_MAPPER.treeToValue(node, Object.class); + final String json = JSON_MAPPER.writeValueAsString(obj); + return json; + } catch (JsonParseException jpe) { + LOGGER.debug("Error converting json to string " + jpe.getMessage()); + } catch (Exception e) { + LOGGER.debug("Error converting json to string " + e.getMessage()); + } + return "[Error converting json to string]"; + } + + private Map<String, String> convertMapStringObjectToStringString(Map<String, Object> objectMap) { + if (objectMap == null) { + return null; + } + Map<String, String> stringMap = new HashMap<>(); + for (String key : objectMap.keySet()) { + if (!stringMap.containsKey(key)) { + Object obj = objectMap.get(key); + if (obj instanceof String) { + stringMap.put(key, (String) objectMap.get(key)); + } else if (obj instanceof JsonNode ){ + // This is a bit of mess - but I think it's the least impacting + // let's convert it BACK to a string - then it will get converted back later + try { + String str = this.convertNode((JsonNode) obj); + stringMap.put(key, str); + } catch (Exception e) { + LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for JsonNode "+ key); + //okay in this instance - only string values (fqdn) are expected to be needed + } + } else if (obj instanceof java.util.LinkedHashMap) { + LOGGER.debug("LinkedHashMap - this is showing up as a LinkedHashMap instead of JsonNode"); + try { + String str = JSON_MAPPER.writeValueAsString(obj); + stringMap.put(key, str); + } catch (Exception e) { + LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for LinkedHashMap "+ key); + } + } else if (obj instanceof Integer) { + try { + String str = "" + obj; + stringMap.put(key, str); + } catch (Exception e) { + LOGGER.debug("DANGER WILL ROBINSON: unable to convert value for Integer "+ key); + } + } else { + try { + String str = obj.toString(); + stringMap.put(key, str); + } catch (Exception e) { + LOGGER.debug("DANGER WILL ROBINSON: unable to convert value "+ key + " (" + e.getMessage() + ")"); + } + } + } + } + + return stringMap; + } + + /** + * This is the "Create VF Module" web service implementation. + * It will instantiate a new VF Module of the requested type in the specified cloud + * and tenant. The tenant must exist before this service is called. + * + * If a VF Module with the same name already exists, this can be considered a + * success or failure, depending on the value of the 'failIfExists' parameter. + * + * All VF Modules are defined in the MSO catalog. The caller must request one of + * the pre-defined module types or an error will be returned. Within the catalog, + * each VF Module references (among other things) a collection of artifacts that + * are used to deploy the required cloud resources (VMs, networks, etc.). + * + * Depending on the module templates, 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 module or an error will be thrown. + * + * The method returns the vfModuleId, a Map of 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 Module. This is useful if a VF module + * is successfully created but the orchestration fails on a subsequent step. + * + * @param cloudSiteId CLLI code of the cloud site in which to create the VNF + * @param tenantId Openstack tenant identifier + * @param vfModuleType VF Module type key, should match a VNF definition in catalog DB. + * Deprecated - should use modelCustomizationUuid + * @param vnfVersion VNF version key, should match a VNF definition in catalog DB + * Deprecated - VF Module versions also captured by modelCustomizationUuid + * @param vfModuleName Name to be assigned to the new VF Module + * @param requestType Indicates if this is a Volume Group or Module request + * @param volumeGroupId Identifier (i.e. deployment ID) for a Volume Group + * to attach to a VF Module + * @param baseVfModuleId Identifier (i.e. deployment ID) of the Base Module if + * this is an Add-on module + * @param modelCustomizationUuid Unique ID for the VF Module's model. Replaces + * the use of vfModuleType. + * @param inputs Map of key=value inputs for VNF stack creation + * @param failIfExists Flag whether already existing VNF should be considered + * @param backout Flag whether to suppress automatic backout (for testing) + * @param msoRequest Request tracking information for logs + * @param vnfId Holder for output VF Module instance ID in the cloud + * @param outputs Holder for Map of VNF outputs from Deployment (assigned IPs, etc) + * @param rollback Holder for returning VnfRollback object + */ + public void createVfModule(String cloudSiteId, + String tenantId, + String vfModuleType, + String vnfVersion, + String vfModuleName, + String requestType, + String volumeGroupId, + String baseVfModuleId, + String modelCustomizationUuid, + Map <String, String> inputs, + Boolean failIfExists, + Boolean backout, + MsoRequest msoRequest, + Holder <String> vnfId, + Holder <Map <String, String>> outputs, + Holder <VnfRollback> rollback) + throws VnfException + { + // Will capture execution time for metrics + long startTime = System.currentTimeMillis (); + + MsoLogger.setLogContext (msoRequest); + MsoLogger.setServiceName ("CreateVfModule"); + + // Require a model customization ID. Every VF Module definition must have one. + if (modelCustomizationUuid == null || modelCustomizationUuid.isEmpty()) { + LOGGER.debug("Missing required input: modelCustomizationUuid"); + String error = "Create vfModule error: Missing required input: modelCustomizationUuid"; + LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, + "VF Module ModelCustomizationUuid", "null", "VDU", "", MsoLogger.ErrorCode.DataError, "Create VF Module: Missing required input: modelCustomizationUuid"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + throw new VnfException(error, MsoExceptionCategory.USERDATA); + } + + // Clean up some inputs to make comparisons easier + if (requestType == null) + requestType = ""; + + if ("".equals(volumeGroupId) || "null".equals(volumeGroupId)) + volumeGroupId = null; + + if ("".equals(baseVfModuleId) || "null".equals(baseVfModuleId)) + baseVfModuleId = null; + + if (inputs == null) { + // Create an empty set of inputs + inputs = new HashMap<String,String>(); + LOGGER.debug("inputs == null - setting to empty"); + } else { + this.sendMapToDebug(inputs); + } + + // Check if this is for a "Volume" module + boolean isVolumeRequest = false; + if (requestType.startsWith("VOLUME")) { + isVolumeRequest = true; + } + + LOGGER.debug("requestType = " + requestType + ", volumeGroupStackId = " + volumeGroupId + ", baseStackId = " + baseVfModuleId); + + // Build a default rollback object (no actions performed) + VnfRollback vfRollback = new VnfRollback(); + vfRollback.setCloudSiteId(cloudSiteId); + vfRollback.setTenantId(tenantId); + vfRollback.setMsoRequest(msoRequest); + vfRollback.setRequestType(requestType); + vfRollback.setIsBase(false); // Until we know better + vfRollback.setVolumeGroupHeatStackId(volumeGroupId); + vfRollback.setBaseGroupHeatStackId(baseVfModuleId); + vfRollback.setModelCustomizationUuid(modelCustomizationUuid); + vfRollback.setMode("CFY"); + + rollback.value = vfRollback; // Default rollback - no updates performed + + // Get the VNF/VF Module definition from the Catalog DB first. + // There are three relevant records: VfModule, VfModuleCustomization, VnfResource + + CatalogDatabase db = CatalogDatabase.getInstance(); + VfModule vfModule = null; + VnfResource vnfResource = null; + VfModuleCustomization vfModuleCust = null; + + try { + vfModuleCust = db.getVfModuleCustomizationByModelCustomizationId(modelCustomizationUuid); + + if (vfModuleCust == null) { + String error = "Create vfModule error: Unable to find vfModuleCust with modelCustomizationUuid=" + modelCustomizationUuid; + LOGGER.debug(error); + LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, + "VF Module ModelCustomizationUuid", modelCustomizationUuid, "CatalogDb", "", MsoLogger.ErrorCode.DataError, error); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + throw new VnfException(error, MsoExceptionCategory.USERDATA); + } else { + LOGGER.debug("Found vfModuleCust entry " + vfModuleCust.toString()); + } + + // Get the vfModule and vnfResource records + vfModule = vfModuleCust.getVfModule(); + vnfResource = db.getVnfResourceByModelUuid(vfModule.getVnfResourceModelUUId()); + } + catch (Exception e) { + db.close (); + LOGGER.debug("unhandled exception in create VF - [Query]" + e.getMessage()); + throw new VnfException("Exception during create VF " + e.getMessage()); + } + + // Perform a version check against cloudSite + // Obtain the cloud site information where we will create the VF Module + Optional<CloudSite> cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (!cloudSite.isPresent()) { + throw new VnfException (new MsoCloudSiteNotFound (cloudSiteId)); + } + MavenLikeVersioning aicV = new MavenLikeVersioning(); + aicV.setVersion(cloudSite.get().getAic_version()); + + String vnfMin = vnfResource.getAicVersionMin(); + String vnfMax = vnfResource.getAicVersionMax(); + + if ( (vnfMin != null && !(aicV.isMoreRecentThan(vnfMin) || aicV.isTheSameVersion(vnfMin))) || + (vnfMax != null && aicV.isMoreRecentThan(vnfMax))) + { + // ERROR + String error = "VNF Resource type: " + vnfResource.getModelName() + ", ModelUuid=" + vnfResource.getModelUuid() + " VersionMin=" + vnfMin + " VersionMax:" + vnfMax + " NOT supported on Cloud: " + cloudSite.get().getId() + " with AIC_Version:" + cloudSite.get().getAic_version(); + LOGGER.error(MessageEnum.RA_CONFIG_EXC, error, "OpenStack", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - setVersion"); + LOGGER.debug(error); + throw new VnfException(error, MsoExceptionCategory.USERDATA); + } + // End Version check + + + VduInstance vduInstance = null; + CloudInfo cloudInfo = new CloudInfo (cloudSiteId, tenantId, null); + + // Use the VduPlugin. + VduPlugin vduPlugin = getVduPlugin(cloudSiteId); + + // First, look up to see if the VF already exists. + + long subStartTime1 = System.currentTimeMillis (); + try { + vduInstance = vduPlugin.queryVdu (cloudInfo, vfModuleName); + LOGGER.recordMetricEvent (subStartTime1, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from VduPlugin", "VDU", "QueryVDU", vfModuleName); + } + catch (VduException me) { + // Failed to query the VDU due to a plugin exception. + String error = "Create VF Module: Query " + vfModuleName + " in " + cloudSiteId + "/" + tenantId + ": " + me ; + LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleName, cloudSiteId, tenantId, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "Exception - queryVdu", me); + LOGGER.recordMetricEvent (subStartTime1, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "QueryVdu", vfModuleName); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + + // Convert to a generic VnfException + me.addContext ("CreateVFModule"); + throw new VnfException (me); + } + + // More precise handling/messaging if the Module already exists + if (vduInstance != null && !(vduInstance.getStatus().getState() == VduStateType.NOTFOUND)) { + VduStateType status = vduInstance.getStatus().getState(); + LOGGER.debug ("Found Existing VDU, status=" + status); + + if (status == VduStateType.INSTANTIATED) { + if (failIfExists != null && failIfExists) { + // fail - it exists + String error = "Create VF: Deployment " + vfModuleName + " already exists in " + cloudSiteId + "/" + tenantId; + LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "VF Module " + vfModuleName + " already exists"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, vduInstance.getVduInstanceId()); + } else { + // Found existing deployment and client has not requested "failIfExists". + // Populate the outputs from the existing deployment. + + vnfId.value = vduInstance.getVduInstanceId(); + outputs.value = copyStringOutputs (vduInstance.getOutputs ()); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create VF Module (found existing)"); + return; + } + } + // Check through various detailed error cases + else if (status == VduStateType.INSTANTIATING || status == VduStateType.DELETING || status == VduStateType.UPDATING) { + // fail - it's in progress - return meaningful error + String error = "Create VF: Deployment " + vfModuleName + " already exists and has status " + status.toString() + " in " + cloudSiteId + "/" + tenantId + "; please wait for it to complete, or fix manually."; + LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "VF Module " + vfModuleName + " already exists"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, vduInstance.getVduInstanceId()); + } + else if (status == VduStateType.FAILED) { + // fail - it exists and is in a FAILED state + String error = "Create VF: Deployment " + vfModuleName + " already exists and is in FAILED state in " + cloudSiteId + "/" + tenantId + "; requires manual intervention."; + LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "VF Module " + vfModuleName + " already exists and is in FAILED state"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, vduInstance.getVduInstanceId()); + } + else if (status == VduStateType.UNKNOWN) { + // fail - it exists and is in a UNKNOWN state + String error = "Create VF: Deployment " + vfModuleName + " already exists and has status " + status.toString() + " in " + cloudSiteId + "/" + tenantId + "; requires manual intervention."; + LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "VF Module " + vfModuleName + " already exists and is in " + status.toString() + " state"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, vduInstance.getVduInstanceId()); + } + else { + // Unexpected, since all known status values have been tested for + String error = "Create VF: Deployment " + vfModuleName + " already exists with unexpected status " + status.toString() + " in " + cloudSiteId + "/" + tenantId + "; requires manual intervention."; + LOGGER.error (MessageEnum.RA_VNF_ALREADY_EXIST, vfModuleName, cloudSiteId, tenantId, "VDU", "queryVdu", MsoLogger.ErrorCode.DataError, "VF Module " + vfModuleName + " already exists and is in an unknown state"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + throw new VnfAlreadyExists (vfModuleName, cloudSiteId, tenantId, vduInstance.getVduInstanceId()); + } + } + + + // Collect outputs from Base Modules and Volume Modules + Map<String, Object> baseModuleOutputs = null; + Map<String, Object> volumeGroupOutputs = null; + + // If a Volume Group was provided, query its outputs for inclusion in Module input parameters + if (volumeGroupId != null) { + long subStartTime2 = System.currentTimeMillis (); + VduInstance volumeVdu = null; + try { + volumeVdu = vduPlugin.queryVdu (cloudInfo, volumeGroupId); + LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Success response from VduPlugin", "VDU", "QueryVdu", volumeGroupId); + } + catch (VduException me) { + // Failed to query the Volume Group VDU due to a plugin exception. + String error = "Create VF Module: Query Volume Group " + volumeGroupId + " in " + cloudSiteId + "/" + tenantId + ": " + me ; + LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, volumeGroupId, cloudSiteId, tenantId, "VDU", "queryVdu(volume)", MsoLogger.ErrorCode.DataError, "Exception - queryVdu(volume)", me); + LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "QueryVdu(volume)", volumeGroupId); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + + // Convert to a generic VnfException + me.addContext ("CreateVFModule(QueryVolume)"); + throw new VnfException (me); + } + + if (volumeVdu == null || volumeVdu.getStatus().getState() == VduStateType.NOTFOUND) { + String error = "Create VFModule: Attached Volume Group DOES NOT EXIST " + volumeGroupId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ; + LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, volumeGroupId, cloudSiteId, tenantId, error, "VDU", "queryVdu(volume)", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Attached Volume Group DOES NOT EXIST"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + LOGGER.debug(error); + throw new VnfException (error, MsoExceptionCategory.USERDATA); + } else { + LOGGER.debug("Found nested volume group"); + volumeGroupOutputs = volumeVdu.getOutputs(); + this.sendMapToDebug(volumeGroupOutputs, "volumeGroupOutputs"); + } + } + + // If this is an Add-On Module, query the Base Module outputs + // Note: This will be performed whether or not the current request is for an + // Add-On Volume Group or Add-On VF Module + + if (vfModule.isBase()) { + LOGGER.debug("This is a BASE Module request"); + vfRollback.setIsBase(true); + } else { + LOGGER.debug("This is an Add-On Module request"); + + // Add-On Modules should always have a Base, but just treat as a warning if not provided. + // Add-on Volume requests may or may not specify a base. + if (!isVolumeRequest && baseVfModuleId == null) { + LOGGER.debug ("WARNING: Add-on Module request - no Base Module ID provided"); + } + + if (baseVfModuleId != null) { + long subStartTime2 = System.currentTimeMillis (); + VduInstance baseVdu = null; + try { + baseVdu = vduPlugin.queryVdu (cloudInfo, baseVfModuleId); + LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Success response from VduPlugin", "VDU", "QueryVdu(Base)", baseVfModuleId); + } + catch (MsoException me) { + // Failed to query the Base VF Module due to a Vdu Plugin exception. + String error = "Create VF Module: Query Base " + baseVfModuleId + " in " + cloudSiteId + "/" + tenantId + ": " + me ; + LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, baseVfModuleId, cloudSiteId, tenantId, "VDU", "queryVdu(Base)", MsoLogger.ErrorCode.DataError, "Exception - queryVdu(Base)", me); + LOGGER.recordMetricEvent (subStartTime2, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "QueryVdu(Base)", baseVfModuleId); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + + // Convert to a generic VnfException + me.addContext ("CreateVFModule(QueryBase)"); + throw new VnfException (me); + } + + if (baseVdu == null || baseVdu.getStatus().getState() == VduStateType.NOTFOUND) { + String error = "Create VFModule: Base Module DOES NOT EXIST " + baseVfModuleId + " in " + cloudSiteId + "/" + tenantId + " USER ERROR" ; + LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, baseVfModuleId, cloudSiteId, tenantId, error, "VDU", "queryVdu(Base)", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: Base Module DOES NOT EXIST"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.Conflict, error); + LOGGER.debug(error); + throw new VnfException (error, MsoExceptionCategory.USERDATA); + } else { + LOGGER.debug("Found base module"); + baseModuleOutputs = baseVdu.getOutputs(); + this.sendMapToDebug(baseModuleOutputs, "baseModuleOutputs"); + } + } + } + + // NOTE: For this section, heatTemplate is used for all template artifacts. + // In final implementation (post-POC), the template object would either be generic or there would + // be a separate DB Table/Object for different sub-orchestrators. + + // NOTE: The template is fixed for the VF Module. The environment is part of the customization. + + // NOTE: The template is fixed for the VF Module. The environment is part of the customization. + String heatTemplateArtifactUuid = null; + String heatEnvironmentArtifactUuid = null; + + if (isVolumeRequest) { + heatTemplateArtifactUuid = vfModule.getVolHeatTemplateArtifactUUId(); + heatEnvironmentArtifactUuid = vfModuleCust.getVolEnvironmentArtifactUuid(); + } else { + heatTemplateArtifactUuid = vfModule.getHeatTemplateArtifactUUId(); + heatEnvironmentArtifactUuid = vfModuleCust.getHeatEnvironmentArtifactUuid(); + } + + if (heatTemplateArtifactUuid == null || heatTemplateArtifactUuid.equals("")) { + String error = "Create: No Heat Template ID defined in catalog database for " + vfModuleType + ", reqType=" + requestType; + LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Template ID", vfModuleType, "Cloudify", "", MsoLogger.ErrorCode.DataError, "Create: No Heat Template ID defined in catalog database"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error); + throw new VnfException(error, MsoExceptionCategory.INTERNAL); + } + + HeatTemplate heatTemplate = db.getHeatTemplateByArtifactUuidRegularQuery(heatTemplateArtifactUuid); + + if (heatTemplate == null) { + String error = "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid; + LOGGER.error(MessageEnum.RA_VNF_UNKNOWN_PARAM, + "Heat Template ID", + String.valueOf(heatTemplateArtifactUuid), "Cloudify", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create VF/VNF: no entry found for heat template ID = " + heatTemplateArtifactUuid); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + alarmLogger.sendAlarm(MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error); + throw new VnfException(error, MsoExceptionCategory.INTERNAL); + } + LOGGER.debug("Got HEAT Template record from DB"); + + // Next get the Environment record. This is optional. + HeatEnvironment heatEnvironment = null; + if (heatEnvironmentArtifactUuid != null && !heatEnvironmentArtifactUuid.equals("")) + { + heatEnvironment = db.getHeatEnvironmentByArtifactUuid(heatEnvironmentArtifactUuid); + if (heatEnvironment == null) { + String error = "Create VFModule: undefined Heat Environment. VFModule=" + vfModuleType + + ", Environment ID=" + + heatEnvironmentArtifactUuid; + LOGGER.error (MessageEnum.RA_VNF_UNKNOWN_PARAM, "Heat Environment ID", String.valueOf(heatEnvironmentArtifactUuid), "Cloudify", "getEnvironment", MsoLogger.ErrorCode.BusinessProcesssError, "Create VFModule: undefined Heat Environment"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, error); + // Alarm on this error, configuration must be fixed + alarmLogger.sendAlarm (MSO_CONFIGURATION_ERROR, MsoAlarmLogger.CRITICAL, error); + + throw new VnfException (error, MsoExceptionCategory.INTERNAL); + } + LOGGER.debug ("Got Heat Environment from DB"); + } else { + LOGGER.debug ("no environment parameter found for this Type " + vfModuleType); + } + + + // Create the combined set of parameters from the incoming request, base-module outputs, + // volume-module outputs. Also, convert all variables to their native object types. + + HashMap<String, Object> goldenInputs = new HashMap<>(); + List<String> extraInputs = new ArrayList<>(); + + Boolean skipInputChecks = false; + + if (skipInputChecks) { + goldenInputs = new HashMap<String,Object>(); + for (String key : inputs.keySet()) { + goldenInputs.put(key, inputs.get(key)); + } + } + else { + // Build maps for the parameters (including aliases) to simplify checks + HashMap<String, HeatTemplateParam> params = new HashMap<>(); + + Set<HeatTemplateParam> paramSet = heatTemplate.getParameters(); + LOGGER.debug("paramSet has " + paramSet.size() + " entries"); + + for (HeatTemplateParam htp : paramSet) { + params.put(htp.getParamName(), htp); + + // Include aliases. + String alias = htp.getParamAlias(); + if (alias != null && !alias.equals("") && !params.containsKey(alias)) { + params.put(alias, htp); + } + } + + // First, convert all inputs to their "template" type + for (String key : inputs.keySet()) { + if (params.containsKey(key)) { + Object value = convertInputValue(inputs.get(key), params.get(key)); + if (value != null) { + goldenInputs.put(key, value); + } + else { + LOGGER.debug("Failed to convert input " + key + "='" + inputs.get(key) + "' to " + params.get(key).getParamType()); + } + } else { + extraInputs.add(key); + } + } + + if (!extraInputs.isEmpty()) { + LOGGER.debug("Ignoring extra inputs: " + extraInputs); + } + + // Next add in Volume Group Outputs if there are any. Copy directly without conversions. + if (volumeGroupOutputs != null && !volumeGroupOutputs.isEmpty()) { + for (String key : volumeGroupOutputs.keySet()) { + if (params.containsKey(key) && !goldenInputs.containsKey(key)) { + goldenInputs.put(key, volumeGroupOutputs.get(key)); + } + } + } + + // Next add in Base Module Outputs if there are any. Copy directly without conversions. + if (baseModuleOutputs != null && !baseModuleOutputs.isEmpty()) { + for (String key : baseModuleOutputs.keySet()) { + if (params.containsKey(key) && !goldenInputs.containsKey(key)) { + goldenInputs.put(key, baseModuleOutputs.get(key)); + } + } + } + + // TODO: The model should support a mechanism to pre-assign default parameter values + // per "customization" (i.e. usage) of a given module. In HEAT, this is specified by + // an Environment file. There is not a general mechanism in the model to handle this. + // For the general case, any such parameter/values can be added dynamically to the + // inputs (only if not already specified). + + + // Check that required parameters have been supplied from any of the sources + String missingParams = null; + boolean checkRequiredParameters = true; + try { + String propertyString = this.msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_VNF_ADAPTER) + .getProperty(MsoVnfPluginAdapterImpl.CHECK_REQD_PARAMS,null); + if ("false".equalsIgnoreCase (propertyString) || "n".equalsIgnoreCase (propertyString)) { + checkRequiredParameters = false; + LOGGER.debug ("CheckRequiredParameters is FALSE. Will still check but then skip blocking..." + + MsoVnfPluginAdapterImpl.CHECK_REQD_PARAMS); + } + } catch (Exception e) { + // No problem - default is true + LOGGER.debug ("An exception occured trying to get property " + MsoVnfPluginAdapterImpl.CHECK_REQD_PARAMS, e); + } + + // Do the actual parameter checking. + // Include looking at the ENV file as a valid definition of a parameter value. + // TODO: This handling of ENV applies only to Heat. A general mechanism to + // support pre-set parameter/values does not yet exist in the model. + // + StringBuilder sb = new StringBuilder(heatEnvironment.getEnvironment()); + MsoHeatEnvironmentEntry mhee = new MsoHeatEnvironmentEntry (sb); + for (HeatTemplateParam parm : heatTemplate.getParameters ()) { + if (parm.isRequired () && (!goldenInputs.containsKey (parm.getParamName ()))) { + if (mhee != null && mhee.containsParameter(parm.getParamName())) { + LOGGER.debug ("Required parameter " + parm.getParamName () + + " appears to be in environment - do not count as missing"); + } else { + LOGGER.debug ("adding to missing parameters list: " + parm.getParamName ()); + if (missingParams == null) { + missingParams = parm.getParamName (); + } else { + missingParams += "," + parm.getParamName (); + } + } + } + } + + if (missingParams != null) { + if (checkRequiredParameters) { + // Problem - missing one or more required parameters + String error = "Create VFModule: Missing Required inputs: " + missingParams; + LOGGER.error (MessageEnum.RA_MISSING_PARAM, missingParams, "VDU", "", MsoLogger.ErrorCode.DataError, "Create VFModule: Missing Required inputs"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, error); + throw new VnfException (error, MsoExceptionCategory.USERDATA); + } else { + LOGGER.debug ("found missing parameters [" + missingParams + "] - but checkRequiredParameters is false - will not block"); + } + } else { + LOGGER.debug ("No missing parameters found - ok to proceed"); + } + + } // NOTE: END PARAMETER CHECKING + + // Here we go... ready to deploy the VF Module. + long instantiateVduStartTime = System.currentTimeMillis (); + if (backout == null) backout = true; + + try { + // Construct the VDU Model structure to pass to the targeted VduPlugin + VduModelInfo vduModel = null; + if (! isVolumeRequest) { + vduModel = vduMapper.mapVfModuleCustomizationToVdu(vfModuleCust); + } else { + vduModel = vduMapper.mapVfModuleCustVolumeToVdu(vfModuleCust); + } + + // Invoke the VduPlugin to instantiate the VF Module + vduInstance = vduPlugin.instantiateVdu(cloudInfo, vfModuleName, goldenInputs, vduModel, backout); + + LOGGER.recordMetricEvent (instantiateVduStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from VduPlugin", "VDU", "instantiateVdu", vfModuleName); + } + catch (VduException me) { + // Failed to instantiate the VDU. + me.addContext ("CreateVFModule"); + String error = "Create VF Module " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + me; + LOGGER.recordMetricEvent (instantiateVduStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "instantiateVdu", vfModuleName); + LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, vfModuleType, cloudSiteId, tenantId, "VDU", "", MsoLogger.ErrorCode.DataError, "MsoException - instantiateVdu", me); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + // Convert to a generic VnfException + throw new VnfException (me); + } + catch (NullPointerException npe) { + String error = "Create VFModule " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + npe; + LOGGER.recordMetricEvent (instantiateVduStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, error, "VDU", "instantiateVdu", vfModuleName); + LOGGER.error (MessageEnum.RA_CREATE_VNF_ERR, vfModuleType, cloudSiteId, tenantId, "VDU", "", MsoLogger.ErrorCode.DataError, "NullPointerException - instantiateVdu", npe); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, error); + LOGGER.debug("NULL POINTER EXCEPTION at vduPlugin.instantiateVdu", npe); + throw new VnfException ("NullPointerException during instantiateVdu"); + } + catch (Exception e) { + String error = "Create VFModule " + vfModuleType + " in " + cloudSiteId + "/" + tenantId + ": " + e; + LOGGER.recordMetricEvent (instantiateVduStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.UnknownError, error, "VDU", "instantiateVdu", vfModuleName); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.UnknownError, error); + LOGGER.debug("Unhandled exception at vduPlugin.instantiateVdu", e); + } finally { + db.close(); + } + + // Reach this point if create is successful. + // Populate remaining rollback info and response parameters. + vfRollback.setVnfCreated (true); + vfRollback.setVnfId (vduInstance.getVduInstanceId()); + vnfId.value = vduInstance.getVduInstanceId(); + outputs.value = copyStringOutputs (vduInstance.getOutputs ()); + + rollback.value = vfRollback; + + LOGGER.debug ("VF Module " + vfModuleName + " successfully created"); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create VF Module"); + return; + } + + public void deleteVfModule (String cloudSiteId, + String tenantId, + String vfModuleId, + MsoRequest msoRequest, + Holder <Map <String, String>> outputs) throws VnfException + { + MsoLogger.setLogContext (msoRequest); + MsoLogger.setServiceName ("DeleteVfModule"); + + LOGGER.debug ("Deleting VF Module " + vfModuleId + " in " + cloudSiteId + "/" + tenantId); + // Will capture execution time for metrics + long startTime = System.currentTimeMillis (); + + // Capture the output parameters on a delete, so need to query first + VduInstance vduInstance = null; + CloudInfo cloudInfo = new CloudInfo(cloudSiteId, tenantId, null); + + // Use the VduPlugin. + VduPlugin vduPlugin = getVduPlugin(cloudSiteId); + + try { + vduInstance = vduPlugin.queryVdu (cloudInfo, vfModuleId); + LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received VDU Query response", "VDU", "QueryVDU", vfModuleId); + } + catch (VduException e) { + // Failed to query the VDU due to a plugin exception. + // Convert to a generic VnfException + e.addContext ("QueryVFModule"); + String error = "Query VfModule (VDU): " + vfModuleId + " in " + cloudSiteId + "/" + tenantId + ": " + e; + LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "VDU", "QueryVNF", vfModuleId); + LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, vfModuleId, cloudSiteId, tenantId, "VDU", "QueryVFModule", MsoLogger.ErrorCode.DataError, "Exception - queryVDU", e); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException (e); + } + + // call method which handles the conversion from Map<String,Object> to Map<String,String> for our expected Object types + outputs.value = convertMapStringObjectToStringString(vduInstance.getOutputs()); + + // Use the VduPlugin to delete the VDU. + // The possible outcomes of deleteVdu are + // - a vnfInstance object with status of DELETED (success) + // - a vnfInstance object with status of NOTFOUND (VDU did not exist, treat as success) + // - a vnfInstance object with status of FAILED (error) + // Also, VduException could be thrown. + long subStartTime = System.currentTimeMillis (); + try { + // TODO: Get an appropriate timeout value - require access to the model + vduPlugin.deleteVdu(cloudInfo, vfModuleId, 5); + LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from deleteVdu", "VDU", "DeleteVdu", vfModuleId); + } catch (VduException me) { + me.addContext ("DeleteVfModule"); + // Convert to a generic VnfException + String error = "Delete VF: " + vfModuleId + " in " + cloudSiteId + "/" + tenantId + ": " + me; + LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "DeleteVdu", "DeleteVdu", vfModuleId); + LOGGER.error (MessageEnum.RA_DELETE_VNF_ERR, vfModuleId, cloudSiteId, tenantId, "VDU", "DeleteVdu", MsoLogger.ErrorCode.DataError, "Exception - DeleteVdu: " + me.getMessage()); + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error); + throw new VnfException (me); + } + + // On success, nothing is returned. + LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully delete VF"); + return; + } + + // Update VF Module not yet implemented for generic VDU plug-in model. + @Override + public void updateVfModule (String cloudSiteId, + String tenantId, + String vnfType, + String vnfVersion, + String vnfName, + String requestType, + String volumeGroupHeatStackId, + String baseVfHeatStackId, + String vfModuleStackId, + String modelCustomizationUuid, + Map <String, String> inputs, + MsoRequest msoRequest, + Holder <Map <String, String>> outputs, + Holder <VnfRollback> rollback) throws VnfException + { + // This operation is not currently supported for VduPlugin-orchestrated VF Modules. + LOGGER.debug ("Update VF Module command attempted but not supported"); + throw new VnfException ("UpdateVfModule: Unsupported command", MsoExceptionCategory.USERDATA); + } + + /* + * Dynamic selection of a VduPlugin version. For initial tests, base on the "orchestrator" + * defined for the target cloud. Should really be looking at the VNF Model (ochestration_mode) + * but we don't currently have access to that in Query and Delete cases. + */ + private VduPlugin getVduPlugin (String cloudSiteId) { + Optional<CloudSite> cloudSite = cloudConfig.getCloudSite(cloudSiteId); + if (cloudSite.isPresent()) { + String orchestrator = cloudSite.get().getOrchestrator(); + + if (orchestrator.equalsIgnoreCase("CLOUDIFY")) { + return cloudifyUtils; + } + else if (orchestrator.equalsIgnoreCase("HEAT")) { + return heatUtils; + } + } + + // Default - return HEAT plugin, though will fail later + return heatUtils; + } + +} diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestUtils.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestUtils.java index f7302c0bf5..487e9c2b60 100644 --- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestUtils.java +++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/VnfAdapterRestUtils.java @@ -74,9 +74,9 @@ public class VnfAdapterRestUtils vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory, cloudConfigFactory); } else { - // Don't expect this, but default is the HEAT adapter - LOGGER.debug ("GetVnfAdapterImpl: Return Default (Heat) Adapter"); - vnfAdapter = new MsoVnfAdapterImpl (msoPropertiesFactory, cloudConfigFactory); + // Default is the PLUGIN adapter + LOGGER.debug ("GetVnfAdapterImpl: Return Default (Plugin) Adapter"); + vnfAdapter = new MsoVnfPluginAdapterImpl (msoPropertiesFactory, cloudConfigFactory); } return vnfAdapter; diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/AriaVduPluginTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/AriaVduPluginTest.java new file mode 100644 index 0000000000..c6d58143cc --- /dev/null +++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/AriaVduPluginTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.openecomp.mso.adapters.vnf; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.mso.vdu.utils.VduBlueprint; +import org.openecomp.mso.vdu.utils.VduPlugin; + +import java.util.HashMap; + +public class AriaVduPluginTest { + + VduPlugin vduPlugin = new AriaVduPlugin(); + + @Test(expected = RuntimeException.class) + public void instantiateVduFailedToCreateCSAR() throws Exception { + VduBlueprint blueprint = new VduBlueprint(); + blueprint.setMainTemplateName("blueprintmain"); + vduPlugin.instantiateVdu("cloudid", "tenantid", "vduinstancename", + new VduBlueprint(), new HashMap<>(), null, 100, true); + Assert.assertFalse(true); + } +}
\ No newline at end of file diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfPluginAdapterImplTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfPluginAdapterImplTest.java new file mode 100644 index 0000000000..37ca4f762a --- /dev/null +++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfPluginAdapterImplTest.java @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018 Huawei 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.openecomp.mso.adapters.vnf; + +import java.util.HashMap; +import java.util.Map; + +import javax.xml.ws.Holder; + +import org.junit.Test; +import org.openecomp.mso.adapters.vnf.exceptions.VnfException; +import org.openecomp.mso.entity.MsoRequest; +import org.openecomp.mso.openstack.beans.VnfRollback; + +public class MsoVnfPluginAdapterImplTest { + + @Test(expected = NullPointerException.class) + public void queryVnfNullPointerExceptionTest() throws Exception { + MsoVnfPluginAdapterImpl instance = new MsoVnfPluginAdapterImpl(); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + instance.queryVnf("siteid", "1234", "vfname", + msoRequest, new Holder<>(), new Holder<>(), new Holder<>(), + new Holder<>()); + } + + @Test(expected = VnfException.class) + public void deleteVnfVnfExceptionTest() throws Exception { + MsoVnfPluginAdapterImpl instance = new MsoVnfPluginAdapterImpl(); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + instance.deleteVnf("12344", "234", "vnfname", msoRequest); + + } + + @Test + public void rollbackVnf() throws Exception { + MsoVnfPluginAdapterImpl instance = new MsoVnfPluginAdapterImpl(); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + VnfRollback vnfRollback = new VnfRollback(); + vnfRollback.setModelCustomizationUuid("1234"); + vnfRollback.setVfModuleStackId("2134"); + vnfRollback.setVnfId("123"); + vnfRollback.setModelCustomizationUuid("1234"); + + instance.rollbackVnf(vnfRollback); + } + + @Test(expected = VnfException.class) + public void createVfModuleVnfException() throws Exception { + MsoVnfPluginAdapterImpl instance = new MsoVnfPluginAdapterImpl(); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + instance.createVfModule("123", "123", "vf", "v1", "module-005", "create", "3245", "234", "123", new HashMap<>(), true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); + } + + @Test(expected = VnfException.class) + public void updateVfModuleVnfException() throws Exception { + MsoVnfPluginAdapterImpl instance = new MsoVnfPluginAdapterImpl(); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + instance.updateVfModule("123", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234", new HashMap<>(), msoRequest, new Holder<>(), new Holder<>()); + } + + @Test + public void healthCheckVNFTest() { + MsoVnfPluginAdapterImpl instance = new MsoVnfPluginAdapterImpl(); + instance.healthCheck(); + } + + @Test + public void createVnfTest() { + MsoVnfPluginAdapterImpl instance = new MsoVnfPluginAdapterImpl(); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + Map<String, String> map = new HashMap<>(); + map.put("key1", "value1"); + try { + instance.createVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", + "volumeGroupHeatStackId|1", map, + Boolean.FALSE, Boolean.TRUE, msoRequest, new Holder<>(), new Holder<>(), + new Holder<>()); + } catch (Exception e) { + } + } + + @Test + public void updateVnfTest() { + MsoVnfPluginAdapterImpl instance = new MsoVnfPluginAdapterImpl(); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + Map<String, String> map = new HashMap<>(); + + map.put("key1", "value1"); + try { + instance.updateVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", + "volumeGroupHeatStackId|1", map, msoRequest, new Holder<>(), + new Holder<>()); + } catch (Exception e) { + + } + } + + @Test + public void deleteVnfTest() { + MsoVnfPluginAdapterImpl instance = new MsoVnfPluginAdapterImpl(); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + try { + instance.deleteVnf("mdt1", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest); + } catch (Exception e) { + + } + } + +} diff --git a/adapters/mso-workflow-message-adapter/src/test/java/org/openecomp/mso/adapters/workflowmessage/BPRestCallbackTest.java b/adapters/mso-workflow-message-adapter/src/test/java/org/openecomp/mso/adapters/workflowmessage/BPRestCallbackTest.java new file mode 100644 index 0000000000..8d2c938c09 --- /dev/null +++ b/adapters/mso-workflow-message-adapter/src/test/java/org/openecomp/mso/adapters/workflowmessage/BPRestCallbackTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 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.workflowmessage; + +import org.apache.http.entity.ContentType; +import org.junit.Test; +import org.mockito.Mock; + +import static junit.framework.Assert.assertFalse; + +public class BPRestCallbackTest { + + @Mock + ContentType contentType; + + @Test + public void testSendExceptionCase() { + + BPRestCallback test = new BPRestCallback(); + test.send("workflowMessageUrl/", "messageType", "correlator", contentType,"message"); + assertFalse(test.send("workflowMessageUrl/", "messageType", "correlator", contentType,"message")); + + } + } |