summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xadapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduBlueprint.java90
-rwxr-xr-xadapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduInfo.java130
-rwxr-xr-xadapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduPlugin.java248
-rwxr-xr-xadapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduStatus.java37
-rwxr-xr-xaria/aria-rest-java-client/pom.xml2
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaClient.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaClientFactory.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaRestClient.java713
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Execution.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ExecutionDetails.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ExecutionImpl.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Input.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/InputImpl.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/NodeTemplate.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/NodeTemplateImpl.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Output.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/OutputImpl.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Service.java0
-rw-r--r--aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceImpl.java58
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceTemplate.java63
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceTemplateImpl.java13
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ValidationResult.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ValidationResultImpl.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Workflow.java0
-rw-r--r--[-rwxr-xr-x]aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/WorkflowImpl.java0
-rw-r--r--bpmn/MSOCommonBPMN/pom.xml11
-rw-r--r--bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/CompleteMsoProcessTest.groovy59
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/ResponseExceptionMapperImplTest.java111
28 files changed, 1135 insertions, 400 deletions
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduBlueprint.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduBlueprint.java
new file mode 100755
index 0000000000..6e06eed702
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduBlueprint.java
@@ -0,0 +1,90 @@
+/*-
+ * ============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.vdu.utils;
+
+import java.util.Map;
+
+/*
+ * This Java bean class describes the template model of a VDU as distributed
+ * by SDC to SO. It is composed of one or more templates, one of which must be
+ * the main template,
+ *
+ * The structure of this class corresponds to the format in which the templates
+ * and associated artifacts are represented in the SO Catalog.
+ *
+ * The map keys will be the "path" that is used to reference these artifacts within
+ * the other templates. This may be relevant to how different VDU plugins package
+ * the files for delivery to the sub-orchestrator.
+ *
+ * In the future, it is possible that pre-packaged blueprints (e.g. complete TOSCA CSARs)
+ * could be stored in the catalog (and added to this structure).
+ *
+ * This bean is passed as an input to instantiateVdu and updateVdu.
+ */
+
+public class VduBlueprint {
+ String vduModelId;
+ String mainTemplateName;
+ Map<String,byte[]> templateFiles;
+ Map<String,byte[]> attachedFiles;
+
+ public String getVduModelId() {
+ return vduModelId;
+ }
+
+ public void setVduModelId(String vduModelId) {
+ this.vduModelId = vduModelId;
+ }
+
+ public String getMainTemplateName() {
+ return mainTemplateName;
+ }
+
+ public void setMainTemplateName(String mainTemplateName) {
+ this.mainTemplateName = mainTemplateName;
+ }
+
+ public Map<String, byte[]> getTemplateFiles() {
+ return templateFiles;
+ }
+
+ public void setTemplateFiles(Map<String, byte[]> templateFiles) {
+ this.templateFiles = templateFiles;
+ }
+
+ public Map<String, byte[]> getAttachedFiles() {
+ return attachedFiles;
+ }
+
+ public void setAttachedFiles(Map<String, byte[]> attachedFiles) {
+ this.attachedFiles = attachedFiles;
+ }
+
+ @Override
+ public String toString() {
+ return "VduInfo {" +
+ "id='" + vduModelId + '\'' +
+ "mainTemplateName='" + mainTemplateName + '\'' +
+ '}';
+ }
+
+}
+
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduInfo.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduInfo.java
new file mode 100755
index 0000000000..53300c9453
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduInfo.java
@@ -0,0 +1,130 @@
+/*-
+ * ============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.vdu.utils;
+
+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 MsoVduUtils interface operations
+ * (instantiate, query, delete).
+ */
+
+public class VduInfo {
+ // Set defaults for everything
+ private String vduInstanceId = "";
+ private String vduInstanceName = "";
+ private VduStatus status = VduStatus.NOTFOUND;
+ private Map<String,Object> outputs = new HashMap<String,Object>();
+ private Map<String,Object> inputs = new HashMap<String,Object>();
+ private String lastAction;
+ private String actionStatus;
+ private String errorMessage;
+
+ public VduInfo () {
+ }
+
+ // Add more constructors as appropriate
+ //
+
+ public VduInfo (String id, Map<String,Object> outputs) {
+ this.vduInstanceId = id;
+ if (outputs != null) this.outputs = outputs;
+ }
+
+ public VduInfo (String id) {
+ this.vduInstanceId = id;
+ }
+
+ public VduInfo (String id, VduStatus status) {
+ this.vduInstanceId = id;
+ this.status = status;
+ }
+
+ public String getVnfInstanceId() {
+ return vduInstanceId;
+ }
+
+ public void setVnfInstanceId (String id) {
+ this.vduInstanceId = id;
+ }
+
+ public String getVnfInstanceName() {
+ return vduInstanceName;
+ }
+
+ public void setVnfInstanceName (String name) {
+ this.vduInstanceName = name;
+ }
+
+ 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;
+ }
+
+ public String getLastAction() {
+ return lastAction;
+ }
+
+ public String getActionStatus() {
+ return actionStatus;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ @Override
+ public String toString() {
+ return "VduInfo {" +
+ "id='" + vduInstanceId + '\'' +
+ "name='" + vduInstanceName + '\'' +
+ ", inputs='" + inputs + '\'' +
+ ", outputs='" + outputs + '\'' +
+ ", lastAction='" + lastAction + '\'' +
+ ", status='" + status + '\'' +
+ ", errorMessage='" + errorMessage + '\'' +
+ '}';
+ }
+
+}
+
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduPlugin.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduPlugin.java
new file mode 100755
index 0000000000..3452a10db9
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduPlugin.java
@@ -0,0 +1,248 @@
+/*-
+ * ============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.vdu.utils;
+
+/**
+ * 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;
+
+import org.openecomp.mso.openstack.exceptions.MsoException;
+
+public interface VduPlugin {
+
+ /**
+ * The instantiateVdu interface deploys a new VDU instance from a blueprint package.
+ * The templates and files in the blueprint may be pre-installed where supported
+ * (e.g. in Cloudify or Aria), or may be passed in directly (e.g. for Heat). These
+ * files are expressed as byte arrays, though only text files are expected from ASDC.
+ *
+ * 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 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 cloudSiteId The target cloud for the VDU. Maps to a CloudConfig entry.
+ * @param tenantId The cloud tenant in which to deploy the VDU. The meaning may differ by
+ * cloud provider, but every cloud supports some sort of tenant partitioning.
+ * @param vduInstanceName A unique name for the VDU instance to create
+ * @param vduBlueprint Object containing the collection of templates and files that comprise
+ * the blueprint for this VDU.
+ * @param inputs A map of key/value inputs. Values may be strings, numbers, or JSON objects.
+ * @param environmentFile A file containing default parameter name/value pairs. This is
+ * primarily for Heat, though ASDC may create a similar file for other orchestrators.
+ * @param timeoutMinutes Timeout after which the instantiation attempt will be cancelled
+ * @param suppressBackout Flag to preserve the deployment on install Failure. Should normally
+ * be False except in troubleshooting/debug cases
+ *
+ * @return A VduInfo object
+ * @throws MsoException Thrown if the sub-orchestrator API calls fail or if a timeout occurs.
+ * Various subclasses of MsoException may be thrown.
+ */
+ public VduInfo instantiateVdu (
+ String cloudSiteId,
+ String tenantId,
+ String vduInstanceName,
+ VduBlueprint vduBlueprint,
+ Map <String, ? extends Object> inputs,
+ String environmentFile,
+ int timeoutMinutes,
+ boolean suppressBackout)
+ throws MsoException;
+
+
+ /**
+ * Query a deployed VDU instance. This call will return a VduInfo 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 VduInfo object contains the input and output parameter maps,
+ * as well as other properties of the deployment (name, status, last action, etc.).
+ *
+ * @param cloudSiteId The target cloud to query for the VDU.
+ * @param tenantId The cloud tenant in which to query
+ * @param vduInstanceId The ID of the deployment to query
+ *
+ * @return A VduInfo object
+ * @throws MsoException Thrown if the VIM/sub-orchestrator API calls fail.
+ * Various subclasses of MsoException may be thrown.
+ */
+ public VduInfo queryVdu (
+ String cloudSiteId,
+ String tenantId,
+ String vduInstanceId)
+ throws MsoException;
+
+
+ /**
+ * Delete a VDU instance by ID. If the VIM sub-orchestrator supports pre-installation
+ * of blueprints, 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 implementation. The deletion should be fully
+ * completed before returning.
+ *
+ * The successful return is a VduInfo object which contains the state of the object just prior
+ * to deletion, with a status of DELETED. If the deployment was not found, the VduInfo 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 cloudSiteId The target cloud from which to delete the VDU.
+ * @param tenantId The cloud tenant in which to delete the VDU.
+ * @param vduInstanceId The unique id of the deployment to delete.
+ * @param timeoutMinutes Timeout after which the delete action will be cancelled
+ * @param deleteBlueprint Flag to also delete the blueprint
+ *
+ * @return A VduInfo object, representing the state of the instance just prior to deletion.
+ *
+ * @throws MsoException Thrown if the API calls fail or if a timeout occurs.
+ * Various subclasses of MsoException may be thrown.
+ */
+ public VduInfo deleteVdu (
+ String cloudSiteId,
+ String tenantId,
+ String vduInstanceId,
+ int timeoutMinutes,
+ boolean keepBlueprintLoaded)
+ throws MsoException;
+
+
+ /**
+ * 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
+ * VduInfo 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 cloudSiteId The target cloud for the VDU. Maps to a CloudConfig entry.
+ * @param tenantId The cloud tenant in which to deploy the VDU. The meaning may differ by
+ * cloud provider, but every cloud supports some sort of tenant partitioning.
+ * @param vduInstanceId The unique ID for the VDU instance to update.
+ * @param vduBlueprint Object containing the collection of templates and files that comprise
+ * the blueprint for this VDU.
+ * @param inputs A map of key/value inputs. Values may be strings, numbers, or JSON objects.
+ * @param environmentFile A file containing default parameter name/value pairs. This is
+ * primarily for Heat, though ASDC may create a similar file for other orchestrators.
+ * @param timeoutMinutes Timeout after which the instantiation attempt will be cancelled
+ *
+ * @return A VduInfo object
+ * @throws MsoException Thrown if the sub-orchestrator API calls fail or if a timeout occurs.
+ * Various subclasses of MsoException may be thrown.
+ */
+ public VduInfo updateVdu (
+ String cloudSiteId,
+ String tenantId,
+ String vduInstanceId,
+ VduBlueprint vduBlueprint,
+ Map <String, ? extends Object> inputs,
+ String environmentFile,
+ int timeoutMinutes)
+ throws MsoException;
+
+
+ /**
+ * Check if a blueprint package has been installed in the sub-orchestrator and available
+ * for use at a targeted cloud site. If the specific sub-orchestrator does not support
+ * pre-installation, then those implementations should always return False.
+ *
+ * @param cloudSiteId The cloud site where the blueprint is needed
+ * @param vduModelId Unique ID of the VDU model to query
+ *
+ * @throws MsoException Thrown if the API call fails.
+ */
+ public boolean isBlueprintLoaded (String cloudSiteId, String vduModelId)
+ throws MsoException;
+
+
+ /**
+ * Install a blueprint package to the target sub-orchestrator for a cloud site.
+ * The blueprints currently must be structured as a single directory with all of the
+ * required files. One of those files is designated the "main file" for the blueprint.
+ * Files are provided as byte arrays, though expect only text files will be distributed
+ * from ASDC and stored by MSO.
+ *
+ * @param cloudSiteId The cloud site where the blueprint is needed
+ * @param vduBlueprint Object containing the collection of templates and files that comprise
+ * the blueprint for this VDU.
+ * @param failIfExists Flag to return an error if blueprint already exists
+ *
+ * @throws MsoException Thrown if the API call fails.
+ */
+ public void uploadBlueprint (String cloudSiteId,
+ VduBlueprint vduBlueprint,
+ boolean failIfExists)
+ throws MsoException;
+
+ /**
+ * Indicator that this VIM sub-orchestrator implementation supports independent upload
+ * of blueprint packages. Each implementation should return a constant value.
+ *
+ * @returns True if the sub-orchestrator supports blueprint pre-installation (upload).
+ */
+ public boolean blueprintUploadSupported ();
+
+}
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduStatus.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduStatus.java
new file mode 100755
index 0000000000..0f4611a2de
--- /dev/null
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/vdu/utils/VduStatus.java
@@ -0,0 +1,37 @@
+/*-
+ * ============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.vdu.utils;
+
+
+/*
+ * Enum status values to capture the state of a generic (cloud-agnostic) VDU.
+ */
+public enum VduStatus {
+ NOTFOUND,
+ INSTANTIATING,
+ INSTANTIATED,
+ DELETING,
+ DELETED, // Note - only returned in success response to deleteVdu call.
+ UPDATING,
+ FAILED,
+ UNKNOWN
+}
+
diff --git a/aria/aria-rest-java-client/pom.xml b/aria/aria-rest-java-client/pom.xml
index 402d3c1268..f35403cf81 100755
--- a/aria/aria-rest-java-client/pom.xml
+++ b/aria/aria-rest-java-client/pom.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<!--
/*
* ============LICENSE_START===================================================
@@ -17,7 +18,6 @@
* ============LICENSE_END====================================================
*/
-->
-<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaClient.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaClient.java
index d6e9f2434d..d6e9f2434d 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaClient.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaClient.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaClientFactory.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaClientFactory.java
index a97384e084..a97384e084 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaClientFactory.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaClientFactory.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaRestClient.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaRestClient.java
index a4e453395d..5de2203b2f 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaRestClient.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/AriaRestClient.java
@@ -1,336 +1,377 @@
-/*
- * ============LICENSE_START===================================================
- * Copyright (c) 2017 Cloudify.co. 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 com.gigaspaces.aria.rest.client;
-
-import com.gigaspaces.aria.rest.client.exceptions.StorageException;
-import com.gigaspaces.aria.rest.client.exceptions.ValidationException;
-import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.JsonNode;
-import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
-import org.codehaus.jackson.map.ObjectMapper;
-import sun.reflect.generics.reflectiveObjects.NotImplementedException;
-
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-
-import static javax.ws.rs.client.Entity.entity;
-
-/**
- * Created by DeWayne on 7/12/2017.
- */
-public class AriaRestClient implements AriaClient {
- private Client client=null;
- private WebTarget base_target=null;
-
- /**
- * Construct an Aria REST client
- *
- * @param protocol either http or https
- * @param address the IP address or host name
- * @param port the port of the service
- * @param version the api version
- */
- public AriaRestClient(String protocol, String address, int port, String version){
- this.client = ClientBuilder.newBuilder().register(JacksonJsonProvider.class).build();
- base_target = client.target(protocol+"://"+address+":"+port+"/api/"+version);
- }
-
- /**
- * Installs a service template
- *
- * @param template the template object
- * @throws ValidationException
- * @throws StorageException
- */
- public void install_service_template(ServiceTemplate template) throws ValidationException, StorageException, Exception {
-
- Response response = base_target.path("templates/"+template.getName()).request(MediaType.APPLICATION_JSON).put(Entity.entity(
- "{\"service-template-path\":\""+template.getURI().toString()+"\""+
- ",\"service-template-filename\":\""+template.getFilename()+"\"", MediaType.APPLICATION_JSON));
-
- if(response.getStatus() == 500){
- throw new StorageException(response.readEntity(String.class));
- }
- else if(response.getStatus() == 400){
- throw new ValidationException(response.readEntity(String.class));
- }
- else if(response.getStatus()>199 && response.getStatus() <300){
- return;
- }
- else{
- throw new Exception("Error installing template: "+response.getStatus()+" "+ response.readEntity(String.class));
- }
- }
-
- public ValidationResult validate_service_template(ServiceTemplate template)throws Exception{
- Response response = base_target.path("templates").request(MediaType.APPLICATION_JSON).post(Entity.entity(
- "{\"service-template-path\":\""+template.getURI().toString()+"\""+
- ",\"service-template-filename\":\""+template.getFilename()+"\"}", MediaType.APPLICATION_JSON));
-
- ValidationResultImpl result = new ValidationResultImpl();
- if(response.getStatus() >= 200 && response.getStatus() < 300){
- result.setFailed(false);
- }
- else if(response.getStatus()==400){
- result.setFailed(true);
- }
- else{
- throw new Exception("received error response '"+ response.getStatus()+"':"+response.readEntity(String.class));
- }
- return result;
-
- }
-
- /**
- *
- * @return a list of service templates
- */
- public List<? extends ServiceTemplate> list_service_templates(){
- List<? extends ServiceTemplate> templates = base_target.path("templates").request(MediaType.APPLICATION_JSON).get(new GenericType<List<ServiceTemplateImpl>>(){});
-
- return templates;
- }
-
-
- /**
- * Deletes the specified template.
- *
- * TODO: Error handling is a little blunt. Need to describe failures better
- *
- * @param template_id the template id to delete
- * @throws IllegalArgumentException thrown when the template can't be deleted
- * @throws Exception other server side errors
- */
- public void delete_service_template(int template_id) throws IllegalArgumentException, Exception{
- Response response = base_target.path("templates/"+template_id).request(MediaType.APPLICATION_JSON).delete();
-
- if(response.getStatus()>=200 && response.getStatus()<300){
- return;
- }
- else if(response.getStatus()==400){
- throw new IllegalArgumentException("Error deleting template '"+template_id+"'");
- }
- else{
- throw new Exception("Error processing request. Return code = "+response.getStatus());
- }
- }
-
- /**
- * List the node templates for a given template id
- *
- * @param template_id
- * @return
- */
- public List<? extends NodeTemplate> list_nodes(int template_id) {
- List<? extends NodeTemplate> nodes = base_target.path("templates/"+template_id+"/nodes").request(MediaType.APPLICATION_JSON).get(new GenericType<List<NodeTemplateImpl>>(){});
- return nodes;
- }
-
- /**
- * Get a specific node by id
- *
- * @param node_id the node id
- * @return
- * @throws IllegalArgumentException
- */
- public NodeTemplate get_node(int node_id) throws IllegalArgumentException {
- NodeTemplate node = base_target.path("nodes/"+node_id).request(MediaType.APPLICATION_JSON).get(NodeTemplateImpl.class);
- return node;
- }
-
- public List<? extends Service> list_services() {
- List<? extends Service> services = base_target.path("services").request(MediaType.APPLICATION_JSON).get(new GenericType<List<ServiceImpl>>(){});
- return services;
- }
-
- public Service get_service(int service_id) throws IllegalArgumentException {
- throw new NotImplementedException();
- }
-
- public List<? extends Output> list_service_outputs(int service_id) throws IllegalArgumentException {
- List<? extends Output> outputs = base_target.path("services").request(MediaType.APPLICATION_JSON).get(new GenericType<List<OutputImpl>>(){});
- return outputs;
- }
-
- public List<? extends Input> list_service_inputs(int service_id) throws IllegalArgumentException {
- List<? extends Input> inputs = base_target.path("services").request(MediaType.APPLICATION_JSON).get(new GenericType<List<InputImpl>>(){});
- return inputs;
- }
-
- /**
- * Create a service based on the supplied template
- *
- * @param template_id the template to create the service for
- * @param service_name a name for the service
- * @param inputs an optional list of inputs for the service (can be null)
- * @throws Exception
- */
- public void create_service(int template_id, String service_name, List<Input> inputs) throws Exception {
-
- String json="{"+inputsToJson(inputs)+"}";
-
- Response response = base_target.path("templates/"+template_id+"/services/"+service_name).
- request(MediaType.APPLICATION_JSON).post(
- Entity.entity(json, MediaType.APPLICATION_JSON)
- );
-
- if( response.getStatus()< 200 || response.getStatus()>299){
- throw new Exception("create service failed:"+response.getStatus()+" "+ response.readEntity(String.class));
- }
- }
-
- public void delete_service(int service_id) throws Exception {
- Response response = base_target.path("services/"+service_id).request(MediaType.APPLICATION_JSON).delete();
- if(!responseOK(response)){
- throw new Exception("delete service failed: "+response.getStatus()+" "+ response.readEntity(String.class));
- }
- }
-
- /**
- * List user workflows for supplied service
- *
- * @param service_id
- * @return
- * @throws IllegalArgumentException
- */
- public List<? extends Workflow> list_workflows(int service_id) throws IllegalArgumentException {
- List<? extends Workflow> workflows = base_target.path("services/"+service_id+"/workflows").request(MediaType.APPLICATION_JSON).get(new GenericType<List<WorkflowImpl>>(){});
- return workflows;
- }
-
- public Workflow get_workflow(int workflow_id) throws IllegalArgumentException {
- throw new NotImplementedException();
- }
-
- /**
- * List all executions
- *
- * @return
- * @throws Exception
- */
- public List<? extends Execution> list_executions() throws Exception {
- List<? extends Execution> executions = base_target.path("executions").request(MediaType.APPLICATION_JSON).get(new GenericType<List<ExecutionImpl>>(){});
- return executions;
- }
-
- /**
- * List executions for specified service
- *
- * @param service_id
- * @return
- * @throws Exception
- */
- public List<? extends Execution> list_executions(int service_id) throws Exception {
- List<? extends Execution> executions = base_target.path("services/"+service_id+"/executions").request(MediaType.APPLICATION_JSON).get(new GenericType<List<ExecutionImpl>>(){});
- return executions;
- }
-
- /**
- * Get details about a specified execution
- *
- * @param execution_id
- * @return
- * @throws IllegalArgumentException
- */
- public Execution get_execution(int execution_id) throws IllegalArgumentException {
- Execution execution = base_target.path("executions/"+execution_id).request(MediaType.APPLICATION_JSON).get(ExecutionImpl.class);
- return execution;
- }
-
- /**
- * Start an execution for the specified service
- *
- * @param service_id the service to run the execution for
- * @param workflow_name the name of the workflow to execute
- * @param details details controlling execution operation
- * @return the execution id
- * @throws Exception
- */
- public int start_execution(int service_id, String workflow_name, ExecutionDetails details) throws Exception {
- StringBuilder json=new StringBuilder("{");
- if(details.getExecutor().length()>0){
- json.append("\"executor\":\"").append(details.getExecutor()).append("\",");
- }
- if(details.getInputs()!=null){
- json.append(inputsToJson(details.getInputs()));
- }
- json.append("\"task_max_attempts\":").append(details.getTaskMaxAttempts()).append(",");
- json.append("\"task_retry_interval\":").append(details.getTaskRetryInterval()).append("}");
-
- System.out.println("JSON="+json.toString());
-
- Response response = base_target.path("services/"+service_id+"/executions/"+workflow_name).request(MediaType.APPLICATION_JSON).
- post(Entity.entity(json.toString(), MediaType.APPLICATION_JSON));
-
- if(!responseOK(response)){
- throw new Exception("start execution failed: "+response.getStatus()+" "+response.readEntity(String.class));
- }
-
- ObjectMapper mapper = new ObjectMapper(new JsonFactory());
- JsonNode rootNode = mapper.readTree(response.readEntity(String.class));
- int id=rootNode.get("id").asInt(-1);
- return id;
- }
-
- public void resume_execution(int execution_id, ExecutionDetails details) throws IllegalArgumentException {
- StringBuilder json=new StringBuilder("{");
- if(details.getExecutor().length()>0){
- json.append("\"executor\":\"").append(details.getExecutor()).append("\",");
- }
- json.append("\"retry_failed_tasks\":").append(details.isRetry_failed_tasks()).append("}");
- Response response = base_target.path("executions/"+execution_id).request(MediaType.APPLICATION_JSON).
- post(Entity.entity(json.toString(), MediaType.APPLICATION_JSON));
- }
-
- public void cancel_execution(int execution_id) throws Exception {
- Response response = base_target.path("executions/"+execution_id).request(MediaType.APPLICATION_JSON).delete();
- if(!responseOK(response)){
- throw new Exception("delete service failed: "+response.getStatus()+" "+ response.readEntity(String.class));
- }
- }
-
- /**
- * -----
- * ----- PRIVATE METHODS
- * -----
- */
-
- private boolean responseOK(Response response){
- return response.getStatus()>199 && response.getStatus()<300;
- }
-
- private String inputsToJson(List<Input> inputs){
- if(inputs==null)return null;
-
- StringBuilder sb=new StringBuilder("\"inputs\":{");
- for(Input input:inputs){
- sb.append("\"").append(input.getName()).append("\":\"").append(input.getValue()).append("\",");
- }
- if(inputs.size()>0)sb.deleteCharAt(sb.length()-1); //trim comma
-
- return sb.toString();
- }
-}
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2017 Cloudify.co. 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 com.gigaspaces.aria.rest.client;
+
+import java.util.List;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
+import org.codehaus.jackson.map.ObjectMapper;
+import com.gigaspaces.aria.rest.client.exceptions.StorageException;
+import com.gigaspaces.aria.rest.client.exceptions.ValidationException;
+
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
+/**
+ * Created by DeWayne on 7/12/2017.
+ */
+public class AriaRestClient implements AriaClient {
+ private Client client = null;
+ private WebTarget base_target = null;
+
+ /**
+ * Construct an Aria REST client
+ *
+ * @param protocol
+ * either http or https
+ * @param address
+ * the IP address or host name
+ * @param port
+ * the port of the service
+ * @param version
+ * the api version
+ */
+ public AriaRestClient(String protocol, String address, int port, String version) {
+ this.client = ClientBuilder.newBuilder().register(JacksonJsonProvider.class).build();
+ base_target = client.target(protocol + "://" + address + ":" + port + "/api/" + version);
+ }
+
+ /**
+ * Installs a service template
+ *
+ * @param template
+ * the template object
+ * @throws ValidationException
+ * @throws StorageException
+ */
+ public void install_service_template(ServiceTemplate template)
+ throws ValidationException, StorageException, Exception {
+
+ byte[] csarBytes = template.getCSARBytes();
+ Response response = null;
+ if (csarBytes == null) {
+ response = base_target.path("templates/" + template.getName()).request(MediaType.APPLICATION_JSON)
+ .put(Entity.entity(
+ "{\"service-template-path\":\"" + template.getURI().toString() + "\""
+ + ",\"service-template-filename\":\"" + template.getFilename() + "\"",
+ MediaType.APPLICATION_JSON));
+ }
+ else {
+
+ response = base_target.path("templates/" + template.getName()).request("application/zip")
+ .put(Entity.entity(csarBytes, "application/zip"));
+ }
+
+ if (response.getStatus() == 500) {
+ throw new StorageException(response.readEntity(String.class));
+ } else if (response.getStatus() == 400) {
+ throw new ValidationException(response.readEntity(String.class));
+ } else if (response.getStatus() > 199 && response.getStatus() < 300) {
+ return;
+ } else {
+ throw new Exception(
+ "Error installing template: " + response.getStatus() + " " + response.readEntity(String.class));
+ }
+ }
+
+ public ValidationResult validate_service_template(ServiceTemplate template) throws Exception {
+ Response response = base_target.path("templates").request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(
+ "{\"service-template-path\":\"" + template.getURI().toString() + "\""
+ + ",\"service-template-filename\":\"" + template.getFilename() + "\"}",
+ MediaType.APPLICATION_JSON));
+
+ ValidationResultImpl result = new ValidationResultImpl();
+ if (response.getStatus() >= 200 && response.getStatus() < 300) {
+ result.setFailed(false);
+ } else if (response.getStatus() == 400) {
+ result.setFailed(true);
+ } else {
+ throw new Exception(
+ "received error response '" + response.getStatus() + "':" + response.readEntity(String.class));
+ }
+ return result;
+
+ }
+
+ /**
+ *
+ * @return a list of service templates
+ */
+ public List<? extends ServiceTemplate> list_service_templates() {
+ List<? extends ServiceTemplate> templates = base_target.path("templates").request(MediaType.APPLICATION_JSON)
+ .get(new GenericType<List<ServiceTemplateImpl>>() {
+ });
+
+ return templates;
+ }
+
+ /**
+ * Deletes the specified template.
+ *
+ * TODO: Error handling is a little blunt. Need to describe failures better
+ *
+ * @param template_id
+ * the template id to delete
+ * @throws IllegalArgumentException
+ * thrown when the template can't be deleted
+ * @throws Exception
+ * other server side errors
+ */
+ public void delete_service_template(int template_id) throws IllegalArgumentException, Exception {
+ Response response = base_target.path("templates/" + template_id).request(MediaType.APPLICATION_JSON).delete();
+
+ if (response.getStatus() >= 200 && response.getStatus() < 300) {
+ return;
+ } else if (response.getStatus() == 400) {
+ throw new IllegalArgumentException("Error deleting template '" + template_id + "'");
+ } else {
+ throw new Exception("Error processing request. Return code = " + response.getStatus());
+ }
+ }
+
+ /**
+ * List the node templates for a given template id
+ *
+ * @param template_id
+ * @return
+ */
+ public List<? extends NodeTemplate> list_nodes(int template_id) {
+ List<? extends NodeTemplate> nodes = base_target.path("templates/" + template_id + "/nodes")
+ .request(MediaType.APPLICATION_JSON).get(new GenericType<List<NodeTemplateImpl>>() {
+ });
+ return nodes;
+ }
+
+ /**
+ * Get a specific node by id
+ *
+ * @param node_id
+ * the node id
+ * @return
+ * @throws IllegalArgumentException
+ */
+ public NodeTemplate get_node(int node_id) throws IllegalArgumentException {
+ NodeTemplate node = base_target.path("nodes/" + node_id).request(MediaType.APPLICATION_JSON)
+ .get(NodeTemplateImpl.class);
+ return node;
+ }
+
+ public List<? extends Service> list_services() {
+ List<? extends Service> services = base_target.path("services").request(MediaType.APPLICATION_JSON)
+ .get(new GenericType<List<ServiceImpl>>() {
+ });
+ return services;
+ }
+
+ public Service get_service(int service_id) throws IllegalArgumentException {
+ throw new NotImplementedException();
+ }
+
+ public List<? extends Output> list_service_outputs(int service_id) throws IllegalArgumentException {
+ List<? extends Output> outputs = base_target.path("services").request(MediaType.APPLICATION_JSON)
+ .get(new GenericType<List<OutputImpl>>() {
+ });
+ return outputs;
+ }
+
+ public List<? extends Input> list_service_inputs(int service_id) throws IllegalArgumentException {
+ List<? extends Input> inputs = base_target.path("services").request(MediaType.APPLICATION_JSON)
+ .get(new GenericType<List<InputImpl>>() {
+ });
+ return inputs;
+ }
+
+ /**
+ * Create a service based on the supplied template
+ *
+ * @param template_id
+ * the template to create the service for
+ * @param service_name
+ * a name for the service
+ * @param inputs
+ * an optional list of inputs for the service (can be null)
+ * @throws Exception
+ */
+ public void create_service(int template_id, String service_name, List<Input> inputs) throws Exception {
+
+ String json = "{" + inputsToJson(inputs) + "}";
+
+ Response response = base_target.path("templates/" + template_id + "/services/" + service_name)
+ .request(MediaType.APPLICATION_JSON).post(Entity.entity(json, MediaType.APPLICATION_JSON));
+
+ if (response.getStatus() < 200 || response.getStatus() > 299) {
+ throw new Exception(
+ "create service failed:" + response.getStatus() + " " + response.readEntity(String.class));
+ }
+ }
+
+ public void delete_service(int service_id) throws Exception {
+ Response response = base_target.path("services/" + service_id).request(MediaType.APPLICATION_JSON).delete();
+ if (!responseOK(response)) {
+ throw new Exception(
+ "delete service failed: " + response.getStatus() + " " + response.readEntity(String.class));
+ }
+ }
+
+ /**
+ * List user workflows for supplied service
+ *
+ * @param service_id
+ * @return
+ * @throws IllegalArgumentException
+ */
+ public List<? extends Workflow> list_workflows(int service_id) throws IllegalArgumentException {
+ List<? extends Workflow> workflows = base_target.path("services/" + service_id + "/workflows")
+ .request(MediaType.APPLICATION_JSON).get(new GenericType<List<WorkflowImpl>>() {
+ });
+ return workflows;
+ }
+
+ public Workflow get_workflow(int workflow_id) throws IllegalArgumentException {
+ throw new NotImplementedException();
+ }
+
+ /**
+ * List all executions
+ *
+ * @return
+ * @throws Exception
+ */
+ public List<? extends Execution> list_executions() throws Exception {
+ List<? extends Execution> executions = base_target.path("executions").request(MediaType.APPLICATION_JSON)
+ .get(new GenericType<List<ExecutionImpl>>() {
+ });
+ return executions;
+ }
+
+ /**
+ * List executions for specified service
+ *
+ * @param service_id
+ * @return
+ * @throws Exception
+ */
+ public List<? extends Execution> list_executions(int service_id) throws Exception {
+ List<? extends Execution> executions = base_target.path("services/" + service_id + "/executions")
+ .request(MediaType.APPLICATION_JSON).get(new GenericType<List<ExecutionImpl>>() {
+ });
+ return executions;
+ }
+
+ /**
+ * Get details about a specified execution
+ *
+ * @param execution_id
+ * @return
+ * @throws IllegalArgumentException
+ */
+ public Execution get_execution(int execution_id) throws IllegalArgumentException {
+ Execution execution = base_target.path("executions/" + execution_id).request(MediaType.APPLICATION_JSON)
+ .get(ExecutionImpl.class);
+ return execution;
+ }
+
+ /**
+ * Start an execution for the specified service
+ *
+ * @param service_id
+ * the service to run the execution for
+ * @param workflow_name
+ * the name of the workflow to execute
+ * @param details
+ * details controlling execution operation
+ * @return the execution id
+ * @throws Exception
+ */
+ public int start_execution(int service_id, String workflow_name, ExecutionDetails details) throws Exception {
+ StringBuilder json = new StringBuilder("{");
+ if (details.getExecutor().length() > 0) {
+ json.append("\"executor\":\"").append(details.getExecutor()).append("\",");
+ }
+ if (details.getInputs() != null) {
+ json.append(inputsToJson(details.getInputs()));
+ }
+ json.append("\"task_max_attempts\":").append(details.getTaskMaxAttempts()).append(",");
+ json.append("\"task_retry_interval\":").append(details.getTaskRetryInterval()).append("}");
+
+ System.out.println("JSON=" + json.toString());
+
+ Response response = base_target.path("services/" + service_id + "/executions/" + workflow_name)
+ .request(MediaType.APPLICATION_JSON).post(Entity.entity(json.toString(), MediaType.APPLICATION_JSON));
+
+ if (!responseOK(response)) {
+ throw new Exception(
+ "start execution failed: " + response.getStatus() + " " + response.readEntity(String.class));
+ }
+
+ ObjectMapper mapper = new ObjectMapper(new JsonFactory());
+ JsonNode rootNode = mapper.readTree(response.readEntity(String.class));
+ int id = rootNode.get("id").asInt(-1);
+ return id;
+ }
+
+ public void resume_execution(int execution_id, ExecutionDetails details) throws IllegalArgumentException {
+ StringBuilder json = new StringBuilder("{");
+ if (details.getExecutor().length() > 0) {
+ json.append("\"executor\":\"").append(details.getExecutor()).append("\",");
+ }
+ json.append("\"retry_failed_tasks\":").append(details.isRetry_failed_tasks()).append("}");
+ Response response = base_target.path("executions/" + execution_id).request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(json.toString(), MediaType.APPLICATION_JSON));
+ }
+
+ public void cancel_execution(int execution_id) throws Exception {
+ Response response = base_target.path("executions/" + execution_id).request(MediaType.APPLICATION_JSON).delete();
+ if (!responseOK(response)) {
+ throw new Exception(
+ "delete service failed: " + response.getStatus() + " " + response.readEntity(String.class));
+ }
+ }
+
+ /**
+ * ----- ----- PRIVATE METHODS -----
+ */
+
+ private boolean responseOK(Response response) {
+ return response.getStatus() > 199 && response.getStatus() < 300;
+ }
+
+ private String inputsToJson(List<Input> inputs) {
+ if (inputs == null)
+ return null;
+
+ StringBuilder sb = new StringBuilder("\"inputs\":{");
+ for (Input input : inputs) {
+ sb.append("\"").append(input.getName()).append("\":\"").append(input.getValue()).append("\",");
+ }
+ if (inputs.size() > 0)
+ sb.deleteCharAt(sb.length() - 1); // trim comma
+
+ return sb.toString();
+ }
+}
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Execution.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Execution.java
index ab742833e6..ab742833e6 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Execution.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Execution.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ExecutionDetails.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ExecutionDetails.java
index e7685a259c..e7685a259c 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ExecutionDetails.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ExecutionDetails.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ExecutionImpl.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ExecutionImpl.java
index 8e420cc16c..8e420cc16c 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ExecutionImpl.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ExecutionImpl.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Input.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Input.java
index 595dfb1245..595dfb1245 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Input.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Input.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/InputImpl.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/InputImpl.java
index 3002b7b54e..3002b7b54e 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/InputImpl.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/InputImpl.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/NodeTemplate.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/NodeTemplate.java
index bc46d7f5b2..bc46d7f5b2 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/NodeTemplate.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/NodeTemplate.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/NodeTemplateImpl.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/NodeTemplateImpl.java
index 43338c952d..43338c952d 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/NodeTemplateImpl.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/NodeTemplateImpl.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Output.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Output.java
index 83363bad6c..83363bad6c 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Output.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Output.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/OutputImpl.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/OutputImpl.java
index 0a6cecc9c1..0a6cecc9c1 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/OutputImpl.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/OutputImpl.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Service.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Service.java
index 9cf86ec73f..9cf86ec73f 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Service.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Service.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceImpl.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceImpl.java
new file mode 100644
index 0000000000..456335cedc
--- /dev/null
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceImpl.java
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2017 Cloudify.co. 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 com.gigaspaces.aria.rest.client;
+
+import java.net.URI;
+import java.util.Date;
+
+/**
+ *
+ *
+ * Created by DeWayne on 7/17/2017.
+ */
+public class ServiceImpl implements Service {
+ private int id;
+ private String description, name, template;
+ private Date created, updated;
+
+ public int getId(){
+ return id;
+ }
+
+ public String getDescription(){
+ return description;
+ }
+
+ public String getName(){
+ return name;
+ }
+
+ public String getServiceTemplate(){
+ return template;
+ }
+
+ public Date getCreated(){
+ return created;
+ }
+
+ public Date getUpdated(){
+ return updated;
+ }
+
+
+}
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceTemplate.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceTemplate.java
index 0df6d60905..a2ca8cf662 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceTemplate.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceTemplate.java
@@ -1,31 +1,32 @@
-/*
- * ============LICENSE_START===================================================
- * Copyright (c) 2017 Cloudify.co. 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 com.gigaspaces.aria.rest.client;
-
-import java.net.URI;
-
-/**
- * Created by DeWayne on 7/12/2017.
- */
-public interface ServiceTemplate {
- String getName();
- URI getURI();
- int getId();
- String getFilename();
- String getDescription();
-}
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2017 Cloudify.co. 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 com.gigaspaces.aria.rest.client;
+
+import java.net.URI;
+
+/**
+ * Created by DeWayne on 7/12/2017.
+ */
+public interface ServiceTemplate {
+ String getName();
+ URI getURI();
+ int getId();
+ String getFilename();
+ String getDescription();
+ byte[] getCSARBytes();
+}
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceTemplateImpl.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceTemplateImpl.java
index 9e158a27fd..a41d5b7236 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceTemplateImpl.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ServiceTemplateImpl.java
@@ -31,6 +31,7 @@ public class ServiceTemplateImpl implements ServiceTemplate {
private URI uri;
private String filename = DEFAULT_TEMPLATE_NAME;
private String description;
+ private byte[] csar_blob; // for opaque binary
public ServiceTemplateImpl(){}
@@ -40,7 +41,7 @@ public class ServiceTemplateImpl implements ServiceTemplate {
}
/**
- * Construct an instance
+ * Construct an instance based on CSAR
* @param name a textual name for the template
* @param uri a URI to a CSAR
* @param filename the filename in the CSAR representing main yaml template
@@ -51,6 +52,13 @@ public class ServiceTemplateImpl implements ServiceTemplate {
this.filename=filename;
this.description=description;
}
+
+ /**
+ * Construct an instance based on CSAR array
+ */
+ public ServiceTemplateImpl(byte[] csar_bytes) {
+ this.csar_blob = csar_bytes;
+ }
public int getId(){
return id;
@@ -76,6 +84,9 @@ public class ServiceTemplateImpl implements ServiceTemplate {
public void setFilename(String filename){
this.filename=filename;
}
+ public byte[] getCSARBytes() {
+ return csar_blob;
+ }
public String getDescription(){ return description;}
}
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ValidationResult.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ValidationResult.java
index 3d40dfa1ec..3d40dfa1ec 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ValidationResult.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ValidationResult.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ValidationResultImpl.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ValidationResultImpl.java
index 22e34eb7b3..22e34eb7b3 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ValidationResultImpl.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/ValidationResultImpl.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Workflow.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Workflow.java
index 7dbab18943..7dbab18943 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Workflow.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/Workflow.java
diff --git a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/WorkflowImpl.java b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/WorkflowImpl.java
index 41105df26a..41105df26a 100755..100644
--- a/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/WorkflowImpl.java
+++ b/aria/aria-rest-java-client/src/main/java/com/gigaspaces/aria/rest/client/WorkflowImpl.java
diff --git a/bpmn/MSOCommonBPMN/pom.xml b/bpmn/MSOCommonBPMN/pom.xml
index 4a7cb5900a..523ee403d0 100644
--- a/bpmn/MSOCommonBPMN/pom.xml
+++ b/bpmn/MSOCommonBPMN/pom.xml
@@ -501,5 +501,16 @@
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.9.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>pl.pragmatists</groupId>
+ <artifactId>JUnitParams</artifactId>
+ <version>1.1.1</version>
+ </dependency>
</dependencies>
</project>
diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/CompleteMsoProcessTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/CompleteMsoProcessTest.groovy
index ab7ee7a689..5949c3af53 100644
--- a/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/CompleteMsoProcessTest.groovy
+++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/openecomp/mso/bpmn/common/scripts/CompleteMsoProcessTest.groovy
@@ -16,23 +16,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- */
+ */
package org.openecomp.mso.bpmn.common.scripts
-import org.junit.runner.RunWith;
-import static org.junit.Assert.*
-import static org.mockito.Mockito.*
-
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
+import org.mockito.ArgumentCaptor
import org.mockito.MockitoAnnotations
import org.mockito.runners.MockitoJUnitRunner
import org.openecomp.mso.bpmn.core.WorkflowException
+import static org.assertj.core.api.Assertions.assertThat
+import static org.assertj.core.api.Assertions.assertThatThrownBy
+import static org.mockito.Matchers.eq
+import static org.mockito.Mockito.*
@RunWith(MockitoJUnitRunner.class)
class CompleteMsoProcessTest {
@@ -128,7 +129,7 @@ class CompleteMsoProcessTest {
when(mockExecution.getVariable("CMSO_mso-bpel-name")).thenReturn("BPEL")
when(mockExecution.getVariable("URN_mso_adapters_db_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC");
when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7");
-
+
CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess()
completeMsoProcess.setUpdateDBstatustoSuccessPayload(mockExecution)
@@ -145,29 +146,25 @@ class CompleteMsoProcessTest {
</sdncadapterworkflow:MsoCompletionResponse>"""
*/
@Test
- public void testbuildDataError(){
-
- boolean thrown = false;
- String msg = "Some-Message";
-
- ExecutionEntity mockExecution = mock(ExecutionEntity.class)
- when(mockExecution.getVariable("CMSO_mso-bpel-name")).thenReturn("BPEL-NAME")
- when(mockExecution.getVariable("testProcessKey")).thenReturn("CompleteMsoProcess")
-
- WorkflowException exception = new WorkflowException("CompleteMsoProcess", 500, msg);
-
- try{
- CompleteMsoProcess completeMsoProcess = new CompleteMsoProcess()
- completeMsoProcess.buildDataError(mockExecution, msg)
- }
- catch (BpmnError e){
- thrown = true;
- }
-
-
- verify(mockExecution).setVariable("CompleteMsoProcessResponse",msoCompletionResponse)
- // Can't seem to figure out how to verify the exception and have spent way too much time on fixing this test case!
- //verify(mockExecution).setVariable("WorkflowException",exception)
- assertTrue(thrown);
- }
+ void testBuildDataError() {
+ // given
+ def message = "Some-Message"
+
+ def mockExecution = mock ExecutionEntity.class
+ when mockExecution.getVariable("CMSO_mso-bpel-name") thenReturn "BPEL-NAME"
+ when mockExecution.getVariable("testProcessKey") thenReturn "CompleteMsoProcess"
+
+ def completeMsoProcess = new CompleteMsoProcess()
+ // when
+ assertThatThrownBy { completeMsoProcess.buildDataError(mockExecution, message) } isInstanceOf BpmnError
+ // then
+ verify mockExecution setVariable("CompleteMsoProcessResponse", msoCompletionResponse)
+ def argumentCaptor = ArgumentCaptor.forClass WorkflowException.class
+ verify mockExecution setVariable(eq("WorkflowException"), argumentCaptor.capture())
+ def capturedException = argumentCaptor.value
+
+ assertThat capturedException.processKey isEqualTo "CompleteMsoProcess"
+ assertThat capturedException.errorCode isEqualTo 500
+ assertThat capturedException.errorMessage isEqualTo message
+ }
} \ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/ResponseExceptionMapperImplTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/ResponseExceptionMapperImplTest.java
new file mode 100644
index 0000000000..8943014ad0
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/ResponseExceptionMapperImplTest.java
@@ -0,0 +1,111 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * 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.client;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Charsets;
+import javax.ws.rs.BadRequestException;
+import javax.ws.rs.ForbiddenException;
+import javax.ws.rs.InternalServerErrorException;
+import javax.ws.rs.NotAcceptableException;
+import javax.ws.rs.NotAllowedException;
+import javax.ws.rs.NotAuthorizedException;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.NotSupportedException;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.ClientResponseContext;
+import javax.ws.rs.core.Response.Status;
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(JUnitParamsRunner.class)
+public class ResponseExceptionMapperImplTest {
+
+ private static final ResponseExceptionMapperImpl mapper = new ResponseExceptionMapperImpl();
+
+ public static Object[][] statusesAndCorrespondingExceptions() {
+ return new Object[][]{
+ {Status.BAD_REQUEST, BadRequestException.class},
+ {Status.UNAUTHORIZED, NotAuthorizedException.class},
+ {Status.FORBIDDEN, ForbiddenException.class},
+ {Status.NOT_FOUND, NotFoundException.class},
+ {Status.METHOD_NOT_ALLOWED, NotAllowedException.class},
+ {Status.NOT_ACCEPTABLE, NotAcceptableException.class},
+ {Status.PRECONDITION_FAILED, PreconditionFailedException.class},
+ {Status.UNSUPPORTED_MEDIA_TYPE, NotSupportedException.class},
+ {Status.INTERNAL_SERVER_ERROR, InternalServerErrorException.class},
+ {Status.SERVICE_UNAVAILABLE, WebApplicationException.class},
+ {Status.BAD_GATEWAY, WebApplicationException.class},
+ };
+ }
+
+ @Test
+ @Parameters(method = "statusesAndCorrespondingExceptions")
+ public void shouldThrowExceptionWhenStatusIsNotOk(Status status, Class<Exception> expectedException) {
+ // given
+ ClientResponseContext responseContext = createMockResponseContext(status);
+ // when, then
+ assertThatThrownBy(() -> mapper.filter(null, responseContext)).isInstanceOf(expectedException);
+ }
+
+ @Test
+ public void shouldNotThrowExceptionWhenStatusIsOk() {
+ // given
+ ClientResponseContext responseContext = createMockResponseContext(Status.OK);
+ // when, then
+ assertThatCode(() -> mapper.filter(null, responseContext)).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void shouldThrowExceptionWithCustomMessageWhenResponseHasEntity() {
+ // given
+ ClientResponseContext responseContext = createMockResponseContext(Status.BAD_REQUEST);
+ when(responseContext.hasEntity()).thenReturn(true);
+ when(responseContext.getEntityStream()).thenReturn(IOUtils.toInputStream("test message", Charsets.UTF_8));
+ // when, then
+ assertThatThrownBy(() -> mapper.filter(null, responseContext)).isInstanceOf(BadRequestException.class)
+ .hasMessage("test message");
+ }
+
+ @Test
+ public void shouldThrowExceptionWithDefaultMessageWhenResponseHasNoEntity() {
+ // given
+ ClientResponseContext responseContext = createMockResponseContext(Status.BAD_REQUEST);
+ when(responseContext.hasEntity()).thenReturn(false);
+ // when, then
+ assertThatThrownBy(() -> mapper.filter(null, responseContext)).isInstanceOf(BadRequestException.class)
+ .hasMessage("empty message");
+ }
+
+ private static ClientResponseContext createMockResponseContext(Status status) {
+ ClientResponseContext responseContext = mock(ClientResponseContext.class);
+ when(responseContext.getStatusInfo()).thenReturn(status);
+ when(responseContext.getStatus()).thenReturn(status.getStatusCode());
+ return responseContext;
+ }
+} \ No newline at end of file