From 5a6a6de6f1a26a1897e4917a0df613e25a24eb70 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Mon, 30 Jul 2018 15:56:09 -0400 Subject: Containerization feature of SO Change-Id: I95381232eeefcd247a66a5cec370a8ce1c288e18 Issue-ID: SO-670 Signed-off-by: Benjamin, Max (mb388a) --- .../base/client/CloudifyBaseException.java | 43 +++ .../so/cloudify/base/client/CloudifyClient.java | 134 ++++++++ .../base/client/CloudifyClientConnector.java | 28 ++ .../base/client/CloudifyClientTokenProvider.java | 85 +++++ .../base/client/CloudifyConnectException.java | 39 +++ .../so/cloudify/base/client/CloudifyRequest.java | 188 +++++++++++ .../so/cloudify/base/client/CloudifyResponse.java | 39 +++ .../base/client/CloudifyResponseException.java | 61 ++++ .../base/client/CloudifyResponseStatus.java | 37 +++ .../base/client/CloudifySimpleTokenProvider.java | 40 +++ .../base/client/CloudifyTokenProvider.java | 29 ++ .../org/onap/so/cloudify/base/client/Entity.java | 71 ++++ .../onap/so/cloudify/base/client/HttpMethod.java | 25 ++ .../connector/http/HttpClientConnector.java | 245 ++++++++++++++ .../connector/http/HttpClientException.java | 42 +++ .../connector/http/HttpClientRedirectStrategy.java | 106 ++++++ .../connector/http/HttpClientResponse.java | 107 ++++++ .../so/cloudify/v3/client/BlueprintsResource.java | 103 ++++++ .../org/onap/so/cloudify/v3/client/Cloudify.java | 83 +++++ .../so/cloudify/v3/client/DeploymentsResource.java | 90 +++++ .../so/cloudify/v3/client/ExecutionsResource.java | 106 ++++++ .../cloudify/v3/client/NodeInstancesResource.java | 70 ++++ .../onap/so/cloudify/v3/client/TokensResource.java | 50 +++ .../org/onap/so/cloudify/v3/model/AzureConfig.java | 75 +++++ .../org/onap/so/cloudify/v3/model/Blueprint.java | 163 +++++++++ .../org/onap/so/cloudify/v3/model/Blueprints.java | 54 +++ .../cloudify/v3/model/CancelExecutionParams.java | 53 +++ .../onap/so/cloudify/v3/model/CloudifyError.java | 74 +++++ .../cloudify/v3/model/CreateDeploymentParams.java | 62 ++++ .../org/onap/so/cloudify/v3/model/Deployment.java | 365 +++++++++++++++++++++ .../so/cloudify/v3/model/DeploymentOutputs.java | 87 +++++ .../org/onap/so/cloudify/v3/model/Deployments.java | 54 +++ .../org/onap/so/cloudify/v3/model/Execution.java | 174 ++++++++++ .../org/onap/so/cloudify/v3/model/Executions.java | 54 +++ .../org/onap/so/cloudify/v3/model/Metadata.java | 57 ++++ .../onap/so/cloudify/v3/model/NodeInstance.java | 205 ++++++++++++ .../onap/so/cloudify/v3/model/NodeInstances.java | 54 +++ .../onap/so/cloudify/v3/model/OpenstackConfig.java | 89 +++++ .../org/onap/so/cloudify/v3/model/Pagination.java | 51 +++ .../so/cloudify/v3/model/ParameterDefinition.java | 58 ++++ .../so/cloudify/v3/model/StartExecutionParams.java | 98 ++++++ .../java/org/onap/so/cloudify/v3/model/Token.java | 67 ++++ .../cloudify/v3/model/UpdateExecutionParams.java | 50 +++ .../v3/model/UpdateNodeInstanceParams.java | 76 +++++ .../base/client/CloudifyBaseException.java | 43 --- .../mso/cloudify/base/client/CloudifyClient.java | 130 -------- .../base/client/CloudifyClientConnector.java | 28 -- .../base/client/CloudifyClientTokenProvider.java | 85 ----- .../base/client/CloudifyConnectException.java | 39 --- .../mso/cloudify/base/client/CloudifyRequest.java | 188 ----------- .../mso/cloudify/base/client/CloudifyResponse.java | 38 --- .../base/client/CloudifyResponseException.java | 61 ---- .../base/client/CloudifyResponseStatus.java | 37 --- .../base/client/CloudifySimpleTokenProvider.java | 40 --- .../base/client/CloudifyTokenProvider.java | 29 -- .../openecomp/mso/cloudify/base/client/Entity.java | 71 ---- .../mso/cloudify/base/client/HttpMethod.java | 25 -- .../connector/http/HttpClientConnector.java | 245 -------------- .../connector/http/HttpClientException.java | 42 --- .../connector/http/HttpClientRedirectStrategy.java | 106 ------ .../connector/http/HttpClientResponse.java | 107 ------ .../mso/cloudify/v3/client/BlueprintsResource.java | 103 ------ .../openecomp/mso/cloudify/v3/client/Cloudify.java | 83 ----- .../cloudify/v3/client/DeploymentsResource.java | 90 ----- .../mso/cloudify/v3/client/ExecutionsResource.java | 106 ------ .../cloudify/v3/client/NodeInstancesResource.java | 70 ---- .../mso/cloudify/v3/client/TokensResource.java | 50 --- .../mso/cloudify/v3/model/AzureConfig.java | 75 ----- .../openecomp/mso/cloudify/v3/model/Blueprint.java | 159 --------- .../mso/cloudify/v3/model/Blueprints.java | 54 --- .../cloudify/v3/model/CancelExecutionParams.java | 53 --- .../mso/cloudify/v3/model/CloudifyError.java | 74 ----- .../cloudify/v3/model/CreateDeploymentParams.java | 62 ---- .../mso/cloudify/v3/model/Deployment.java | 365 --------------------- .../mso/cloudify/v3/model/DeploymentOutputs.java | 87 ----- .../mso/cloudify/v3/model/Deployments.java | 54 --- .../openecomp/mso/cloudify/v3/model/Execution.java | 174 ---------- .../mso/cloudify/v3/model/Executions.java | 54 --- .../openecomp/mso/cloudify/v3/model/Metadata.java | 57 ---- .../mso/cloudify/v3/model/NodeInstance.java | 205 ------------ .../mso/cloudify/v3/model/NodeInstances.java | 54 --- .../mso/cloudify/v3/model/OpenstackConfig.java | 89 ----- .../mso/cloudify/v3/model/Pagination.java | 51 --- .../mso/cloudify/v3/model/ParameterDefinition.java | 58 ---- .../cloudify/v3/model/StartExecutionParams.java | 98 ------ .../org/openecomp/mso/cloudify/v3/model/Token.java | 67 ---- .../cloudify/v3/model/UpdateExecutionParams.java | 50 --- .../v3/model/UpdateNodeInstanceParams.java | 76 ----- .../java/org/onap/so/cloudify/BeanMultiTest.java | 63 ++++ .../cloudify/base/client/CloudifyClientTest.java | 103 ++++++ .../client/CloudifyClientTokenProviderTest.java | 56 ++++ .../connector/http/HttpClientConnectorTest.java | 254 ++++++++++++++ .../cloudify/v3/client/BlueprintsResourceTest.java | 147 +++++++++ .../v3/client/DeploymentsResourceTest.java | 148 +++++++++ .../cloudify/v3/client/ExecutionsResourceTest.java | 170 ++++++++++ .../v3/client/NodeInstancesResourceTest.java | 98 ++++++ .../org/openecomp/mso/cloudify/BeanMultiTest.java | 63 ---- .../cloudify/base/client/CloudifyClientTest.java | 103 ------ .../client/CloudifyClientTokenProviderTest.java | 56 ---- .../connector/http/HttpClientConnectorTest.java | 251 -------------- .../cloudify/v3/client/BlueprintsResourceTest.java | 147 --------- .../v3/client/DeploymentsResourceTest.java | 148 --------- .../cloudify/v3/client/ExecutionsResourceTest.java | 170 ---------- .../v3/client/NodeInstancesResourceTest.java | 98 ------ 104 files changed, 4880 insertions(+), 4868 deletions(-) create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyBaseException.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClient.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientConnector.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProvider.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyConnectException.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyRequest.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponse.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseException.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseStatus.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifySimpleTokenProvider.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyTokenProvider.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/Entity.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/base/client/HttpMethod.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientConnector.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientException.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategy.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientResponse.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/BlueprintsResource.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/Cloudify.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/DeploymentsResource.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/ExecutionsResource.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/NodeInstancesResource.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/TokensResource.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/AzureConfig.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprint.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprints.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CancelExecutionParams.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CloudifyError.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CreateDeploymentParams.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployment.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/DeploymentOutputs.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployments.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Execution.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Executions.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Metadata.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstance.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstances.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/OpenstackConfig.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Pagination.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/ParameterDefinition.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/StartExecutionParams.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Token.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateExecutionParams.java create mode 100644 cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateNodeInstanceParams.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyBaseException.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClient.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientConnector.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProvider.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyConnectException.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyRequest.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponse.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseException.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseStatus.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifySimpleTokenProvider.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyTokenProvider.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/Entity.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/HttpMethod.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientConnector.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientException.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientRedirectStrategy.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientResponse.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResource.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/Cloudify.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/DeploymentsResource.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResource.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/NodeInstancesResource.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/TokensResource.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/AzureConfig.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Blueprint.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Blueprints.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CancelExecutionParams.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CloudifyError.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CreateDeploymentParams.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Deployment.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/DeploymentOutputs.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Deployments.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Execution.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Executions.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Metadata.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/NodeInstance.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/NodeInstances.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/OpenstackConfig.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Pagination.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/ParameterDefinition.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/StartExecutionParams.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Token.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/UpdateExecutionParams.java delete mode 100644 cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/UpdateNodeInstanceParams.java create mode 100644 cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java create mode 100644 cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java create mode 100644 cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java create mode 100644 cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java create mode 100644 cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java create mode 100644 cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java create mode 100644 cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java create mode 100644 cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java delete mode 100644 cloudify-client/src/test/java/org/openecomp/mso/cloudify/BeanMultiTest.java delete mode 100644 cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTest.java delete mode 100644 cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProviderTest.java delete mode 100644 cloudify-client/src/test/java/org/openecomp/mso/cloudify/connector/http/HttpClientConnectorTest.java delete mode 100644 cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResourceTest.java delete mode 100644 cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/DeploymentsResourceTest.java delete mode 100644 cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResourceTest.java delete mode 100644 cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/NodeInstancesResourceTest.java (limited to 'cloudify-client/src') diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyBaseException.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyBaseException.java new file mode 100644 index 0000000000..a6e0cc3680 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyBaseException.java @@ -0,0 +1,43 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +/** + * A common abstract parent of all Openstack Exception types, allowing + * calling classes the choice to catch all error exceptions together. + */ +public abstract class CloudifyBaseException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + /* + * Implement only the basic constructors + */ + public CloudifyBaseException () {} + + public CloudifyBaseException(String message) { + super(message); + } + + public CloudifyBaseException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClient.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClient.java new file mode 100644 index 0000000000..8387557c24 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClient.java @@ -0,0 +1,134 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +import java.util.Properties; + +import org.onap.so.cloudify.connector.http.HttpClientConnector; + +public class CloudifyClient { + + protected String managerEndpoint; + protected String tenant = "default_tenant"; // Note - only default_tenant supported in community edition + + protected CloudifyTokenProvider tokenProvider; + + protected static int AUTHENTICATION_RETRIES = 1; + + protected CloudifyClientConnector connector; + + protected Properties properties = new Properties(); + + public CloudifyClient(String managerEndpoint) { + this.managerEndpoint = managerEndpoint; + this.connector = new HttpClientConnector(); + } + + public CloudifyClient(String managerEndpoint, String tenant) { + this.managerEndpoint = managerEndpoint; + this.tenant = tenant; + this.connector = new HttpClientConnector(); + } + + public CloudifyClient(String managerEndpoint, CloudifyClientConnector connector) { + this.managerEndpoint = managerEndpoint; + this.connector = connector; + } + + /** + * Execute a Cloudify request by making the REST API call. Return the + * complete CloudifyResponse structure, which includes the complete + * HTTP response. + * @param request a CloudifyRequest object + * @return a CloudifyResponse object + */ + public CloudifyResponse request(CloudifyRequest request) { + CloudifyResponseException authException = null; + + for (int i = 0; i <= AUTHENTICATION_RETRIES; i++) { + request.endpoint(managerEndpoint); + request.header("Tenant", tenant); + if (tokenProvider != null) + request.header("Authentication-Token", tokenProvider.getToken()); + + try { + return connector.request(request); + } catch (CloudifyResponseException e) { + if (e.getStatus() != CloudifyResponseStatus.NOT_AUTHORIZED + || tokenProvider == null) { + throw e; + } + authException = e; + tokenProvider.expireToken(); + } + } + + if (authException != null) { + throw authException; + } + + return null; + } + + /** + * Execute a CloudifyRequest by sending the REST API call to the Cloudify + * Manager endpoint. The return type is a JSON POJO object containing the + * response body entity. + * @param request + * @return a JSON POJO object specific to the request type + */ + public T execute(CloudifyRequest request) { + CloudifyResponse response = request(request); + return (request.returnType() != null && request.returnType() != Void.class) ? response.getEntity(request.returnType()) : null; + } + + public void property(String property, String value) { + properties.put(property, value); + } + + /** + * Set a Token Provider. This class should be able to produce an + * authentication token on-demand. + * @param tokenProvider + */ + public void setTokenProvider(CloudifyTokenProvider tokenProvider) { + this.tokenProvider = tokenProvider; + } + + /** + * Manually set the authentication token to use for this client. + * @param token + */ + public void setToken(String token) { + setTokenProvider(new CloudifySimpleTokenProvider(token)); + } + + /** + * Perform a simple GET request with no request message body + * @param path + * @param returnType + * @return An object of Class + */ + public CloudifyRequest get(String path, Class returnType) { + return new CloudifyRequest(this, HttpMethod.GET, path, null, returnType); + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientConnector.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientConnector.java new file mode 100644 index 0000000000..2e00c4c396 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientConnector.java @@ -0,0 +1,28 @@ +/*- + * ============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.onap.so.cloudify.base.client; + + +public interface CloudifyClientConnector { + + public CloudifyResponse request(CloudifyRequest request); + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProvider.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProvider.java new file mode 100644 index 0000000000..7676afa6c7 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProvider.java @@ -0,0 +1,85 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +import java.util.Date; + +import org.apache.commons.lang.time.DateUtils; + +import org.onap.so.cloudify.v3.client.Cloudify; +import org.onap.so.cloudify.v3.client.TokensResource.GetToken; +import org.onap.so.cloudify.v3.model.Token; + +/** + * Cloudify Token Provider that uses the Cloudify client API itself to obtain a token + * + * @author JC1348 + * + */ +public class CloudifyClientTokenProvider implements CloudifyTokenProvider { + + String user; + String password; + String token; + Date expiration; + Cloudify cloudify = null; + + public CloudifyClientTokenProvider(String cloudifyEndpoint, String user, String password) { + this.user = user; + this.password = password; + + cloudify = new Cloudify (cloudifyEndpoint); + } + + @Override + public String getToken() { + Date now = new Date(); + if (token != null && expiration != null && expiration.after(now)) { + return token; + } + + // Create a "Get Token" request. Force basic authentication to acquire the token itself. + GetToken tokenRequest = cloudify.tokens().token(); + tokenRequest.setBasicAuthentication(user, password); + Token newToken = tokenRequest.execute(); + + token = newToken.getValue(); + + if (expiration == null) { + expiration = new Date(); + } + // TODO: Make this property driven (or see if it comes back somehow in response) + expiration = DateUtils.addMinutes(expiration, 10); + + return token; + } + + @Override + /** + * This doesn't actually expire the token in Cloudify. It just prevents this token provider + * from using it. + */ + public void expireToken() { + expiration = null; + token = null; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyConnectException.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyConnectException.java new file mode 100644 index 0000000000..3f378fd10f --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyConnectException.java @@ -0,0 +1,39 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +/** + * Custom RuntimeException to report connection errors to Openstack endpoints. + * Must be a RuntimeException to conform with OpenstackClient interface, which + * does not declare specific Exceptions. + */ +public class CloudifyConnectException extends CloudifyBaseException { + + private static final long serialVersionUID = 7294957362769575271L; + + public CloudifyConnectException(String message) { + super(message); + } + + public CloudifyConnectException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyRequest.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyRequest.java new file mode 100644 index 0000000000..ffa89fe4a3 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyRequest.java @@ -0,0 +1,188 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; + +public class CloudifyRequest { + + private CloudifyClient client; + + public CloudifyRequest() { + + } + + public CloudifyRequest(CloudifyClient client, HttpMethod method, CharSequence path, Entity entity, Class returnType) { + this.client = client; + this.method = method; + this.path = new StringBuilder(path); + this.entity = entity; + this.returnType = returnType; + header("Accept", "application/json"); + } + + private String endpoint; + + private HttpMethod method; + + private StringBuilder path = new StringBuilder(); + + private Map> headers = new HashMap>(); + + private Entity entity; + + private Class returnType; + + private boolean basicAuth = false; + private String user = null; + private String password = null; + + public CloudifyRequest endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + public String endpoint() { + return endpoint; + } + + public CloudifyRequest method(HttpMethod method) { + this.method = method; + return this; + } + + public HttpMethod method() { + return method; + } + + public CloudifyRequest path(String path) { + this.path.append(path); + return this; + } + + public String path() { + return path.toString(); + } + + public CloudifyRequest header(String name, Object value) { + if(value != null) { + headers.put(name, Arrays.asList(value)); + } + return this; + } + + public Map> headers() { + return headers; + } + + public Entity entity(T entity, String contentType) { + return new Entity(entity, contentType); + } + + public Entity entity() { + return entity; + } + + public Entity json(T entity) { + return entity(entity, "application/json"); + } + + public void returnType(Class returnType) { + this.returnType = returnType; + } + + public Class returnType() { + return returnType; + } + + /* + * Use Basic Authentication for this request. If not set, the client will use Token authentication + * if a token provider is defined. Otherwise, no authentication will be applied. + */ + public void setBasicAuthentication (String user, String password) { + this.basicAuth = true; + this.user = user; + this.password= password; + } + + public boolean isBasicAuth () { + return this.basicAuth; + } + + public String getUser() { + return user; + } + + public String getPassword() { + return password; + } + + public R execute() { + return client.execute(this); + } + + public CloudifyResponse request() { + return client.request(this); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "CloudifyRequest [endpoint=" + endpoint + ", method=" + method + + ", path=" + path + ", headers=" + headers + ", entity=" + + entity + ", returnType=" + returnType + "]"; + } + + private Map > queryParams = new LinkedHashMap >(); + + public Map > queryParams() { + return queryParams; + } + + public CloudifyRequest queryParam(String key, Object value) { + if (queryParams.containsKey(key)) { + List values = queryParams.get(key); + values.add(value); + } else { + List values = new ArrayList(); + values.add(value); + queryParams.put(key, values); + } + + return this; + } + + protected static String buildPath(String ... elements) { + StringBuilder stringBuilder = new StringBuilder(); + for (String element : elements) { + stringBuilder.append(element); + } + + return stringBuilder.toString(); + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponse.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponse.java new file mode 100644 index 0000000000..2d920734b5 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponse.java @@ -0,0 +1,39 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +import java.io.InputStream; +import java.io.Serializable; +import java.util.Map; + +public interface CloudifyResponse extends Serializable{ + + public T getEntity(Class returnType); + + public T getErrorEntity(Class returnType); + + public InputStream getInputStream(); + + public String getHeader(String name); + + public Map headers(); + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseException.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseException.java new file mode 100644 index 0000000000..f7c42d3957 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseException.java @@ -0,0 +1,61 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +import org.onap.so.cloudify.v3.model.CloudifyError; + +public class CloudifyResponseException extends CloudifyBaseException { + + private static final long serialVersionUID = 7294957362769575271L; + + protected String message; + protected int status; + + // Make the response available for exception handling (includes body) + protected CloudifyResponse response; + + public CloudifyResponseException(String message, int status) { + this.message = message; + this.status = status; + this.response = null; + } + + // Include the response message itself. The body is a CloudifyError JSON structure. + public CloudifyResponseException(String message, int status, CloudifyResponse response) { + CloudifyError error = response.getErrorEntity(CloudifyError.class); + this.message = message + ": " + error.getErrorCode(); + this.status = status; + this.response = response; + } + + public String getMessage() { + return message; + } + + public int getStatus() { + return status; + } + + public CloudifyResponse getResponse() { + return response; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseStatus.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseStatus.java new file mode 100644 index 0000000000..af6940c041 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseStatus.java @@ -0,0 +1,37 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +public class CloudifyResponseStatus { + + public static final int OK = 200; + + public static final int ACCEPTED = 201; + + public static final int BAD_REQUEST = 400; + + public static final int NOT_AUTHORIZED = 401; + + public static final int NOT_FOUND = 404; + + public static final int CONFLICT = 409; + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifySimpleTokenProvider.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifySimpleTokenProvider.java new file mode 100644 index 0000000000..074d164b48 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifySimpleTokenProvider.java @@ -0,0 +1,40 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +public class CloudifySimpleTokenProvider implements CloudifyTokenProvider { + + String token; + + public CloudifySimpleTokenProvider(String token) { + this.token = token; + } + + @Override + public String getToken() { + return this.token; + } + + @Override + public void expireToken() { + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyTokenProvider.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyTokenProvider.java new file mode 100644 index 0000000000..8915a0393b --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyTokenProvider.java @@ -0,0 +1,29 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +public interface CloudifyTokenProvider { + + String getToken(); + + void expireToken(); + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/Entity.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/Entity.java new file mode 100644 index 0000000000..15a913a4c4 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/Entity.java @@ -0,0 +1,71 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +public class Entity { + + private T entity; + + private String contentType; + + public static Entity json(T entity) { + return new Entity(entity, "application/json"); + } + + public static Entity stream(T entity) { + return new Entity(entity, "application/octet-stream"); + } + + public Entity(T entity, String contentType) { + super(); + this.entity = entity; + this.contentType = contentType; + } + + /** + * @return the entity + */ + public T getEntity() { + return entity; + } + + /** + * @param entity the entity to set + */ + public void setEntity(T entity) { + this.entity = entity; + } + + /** + * @return the contentType + */ + public String getContentType() { + return contentType; + } + + /** + * @param contentType the contentType to set + */ + public void setContentType(String contentType) { + this.contentType = contentType; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/HttpMethod.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/HttpMethod.java new file mode 100644 index 0000000000..aa991dfcf8 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/HttpMethod.java @@ -0,0 +1,25 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +public enum HttpMethod { + HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientConnector.java b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientConnector.java new file mode 100644 index 0000000000..a10945e855 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientConnector.java @@ -0,0 +1,245 @@ +/*- + * ============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.onap.so.cloudify.connector.http; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.UnknownHostException; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.HttpResponseException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.InputStreamEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.onap.so.cloudify.base.client.CloudifyClientConnector; +import org.onap.so.cloudify.base.client.CloudifyConnectException; +import org.onap.so.cloudify.base.client.CloudifyRequest; +import org.onap.so.cloudify.base.client.CloudifyResponse; +import org.onap.so.cloudify.base.client.CloudifyResponseException; +import org.onap.so.logger.MsoLogger; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonRootName; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +public class HttpClientConnector implements CloudifyClientConnector { + + public static ObjectMapper DEFAULT_MAPPER; + public static ObjectMapper WRAPPED_MAPPER; + + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, HttpClientConnector.class); + + static { + DEFAULT_MAPPER = new ObjectMapper(); + + DEFAULT_MAPPER.setSerializationInclusion(Include.NON_NULL); + DEFAULT_MAPPER.disable(SerializationFeature.INDENT_OUTPUT); + DEFAULT_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + DEFAULT_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + + WRAPPED_MAPPER = new ObjectMapper(); + + WRAPPED_MAPPER.setSerializationInclusion(Include.NON_NULL); + WRAPPED_MAPPER.disable(SerializationFeature.INDENT_OUTPUT); + WRAPPED_MAPPER.enable(SerializationFeature.WRAP_ROOT_VALUE); + WRAPPED_MAPPER.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); + WRAPPED_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + WRAPPED_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + } + + protected static ObjectMapper getObjectMapper (Class type) { + return type.getAnnotation(JsonRootName.class) == null ? DEFAULT_MAPPER : WRAPPED_MAPPER; + } + + public CloudifyResponse request(CloudifyRequest request) { + + CloseableHttpClient httpClient = null; //HttpClients.createDefault(); + + if (request.isBasicAuth()) { + // Use Basic Auth for this request. + CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials(AuthScope.ANY, + new UsernamePasswordCredentials (request.getUser(), request.getPassword())); + + httpClient = HttpClients.custom().setRedirectStrategy(new HttpClientRedirectStrategy()).setDefaultCredentialsProvider(credentialsProvider).build(); + } + else { + // Don't use basic authentication. The Client will attempt Token-based authentication + httpClient = HttpClients.custom().setRedirectStrategy(new HttpClientRedirectStrategy()).build(); + } + + URI uri = null; + + // Build the URI with query params + try { + URIBuilder uriBuilder = new URIBuilder(request.endpoint() + request.path()); + + for(Map.Entry > entry : request.queryParams().entrySet()) { + for (Object o : entry.getValue()) { + uriBuilder.setParameter(entry.getKey(), String.valueOf(o)); + } + } + + uri = uriBuilder.build(); + } catch (URISyntaxException e) { + throw new HttpClientException (e); + } + + HttpEntity entity = null; + if (request.entity() != null) { + // Special handling for streaming input + if (request.entity().getEntity() instanceof InputStream) { + // Entity is an InputStream + entity = new InputStreamEntity ((InputStream) request.entity().getEntity()); + } + else { + // Assume to be JSON. Flatten the entity to a Json string + try { + // Get appropriate mapper, based on existence of a root element in Entity class + ObjectMapper mapper = getObjectMapper (request.entity().getEntity().getClass()); + + String entityJson = mapper.writeValueAsString (request.entity().getEntity()); + entity = new StringEntity(entityJson, ContentType.create(request.entity().getContentType())); + + LOGGER.debug ("Request JSON Body: " + entityJson.replaceAll("\"password\":\"[^\"]*\"", "\"password\":\"***\"")); + + } catch (JsonProcessingException e) { + throw new HttpClientException ("Json processing error on request entity", e); + } catch (IOException e) { + throw new HttpClientException ("Json IO error on request entity", e); + } + } + } + + // Determine the HttpRequest class based on the method + HttpUriRequest httpRequest; + + switch (request.method()) { + case POST: + HttpPost post = new HttpPost(uri); + post.setEntity (entity); + httpRequest = post; + break; + + case GET: + httpRequest = new HttpGet(uri); + break; + + case PUT: + HttpPut put = new HttpPut(uri); + put.setEntity (entity); + httpRequest = put; + break; + + case DELETE: + httpRequest = new HttpDelete(uri); + break; + + default: + throw new HttpClientException ("Unrecognized HTTP Method: " + request.method()); + } + + for (Entry> h : request.headers().entrySet()) { + StringBuilder sb = new StringBuilder(); + for (Object v : h.getValue()) { + sb.append(String.valueOf(v)); + } + httpRequest.addHeader(h.getKey(), sb.toString()); + } + + // Get the Response. But don't get the body entity yet, as this response + // will be wrapped in an HttpClientResponse. The HttpClientResponse + // buffers the body in constructor, so can close the response here. + HttpClientResponse httpClientResponse = null; + CloseableHttpResponse httpResponse = null; + + // Catch known HttpClient exceptions, and wrap them in OpenStack Client Exceptions + // so calling functions can distinguish. Only RuntimeExceptions are allowed. + try { + httpResponse = httpClient.execute(httpRequest); + + LOGGER.debug ("Response status: " + httpResponse.getStatusLine().getStatusCode()); + + httpClientResponse = new HttpClientResponse (httpResponse); + + int status = httpResponse.getStatusLine().getStatusCode(); + if (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || + status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_ACCEPTED) + { + return httpClientResponse; + } + } + catch (HttpResponseException e) { + // What exactly does this mean? It does not appear to get thrown for + // non-2XX responses as documented. + throw new CloudifyResponseException(e.getMessage(), e.getStatusCode()); + } + catch (UnknownHostException e) { + throw new CloudifyConnectException("Unknown Host: " + e.getMessage()); + } + catch (IOException e) { + // Catch all other IOExceptions and throw as OpenStackConnectException + throw new CloudifyConnectException(e.getMessage()); + } + catch (Exception e) { + // Catchall for anything else, must throw as a RuntimeException + LOGGER.error("Client exception", e); + throw new RuntimeException("Unexpected client exception", e); + } + finally { + // Have the body. Close the stream + if (httpResponse != null) + try { + httpResponse.close(); + } catch (IOException e) { + LOGGER.debug("Unable to close HTTP Response: " + e); + } + } + + // Get here on an error response (4XX-5XX) + throw new CloudifyResponseException(httpResponse.getStatusLine().getReasonPhrase(), + httpResponse.getStatusLine().getStatusCode(), + httpClientResponse); + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientException.java b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientException.java new file mode 100644 index 0000000000..eb967af996 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientException.java @@ -0,0 +1,42 @@ +/*- + * ============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.onap.so.cloudify.connector.http; + +/* + * Declare a RuntimeException since the Interface does not declare any + * throwables. Any caught exception will be wrapped in HttpClientException + */ +public class HttpClientException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public HttpClientException (String s) { + super (s); + } + + public HttpClientException (Exception e) { + super ("Caught nested exception in HttpClient", e); + } + + public HttpClientException (String s, Exception e) { + super (s, e); + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategy.java b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategy.java new file mode 100644 index 0000000000..a7575ff499 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategy.java @@ -0,0 +1,106 @@ +/*- + * ============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.onap.so.cloudify.connector.http; + +import java.net.URI; + +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.ProtocolException; +import org.apache.http.annotation.Immutable; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpHead; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.methods.RequestBuilder; +import org.apache.http.impl.client.DefaultRedirectStrategy; +import org.apache.http.protocol.HttpContext; + +/** + * Custom {@link org.apache.http.client.RedirectStrategy} implementation + * that automatically redirects all HEAD, GET and DELETE requests. + * The {@link org.apache.http.client.DefaultRedirectStrategy} only + * redirects GET and HEAD automatically, per the HTTP specification + * (POST and PUT typically have bodies and thus cannot be redirected). + * + * A custom strategy is needed for the Openstack API, which can also send + * 302 on a DELETE (by name) request, expecting the client to follow the + * redirect to perform the actual deletion. + */ +@Immutable +public class HttpClientRedirectStrategy extends DefaultRedirectStrategy { + + /** + * Redirectable methods. + */ + private static final String[] REDIRECT_METHODS = new String[] { + HttpGet.METHOD_NAME, + HttpDelete.METHOD_NAME, + HttpHead.METHOD_NAME + }; + + /** + * Determine if the request should be redirected. + * This may not actually be needed, since the REDIRECT_METHODS + * array has been updated with the DELETE. + */ + @Override + protected boolean isRedirectable(final String method) { + for (final String m: REDIRECT_METHODS) { + if (m.equalsIgnoreCase(method)) { + return true; + } + } + return false; + } + + /** + * Override the default redirect handling method. As implemented + * in HttpClient, it does not preserve the method on 301 or 302 + * responses, always redirecting to a GET. + */ + @Override + public HttpUriRequest getRedirect( + final HttpRequest request, + final HttpResponse response, + final HttpContext context) throws ProtocolException { + + final URI uri = getLocationURI(request, response, context); + final String method = request.getRequestLine().getMethod(); + if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) { + return new HttpHead(uri); + } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) { + return new HttpGet(uri); + } else { + + final int status = response.getStatusLine().getStatusCode(); + + HttpUriRequest newRequest = null; + if (status == HttpStatus.SC_TEMPORARY_REDIRECT || status == HttpStatus.SC_MOVED_TEMPORARILY) { + newRequest = RequestBuilder.copy(request).setUri(uri).build(); + } else { + newRequest = new HttpGet(uri); + } + return newRequest; + } + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientResponse.java b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientResponse.java new file mode 100644 index 0000000000..0c1743fc5f --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientResponse.java @@ -0,0 +1,107 @@ +/*- + * ============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.onap.so.cloudify.connector.http; + +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.onap.so.cloudify.base.client.CloudifyResponse; +import org.onap.so.logger.MsoLogger; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +public class HttpClientResponse implements CloudifyResponse { + + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, HttpClientResponse.class); + + private HttpResponse response = null; + private String entityBody = null; + + public HttpClientResponse(HttpResponse response) + { + this.response = response; + + // Read the body so InputStream can be closed + if (response.getEntity() == null) { + // No body + LOGGER.debug ("No Response Body"); + return; + } + + ByteArrayOutputStream responseBody = new ByteArrayOutputStream(); + try { + response.getEntity().writeTo(responseBody); + } catch (IOException e) { + throw new HttpClientException ("Error Reading Response Body", e); + } + entityBody = responseBody.toString(); + LOGGER.debug (entityBody); + } + + + @Override + public T getEntity (Class returnType) { + // Get appropriate mapper, based on existence of a root element + ObjectMapper mapper = HttpClientConnector.getObjectMapper (returnType); + + T resp = null; + try { + resp = mapper.readValue(entityBody, returnType); + } catch (Exception e) { + throw new HttpClientException ("Caught exception in getEntity", e); + } + return resp; + } + + @Override + public T getErrorEntity(Class returnType) { + return getEntity(returnType); + } + + @Override + public InputStream getInputStream() { + return new ByteArrayInputStream (entityBody.getBytes()); + } + + @Override + public String getHeader(String name) { + return response.getFirstHeader(name).getValue(); + } + + @Override + public Map headers() { + Map headers = new HashMap(); + + Header responseHeaders[] = response.getAllHeaders(); + for (Header h : responseHeaders) { + headers.put(h.getName(), h.getValue()); + } + + return headers; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/BlueprintsResource.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/BlueprintsResource.java new file mode 100644 index 0000000000..03c130e4c5 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/BlueprintsResource.java @@ -0,0 +1,103 @@ +/*- + * ============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.onap.so.cloudify.v3.client; + +import java.io.InputStream; + +import org.onap.so.cloudify.v3.model.Blueprint; +import org.onap.so.cloudify.v3.model.Blueprints; +import org.onap.so.cloudify.base.client.Entity; +import org.onap.so.cloudify.base.client.HttpMethod; +import org.onap.so.cloudify.base.client.CloudifyClient; +import org.onap.so.cloudify.base.client.CloudifyRequest; + +public class BlueprintsResource { + + private final CloudifyClient client; + + public BlueprintsResource(CloudifyClient client) { + this.client = client; + } + + /* + * Upload a blueprint package directly. The blueprint must be a ZIP archive. + * However, this method will not validate this. + */ + public UploadBlueprint uploadFromStream (String blueprintId, String mainFileName, InputStream blueprint) { + return new UploadBlueprint (blueprintId, mainFileName, blueprint, null); + } + + public UploadBlueprint uploadFromUrl (String blueprintId, String mainFileName, String blueprintUrl) { + return new UploadBlueprint (blueprintId, mainFileName, null, blueprintUrl); + } + + public ListBlueprints list() { + return new ListBlueprints(); + } + + public GetBlueprint getById(String id) { + return new GetBlueprint(id, ""); + } + + // Return all of the metadata, but not the plan + public GetBlueprint getMetadataById(String id) { + return new GetBlueprint(id, "?_include=id,main_file_name,description,tenant_name,created_at,updated_at"); + } + + public DeleteBlueprint deleteById(String id) { + return new DeleteBlueprint(id); + } + + public class UploadBlueprint extends CloudifyRequest { + public UploadBlueprint(String blueprintId, String mainFileName, InputStream blueprint, String blueprintUrl) { + // Initialize the request elements dynamically. + // Either a blueprint input stream or a URL will be provided. + // If a URL is provided, add it to the query string + // If a Stream is provided, set it as the Entity body + super(client, HttpMethod.PUT, + "/api/v3/blueprints/" + blueprintId + "?application_file_name=" + mainFileName + ((blueprintUrl != null) ? "&blueprint_archive=" + blueprintUrl : ""), + ((blueprint != null) ? Entity.stream(blueprint) : null), + Blueprint.class); + } + } + + public class DeleteBlueprint extends CloudifyRequest { + public DeleteBlueprint(String blueprintId) { + super(client, HttpMethod.DELETE, "/api/v3/blueprints/" + blueprintId, null, Blueprint.class); + } + } + + public class GetBlueprint extends CloudifyRequest { + public GetBlueprint(String id, String queryArgs) { + super(client, HttpMethod.GET, "/api/v3/blueprints/" + id + queryArgs, null, Blueprint.class); + } + } + + public class ListBlueprints extends CloudifyRequest { + public ListBlueprints() { + super(client, HttpMethod.GET, "/api/v3/blueprints", null, Blueprints.class); + } + } + + // TODO: DownloadBlueprint is not supported, as it needs to return an input stream + // containing the full blueprint ZIP. + // For a full client library, this will require returning an open stream as the entity... +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/Cloudify.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/Cloudify.java new file mode 100644 index 0000000000..cd47e1937a --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/Cloudify.java @@ -0,0 +1,83 @@ +/*- + * ============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.onap.so.cloudify.v3.client; + +import org.onap.so.cloudify.base.client.CloudifyClient; +import org.onap.so.cloudify.base.client.CloudifyClientConnector; + +/** + * Reference: http://docs.getcloudify.org/api/v3/ + */ +public class Cloudify extends CloudifyClient { + + private final DeploymentsResource deployments; + private final BlueprintsResource blueprints; + private final TokensResource tokens; + private final NodeInstancesResource nodeInstances; + private final ExecutionsResource executions; + +/* Not supporting dynamic connectors + public Cloudify(String endpoint, CloudifyClientConnector connector) { + super(endpoint, connector); + deployments = new DeploymentsResource(this); + blueprints = new BlueprintsResource(this); + nodeInstances = new NodeInstancesResource(this); + tokens = new TokensResource(this); + } +*/ + public Cloudify(String endpoint, String tenant) { + super(endpoint, tenant); + deployments = new DeploymentsResource(this); + blueprints = new BlueprintsResource(this); + nodeInstances = new NodeInstancesResource(this); + executions = new ExecutionsResource(this); + tokens = new TokensResource(this); + } + + public Cloudify(String endpoint) { + super(endpoint); + deployments = new DeploymentsResource(this); + blueprints = new BlueprintsResource(this); + nodeInstances = new NodeInstancesResource(this); + executions = new ExecutionsResource(this); + tokens = new TokensResource(this); + } + + public DeploymentsResource deployments() { + return this.deployments; + } + + public BlueprintsResource blueprints() { + return this.blueprints; + } + + public NodeInstancesResource nodeInstances() { + return this.nodeInstances; + } + + public ExecutionsResource executions() { + return this.executions; + } + + public TokensResource tokens() { + return this.tokens; + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/DeploymentsResource.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/DeploymentsResource.java new file mode 100644 index 0000000000..1160bee420 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/DeploymentsResource.java @@ -0,0 +1,90 @@ +/*- + * ============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.onap.so.cloudify.v3.client; + +import org.onap.so.cloudify.v3.model.CreateDeploymentParams; +import org.onap.so.cloudify.v3.model.Deployment; +import org.onap.so.cloudify.v3.model.DeploymentOutputs; +import org.onap.so.cloudify.v3.model.Deployments; +import org.onap.so.cloudify.base.client.Entity; +import org.onap.so.cloudify.base.client.HttpMethod; +import org.onap.so.cloudify.base.client.CloudifyClient; +import org.onap.so.cloudify.base.client.CloudifyRequest; + +public class DeploymentsResource { + + private final CloudifyClient client; + + public DeploymentsResource(CloudifyClient client) { + this.client = client; + } + + public CreateDeployment create(String deploymentId, CreateDeploymentParams body) { + return new CreateDeployment(deploymentId, body); + } + + public ListDeployments list() { + return new ListDeployments(); + } + + public GetDeployment byId(String id) { + return new GetDeployment(id); + } + + public GetDeploymentOutputs outputsById(String id) { + return new GetDeploymentOutputs(id); + } + + public DeleteDeployment deleteByName(String name) { + return new DeleteDeployment(name); + } + + public class CreateDeployment extends CloudifyRequest { + public CreateDeployment(String deploymentId, CreateDeploymentParams body) { + super(client, HttpMethod.PUT, "/api/v3/deployments/" + deploymentId, Entity.json(body), Deployment.class); + } + } + + public class DeleteDeployment extends CloudifyRequest { + public DeleteDeployment(String deploymentId) { + super(client, HttpMethod.DELETE, "/api/v3/deployments/" + deploymentId, null, Deployment.class); + } + } + + public class GetDeployment extends CloudifyRequest { + public GetDeployment(String id) { + super(client, HttpMethod.GET, "/api/v3/deployments/" + id, null, Deployment.class); + } + } + + public class GetDeploymentOutputs extends CloudifyRequest { + public GetDeploymentOutputs(String id) { + super(client, HttpMethod.GET, "/api/v3/deployments/" + id + "/outputs", null, DeploymentOutputs.class); + } + } + + public class ListDeployments extends CloudifyRequest { + public ListDeployments() { + super(client, HttpMethod.GET, "/api/v3/deployments", null, Deployments.class); + } + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/ExecutionsResource.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/ExecutionsResource.java new file mode 100644 index 0000000000..6057fbba97 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/ExecutionsResource.java @@ -0,0 +1,106 @@ +/*- + * ============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.onap.so.cloudify.v3.client; + +import org.onap.so.cloudify.v3.model.CancelExecutionParams; +import org.onap.so.cloudify.v3.model.Execution; +import org.onap.so.cloudify.v3.model.Executions; +import org.onap.so.cloudify.v3.model.StartExecutionParams; +import org.onap.so.cloudify.v3.model.UpdateExecutionParams; +import org.onap.so.cloudify.base.client.Entity; +import org.onap.so.cloudify.base.client.HttpMethod; +import org.onap.so.cloudify.base.client.CloudifyClient; +import org.onap.so.cloudify.base.client.CloudifyRequest; + +public class ExecutionsResource { + + private final CloudifyClient client; + + public ExecutionsResource(CloudifyClient client) { + this.client = client; + } + + public ListExecutions list() { + return new ListExecutions(null); + } + + public ListExecutions listSorted (String sortBy) { + return new ListExecutions("?_sort=" + sortBy); + } + + // Return a filtered list. + // The filter parameter should be a query string of filter criteria (without leading "?") + public ListExecutions listFiltered (String filter, String sortBy) { + String listParams = "?" + filter; + if (sortBy != null) listParams += "&_sort=" + sortBy; + return new ListExecutions(listParams); + } + + public GetExecution byId(String id) { + return new GetExecution(id); + } + + public StartExecution start(StartExecutionParams params) { + return new StartExecution(params); + } + + public UpdateExecution updateStatus(String id, String status) { + UpdateExecutionParams params = new UpdateExecutionParams(); + params.setStatus(status); + return new UpdateExecution(id, params); + } + + public CancelExecution cancel(String executionId, CancelExecutionParams params) { + return new CancelExecution(executionId, params); + } + + + public class GetExecution extends CloudifyRequest { + public GetExecution (String id) { + super(client, HttpMethod.GET, "/api/v3/executions/" + id, null, Execution.class); + } + } + + public class ListExecutions extends CloudifyRequest { + public ListExecutions(String listParams) { + super(client, HttpMethod.GET, "/api/v3/executions" + ((listParams!=null) ? listParams : ""), null, Executions.class); + } + } + + public class StartExecution extends CloudifyRequest { + public StartExecution(StartExecutionParams body) { + super(client, HttpMethod.POST, "/api/v3/executions", Entity.json(body), Execution.class); + } + } + + public class UpdateExecution extends CloudifyRequest { + public UpdateExecution(String executionId, UpdateExecutionParams body) { + super(client, HttpMethod.PATCH, "/api/v3/executions/" + executionId, Entity.json(body), Execution.class); + } + } + + public class CancelExecution extends CloudifyRequest { + public CancelExecution(String executionId, CancelExecutionParams body) { + super(client, HttpMethod.POST, "/api/v3/executions/" + executionId, Entity.json(body), Execution.class); + } + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/NodeInstancesResource.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/NodeInstancesResource.java new file mode 100644 index 0000000000..801ced6ef7 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/NodeInstancesResource.java @@ -0,0 +1,70 @@ +/*- + * ============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.onap.so.cloudify.v3.client; + +import org.onap.so.cloudify.v3.model.UpdateNodeInstanceParams; +import org.onap.so.cloudify.v3.model.NodeInstance; +import org.onap.so.cloudify.v3.model.NodeInstances; +import org.onap.so.cloudify.base.client.Entity; +import org.onap.so.cloudify.base.client.HttpMethod; +import org.onap.so.cloudify.base.client.CloudifyClient; +import org.onap.so.cloudify.base.client.CloudifyRequest; + +public class NodeInstancesResource { + + private final CloudifyClient client; + + public NodeInstancesResource(CloudifyClient client) { + this.client = client; + } + + public ListNodeInstances list() { + return new ListNodeInstances(); + } + + public GetNodeInstance byId(String id) { + return new GetNodeInstance(id); + } + + public UpdateNodeInstance update(String id, UpdateNodeInstanceParams params) { + return new UpdateNodeInstance(id, params); + } + + + public class GetNodeInstance extends CloudifyRequest { + public GetNodeInstance (String id) { + super(client, HttpMethod.GET, "/api/v3/node-instances/" + id, null, NodeInstance.class); + } + } + + public class ListNodeInstances extends CloudifyRequest { + public ListNodeInstances() { + super(client, HttpMethod.GET, "/api/v3/node-instances", null, NodeInstances.class); + } + } + + public class UpdateNodeInstance extends CloudifyRequest { + public UpdateNodeInstance(String nodeInstanceId, UpdateNodeInstanceParams body) { + super(client, HttpMethod.PATCH, "/api/v3/node-instances/" + nodeInstanceId, Entity.json(body), NodeInstance.class); + } + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/TokensResource.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/TokensResource.java new file mode 100644 index 0000000000..3ef2ef2bb9 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/TokensResource.java @@ -0,0 +1,50 @@ +/*- + * ============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.onap.so.cloudify.v3.client; + +import org.onap.so.cloudify.v3.model.Token; +import org.onap.so.cloudify.base.client.HttpMethod; +import org.onap.so.cloudify.base.client.CloudifyClient; +import org.onap.so.cloudify.base.client.CloudifyRequest; + +public class TokensResource { + + private final CloudifyClient client; + + public TokensResource(CloudifyClient client) { + this.client = client; + } + + /* + * Get a new token for a user + * TODO: User ID/Password logic need to be in the Client. + * Results of a token query should also be able to add to the Client + */ + public GetToken token() { + return new GetToken(); + } + + public class GetToken extends CloudifyRequest { + public GetToken() { + super(client, HttpMethod.GET, "/api/v3/tokens", null, Token.class); + } + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/AzureConfig.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/AzureConfig.java new file mode 100644 index 0000000000..29f2d1a8ce --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/AzureConfig.java @@ -0,0 +1,75 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class AzureConfig implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("subscription_id") + String subscriptionId; + + @JsonProperty("tenant_id") + String tenantId; + + @JsonProperty("client_id") + String clientId; + + @JsonProperty("client_secret") + String clientSecret; + + public String getSubscriptionId() { + return subscriptionId; + } + + public void setSubscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getClientSecret() { + return clientSecret; + } + + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } + +} \ No newline at end of file diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprint.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprint.java new file mode 100644 index 0000000000..ef2a258b9e --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprint.java @@ -0,0 +1,163 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Date; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; + +@JsonIgnoreProperties(ignoreUnknown = true) +//@JsonRootName("blueprint") +public class Blueprint implements Serializable { + + + /** + * + */ + private static final long serialVersionUID = 938604986548763151L; + + @JsonProperty("created_at") + private Date createdAt; + + @JsonProperty("description") + private String description; + + @JsonProperty("id") + private String id; + + @JsonProperty("main_file_name") + private String mainFileName; + + @JsonProperty("plan") + private Map plan = null; + + @JsonProperty("tenant_name") + private String tenantName; + + @JsonProperty("updated_at") + private Date updatedAt; + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getMainFileName() { + return mainFileName; + } + + public void setMainFileName(String mainFileName) { + this.mainFileName = mainFileName; + } + + public Map getPlan() { + return this.plan; + } + + public void setPlan(Map plan) { + this.plan = plan; + } + + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + + + /* + * Return an output as a Json-mapped Object of the provided type. + * This is useful for json-object outputs. + */ + public T getMapValue (Map map, String key, Class type) + { + + ObjectMapper mapper = new ObjectMapper(); + + if (map.containsKey(key)) { + try { + String s = mapper.writeValueAsString(map.get(key)); + return (mapper.readValue(s, type)); + } + catch (IOException e) { + return null; + } + } + return null; + } + + @Override + public String toString() { + return "Deployment{" + + "id='" + id + '\'' + + ", description='" + description + '\'' + + ", createdAt=" + createdAt + + ", updatedAt=" + updatedAt + + ", mainFileName='" + mainFileName + '\'' + + ", tenantName='" + tenantName + '\'' + + '}'; + } + + /* Add a definition of the Cloudify "plan" attribute once we know what it is. + + @JsonIgnoreProperties(ignoreUnknown=true) + public static final class Plan { + } + +*/ + + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprints.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprints.java new file mode 100644 index 0000000000..aa8e2fc28f --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprints.java @@ -0,0 +1,54 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Blueprints implements Serializable{ + + private static final long serialVersionUID = 1L; + + @JsonProperty("items") + private List items; + + @JsonProperty("metadata") + private Metadata metadata; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public Metadata getMetadata() { + return metadata; + } + + public void setMetadata(Metadata metadata) { + this.metadata = metadata; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CancelExecutionParams.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CancelExecutionParams.java new file mode 100644 index 0000000000..4e90d699c7 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CancelExecutionParams.java @@ -0,0 +1,53 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CancelExecutionParams implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("action") + private String action; + + public final static String CANCEL_ACTION = "cancel"; + public final static String FORCE_CANCEL_ACTION = "force-cancel"; + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + + @Override + public String toString() { + return "CancelExecutionParams{" + + "action='" + action + '\'' + + '}'; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CloudifyError.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CloudifyError.java new file mode 100644 index 0000000000..546ae086d8 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CloudifyError.java @@ -0,0 +1,74 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * This class represents a generic Cloudify error response body. + * These responses have a common format: + * { + * "message": "", + * "error_code": "". + * "server_traceback": "" + * } + * + * @author jc1348 + */ +public class CloudifyError implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("message") + private String message; + + @JsonProperty("error_code") + private String errorCode; + + @JsonProperty("server_traceback") + private String serverTraceback; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public String getServerTraceback() { + return serverTraceback; + } + + public void setServerTraceback(String serverTraceback) { + this.serverTraceback = serverTraceback; + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CreateDeploymentParams.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CreateDeploymentParams.java new file mode 100644 index 0000000000..10b1854d81 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CreateDeploymentParams.java @@ -0,0 +1,62 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.Map; + +public class CreateDeploymentParams implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("blueprint_id") + private String blueprintId; + + @JsonProperty("inputs") + private Map inputs; + + public String getBlueprintId() { + return blueprintId; + } + + public void setBlueprintId(String blueprintId) { + this.blueprintId = blueprintId; + } + + public Map getInputs() { + return inputs; + } + + public void setInputs(Map inputs) { + this.inputs = inputs; + } + + @Override + public String toString() { + return "CreateDeploymentBody{" + + "blueprintId='" + blueprintId + '\'' + + ", inputs=" + inputs + + '}'; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployment.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployment.java new file mode 100644 index 0000000000..9bb3107798 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployment.java @@ -0,0 +1,365 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; + +@JsonIgnoreProperties(ignoreUnknown = true) +//@JsonRootName("deployment") +public class Deployment implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("blueprint_id") + private String blueprintId; + + @JsonProperty("created_at") + private Date createdAt; + + @JsonProperty("created_by") + private String createdBy; + + @JsonProperty("description") + private String description; + + @JsonProperty("groups") + private Map groups = null; + + @JsonProperty("id") + private String id; + + @JsonProperty("inputs") + private Map inputs = null; + + // TODO: Expand the definition of a PolicyTrigger + @JsonProperty("policy_triggers") + private List policyTriggers; + + // TODO: Expand the definition of a PolicyType + @JsonProperty("policy_types") + private List policyTypes; + + @JsonProperty("scaling_groups") + private Map scalingGroups = null; + + @JsonProperty("tenant_name") + private String tenantName; + + @JsonProperty("updated_at") + private Date updatedAt; + + @JsonProperty("workflows") + private List workflows; + + public List getPolicyTriggers() { + return policyTriggers; + } + + public void setPolicyTriggers(List policyTriggers) { + this.policyTriggers = policyTriggers; + } + + public List getPolicyTypes() { + return policyTypes; + } + + public void setPolicyTypes(List policyTypes) { + this.policyTypes = policyTypes; + } + + public String getBlueprintId() { + return blueprintId; + } + + public void setBlueprintId(String blueprintId) { + this.blueprintId = blueprintId; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map getGroups() { + return this.groups; + } + + public void setGroups(Map groups) { + this.groups = groups; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Map getInputs() { + return this.inputs; + } + public void setInputs(Map inputs) { + this.inputs = inputs; + } + + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public Map getScalingGroups() { + return scalingGroups; + } + + public void setScalingGroups(Map scalingGroups) { + this.scalingGroups = scalingGroups; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + + public List getWorkflows() { + return workflows; + } + + public void setWorkflows(List workflows) { + this.workflows = workflows; + } + + /* + * Nested subclasses for Group definitions + */ + public static final class Group { + @JsonProperty ("policies") + Object policies; + + @JsonProperty("members") + List members; + + public Object getPolicies() { + return policies; + } + + public void setPolicies(Object policies) { + this.policies = policies; + } + + public List getMembers() { + return members; + } + + public void setMembers(List members) { + this.members = members; + } + } + + /* + * Nested subclasses for Scaling Group definitions + */ + public static final class ScalingGroup { + @JsonProperty ("properties") + ScalingGroupProperties properties; + + @JsonProperty("members") + List members; + + public ScalingGroupProperties getProperties() { + return properties; + } + + public void setProperties(ScalingGroupProperties properties) { + this.properties = properties; + } + + public List getMembers() { + return members; + } + + public void setMembers(List members) { + this.members = members; + } + } + + public static final class ScalingGroupProperties { + @JsonProperty("current_instances") + int currentInstances; + + @JsonProperty("default_instances") + int defaultInstances; + + @JsonProperty("max_instances") + int maxInstances; + + @JsonProperty("min_instances") + int minInstances; + + @JsonProperty("planned_instances") + int plannedInstances; + + public int getCurrentInstances() { + return currentInstances; + } + + public void setCurrentInstances(int currentInstances) { + this.currentInstances = currentInstances; + } + + public int getDefaultInstances() { + return defaultInstances; + } + + public void setDefaultInstances(int defaultInstances) { + this.defaultInstances = defaultInstances; + } + + public int getMaxInstances() { + return maxInstances; + } + + public void setMaxInstances(int maxInstances) { + this.maxInstances = maxInstances; + } + + public int getMinInstances() { + return minInstances; + } + + public void setMinInstances(int minInstances) { + this.minInstances = minInstances; + } + + public int getPlannedInstances() { + return plannedInstances; + } + + public void setPlannedInstances(int plannedInstances) { + this.plannedInstances = plannedInstances; + } + } + + /* + * Nested subclass for Deployment Workflow entities. + * Note that Blueprint class also contains a slightly different Workflow structure. + */ + public static final class Workflow { + @JsonProperty("name") + private String name; + @JsonProperty("created_at") + private Date createdAt; + @JsonProperty("parameters") + private Map parameters; + + public Workflow() {} + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public Date getCreatedAt() { + return createdAt; + } + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + public Map getParameters() { + return parameters; + } + public void setParameters(Map parameters) { + this.parameters = parameters; + } + } + + /* + * Return an output as a Json-mapped Object of the provided type. + * This is useful for json-object outputs. + */ + public T getMapValue (Map map, String key, Class type) + { + + ObjectMapper mapper = new ObjectMapper(); + if (map.containsKey(key)) { + try { + String s = mapper.writeValueAsString(map.get(key)); + return (mapper.readValue(s, type)); + } + catch (IOException e) { + return null; + } + } + return null; + } + + @Override + public String toString() { + return "Deployment{" + + "id='" + id + '\'' + + ", description='" + description + '\'' + + ", blueprintId='" + blueprintId + '\'' + + ", createdBy='" + createdBy + '\'' + + ", tenantName='" + tenantName + '\'' + + ", createdAt=" + createdAt + + ", updatedAt=" + updatedAt + + ", inputs='" + inputs + '\'' + + ", workflows=" + workflows + + ", groups=" + groups + + '}'; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/DeploymentOutputs.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/DeploymentOutputs.java new file mode 100644 index 0000000000..d34195cfd7 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/DeploymentOutputs.java @@ -0,0 +1,87 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; + +@JsonIgnoreProperties(ignoreUnknown = true) +//@JsonRootName("outputs") +public class DeploymentOutputs implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("deployment_id") + private String deploymentId; + + @JsonProperty("outputs") + private Map outputs = null; + + public Map getOutputs() { + return this.outputs; + } + public void setOutputs(Map outputs) { + this.outputs = outputs; + } + + public String getDeploymentId() { + return deploymentId; + } + public void setDeploymentId(String deploymentId) { + this.deploymentId = deploymentId; + } + + /* + * Return an output as a Json-mapped Object of the provided type. + * This is useful for json-object outputs. + */ + public T getMapValue (Map map, String key, Class type) + { + + ObjectMapper mapper = new ObjectMapper(); + + if (map.containsKey(key)) { + try { + String s = mapper.writeValueAsString(map.get(key)); + return (mapper.readValue(s, type)); + } + catch (IOException e) { + return null; + } + } + return null; + } + + @Override + public String toString() { + return "DeploymentOutputs{" + + "deploymentId='" + deploymentId + '\'' + + ", outputs='" + outputs + '\'' + + '}'; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployments.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployments.java new file mode 100644 index 0000000000..f5019a74e9 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployments.java @@ -0,0 +1,54 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.List; + +public class Deployments implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("items") + private List items; + + @JsonProperty("metadata") + private Metadata metadata; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public Metadata getMetadata() { + return metadata; + } + + public void setMetadata(Metadata metadata) { + this.metadata = metadata; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Execution.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Execution.java new file mode 100644 index 0000000000..73510ceeb0 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Execution.java @@ -0,0 +1,174 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; +import java.util.Date; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +// @JsonRootName("execution") +public class Execution implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("blueprint_id") + private String blueprintId; + + @JsonProperty("created_at") + private Date createdAt; + + @JsonProperty("created_by") + private String createdBy; + + @JsonProperty("deployment_id") + private String deploymentId; + + @JsonProperty("error") + private String error; + + @JsonProperty("id") + private String id; + + @JsonProperty("is_system_workflow") + private boolean isSystemWorkflow; + + @JsonProperty("parameters") + private Map parameters; + + @JsonProperty("status") + private String status; + + @JsonProperty("tenant_name") + private String tenantName; + + @JsonProperty("workflow_id") + private String workflowId; + + public String getBlueprintId() { + return blueprintId; + } + + public void setBlueprintId(String blueprintId) { + this.blueprintId = blueprintId; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public String getDeploymentId() { + return deploymentId; + } + + public void setDeploymentId(String deploymentId) { + this.deploymentId = deploymentId; + } + + public String getError() { + return error; + } + + public void setError(String error) { + this.error = error; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public boolean isSystemWorkflow() { + return isSystemWorkflow; + } + + public void setSystemWorkflow(boolean isSystemWorkflow) { + this.isSystemWorkflow = isSystemWorkflow; + } + + public Map getParameters() { + return parameters; + } + + public void setParameters(Map parameters) { + this.parameters = parameters; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public String getWorkflowId() { + return workflowId; + } + + public void setWorkflowId(String workflowId) { + this.workflowId = workflowId; + } + + @Override + public String toString() { + return "Execution{" + + "id='" + id + '\'' + + ", blueprintId='" + blueprintId + '\'' + + ", createdBy='" + createdBy + '\'' + + ", createdAt=" + createdAt + + ", deploymentId='" + deploymentId + '\'' + + ", error=" + error + + ", isSystemWorkflow=" + isSystemWorkflow + + ", status=" + status + + ", tenantName='" + tenantName + '\'' + + ", parameters=" + parameters + + '}'; + } + + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Executions.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Executions.java new file mode 100644 index 0000000000..2095f8acd9 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Executions.java @@ -0,0 +1,54 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.List; + +public class Executions implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("items") + private List items; + + @JsonProperty("metadata") + private Metadata metadata; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public Metadata getMetadata() { + return metadata; + } + + public void setMetadata(Metadata metadata) { + this.metadata = metadata; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Metadata.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Metadata.java new file mode 100644 index 0000000000..6ae895b30d --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Metadata.java @@ -0,0 +1,57 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; + +/** + * This class represents a generic Cloudify response to a GET command. + * These responses have a common format: + * { + * "items": [ + * List of objects of the requested type + * ], + * "metadata": { + * } + * } + * + * @author jc1348 + * + */ +public class Metadata implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("pagination") + private Pagination pagination; + + + public Pagination getPagination() { + return pagination; + } + + public void setPagination(Pagination pagination) { + this.pagination = pagination; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstance.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstance.java new file mode 100644 index 0000000000..ec597b77a4 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstance.java @@ -0,0 +1,205 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonRootName("node_instance") +public class NodeInstance implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("created_by") + private String createdBy; + + @JsonProperty("deployment_id") + private String deploymentId; + + @JsonProperty("host_id") + private String hostId; + + @JsonProperty("id") + private String id; + + @JsonProperty("node_id") + private String nodeId; + + @JsonProperty("relationships") + private List relationships = null; + + @JsonProperty("runtime_properties") + private Map runtimeProperties = null; + + @JsonProperty("scaling_groups") + private List scalingGroups; + + @JsonProperty("state") + private String state; + + @JsonProperty("tenant_name") + private String tenantName; + + @JsonProperty("version") + private String version; + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public String getDeploymentId() { + return deploymentId; + } + + public void setDeploymentId(String deploymentId) { + this.deploymentId = deploymentId; + } + + public String getHostId() { + return hostId; + } + + public void setHostId(String hostId) { + this.hostId = hostId; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public List getRelationships() { + return relationships; + } + + public void setRelationships(List relationships) { + this.relationships = relationships; + } + + public Map getRuntimeProperties() { + return runtimeProperties; + } + + public void setRuntimeProperties(Map runtimeProperties) { + this.runtimeProperties = runtimeProperties; + } + + public List getScalingGroups() { + return scalingGroups; + } + + public void setScalingGroups(List scalingGroups) { + this.scalingGroups = scalingGroups; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + /* + * Nested structure representing scaling groups in which this node is a member + */ + public static final class ScalingGroupIdentifier + { + @JsonProperty("name") + private String name; + + @JsonProperty("id") + private String id; + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + public String toString() { + return "Scaling Group{ name=" + name + ", id=" + id + "}"; + } + } + + @Override + public String toString() { + return "Deployment{" + + "id='" + id + '\'' + + "nodeId='" + nodeId + '\'' + + ", createdBy='" + createdBy + '\'' + + ", tenantName='" + tenantName + '\'' + + ", state=" + state + + ", deploymentId=" + deploymentId + + ", hostId='" + hostId + '\'' + + ", version='" + version + '\'' + + ", relationships=" + relationships + + ", runtimeProperties=" + runtimeProperties + + ", scalingGroups=" + scalingGroups + + '}'; + } + + // TODO: Need an object structure for Relationships +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstances.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstances.java new file mode 100644 index 0000000000..ddaa209b75 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstances.java @@ -0,0 +1,54 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.List; + +public class NodeInstances implements Serializable{ + + private static final long serialVersionUID = 1L; + + @JsonProperty("items") + private List items; + + @JsonProperty("metadata") + private Metadata metadata; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public Metadata getMetadata() { + return metadata; + } + + public void setMetadata(Metadata metadata) { + this.metadata = metadata; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/OpenstackConfig.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/OpenstackConfig.java new file mode 100644 index 0000000000..03ab1f194c --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/OpenstackConfig.java @@ -0,0 +1,89 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class OpenstackConfig implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("username") + String username; + + @JsonProperty("password") + String password; + + @JsonProperty("tenant_name") + String tenantName; + + @JsonProperty("auth_url") + String authUrl; + + @JsonProperty("region") + String region; + + // NOTE: Not supporting "custom_configuration" + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public String getAuthUrl() { + return authUrl; + } + + public void setAuthUrl(String authUrl) { + this.authUrl = authUrl; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Pagination.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Pagination.java new file mode 100644 index 0000000000..547c437b75 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Pagination.java @@ -0,0 +1,51 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Pagination { + @JsonProperty("total") + private int total; + @JsonProperty("offset") + private int offset; + @JsonProperty("size") + private int size; + + public int getTotal() { + return total; + } + public void setTotal(int total) { + this.total = total; + } + public int getOffset() { + return offset; + } + public void setOffset(int offset) { + this.offset = offset; + } + public int getSize() { + return size; + } + public void setSize(int size) { + this.size = size; + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/ParameterDefinition.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/ParameterDefinition.java new file mode 100644 index 0000000000..ae79880cca --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/ParameterDefinition.java @@ -0,0 +1,58 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ParameterDefinition implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("type") + private String type; + @JsonProperty("description") + private String description; + @JsonProperty("default") + private Object defaultValue; + + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public Object getDefaultValue() { + return defaultValue; + } + public void setDefaultValue(Object defaultValue) { + this.defaultValue = defaultValue; + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/StartExecutionParams.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/StartExecutionParams.java new file mode 100644 index 0000000000..f9d1cecb30 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/StartExecutionParams.java @@ -0,0 +1,98 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class StartExecutionParams implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("workflow_id") + private String workflowId; + + @JsonProperty("deployment_id") + private String deploymentId; + + @JsonProperty("allow_custom_parameters") + private boolean allowCustomParameters; + + @JsonProperty("force") + private boolean force; + + @JsonProperty("parameters") + private Map parameters; + + public String getWorkflowId() { + return workflowId; + } + + public void setWorkflowId(String workflowId) { + this.workflowId = workflowId; + } + + public String getDeploymentId() { + return deploymentId; + } + + public void setDeploymentId(String deploymentId) { + this.deploymentId = deploymentId; + } + + public boolean isAllowCustomParameters() { + return allowCustomParameters; + } + + public void setAllowCustomParameters(boolean allowCustomParameters) { + this.allowCustomParameters = allowCustomParameters; + } + + public boolean isForce() { + return force; + } + + public void setForce(boolean force) { + this.force = force; + } + + public Map getParameters() { + return parameters; + } + + public void setParameters(Map parameters) { + this.parameters = parameters; + } + + @Override + public String toString() { + return "UpdateExecutionParams{" + + "workflowId='" + workflowId + '\'' + + "deploymentId='" + deploymentId + '\'' + + "allowCustomParameters='" + allowCustomParameters + '\'' + + "force='" + force + '\'' + + "parameters='" + parameters + '\'' + + '}'; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Token.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Token.java new file mode 100644 index 0000000000..ebb968acbf --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Token.java @@ -0,0 +1,67 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +//@JsonRootName("token") +// The Token object is returned without a root element +public class Token implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("role") + private String role; + + @JsonProperty("value") + private String value; + + // Any expiration? Maybe something in the Headers? + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + + @Override + public String toString() { + return "Token{" + + "role='" + role + '\'' + + ", value='" + value + '\'' + + '}'; + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateExecutionParams.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateExecutionParams.java new file mode 100644 index 0000000000..abd809b5d6 --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateExecutionParams.java @@ -0,0 +1,50 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class UpdateExecutionParams implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("status") + private String status; + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + + @Override + public String toString() { + return "UpdateExecutionParams{" + + "status='" + status + '\'' + + '}'; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateNodeInstanceParams.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateNodeInstanceParams.java new file mode 100644 index 0000000000..946bb2165c --- /dev/null +++ b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateNodeInstanceParams.java @@ -0,0 +1,76 @@ +/*- + * ============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.onap.so.cloudify.v3.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.Map; + +public class UpdateNodeInstanceParams implements Serializable { + + private static final long serialVersionUID = 1L; + + @JsonProperty("state") + private String state; + + @JsonProperty("version") + private String version; + + @JsonProperty("runtime_properties") + private Map runtimeProperties; + + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public Map getRuntimeProperties() { + return runtimeProperties; + } + + public void setRuntimeProperties(Map runtimeProperties) { + this.runtimeProperties = runtimeProperties; + } + + + @Override + public String toString() { + return "UpdateNodeInstanceParams{" + + "state='" + state + '\'' + + "version='" + version + '\'' + + ", runtimeProperties=" + runtimeProperties + + '}'; + } + +} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyBaseException.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyBaseException.java deleted file mode 100644 index 1fe933b174..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyBaseException.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -/** - * A common abstract parent of all Openstack Exception types, allowing - * calling classes the choice to catch all error exceptions together. - */ -public abstract class CloudifyBaseException extends RuntimeException -{ - private static final long serialVersionUID = 1L; - - /* - * Implement only the basic constructors - */ - public CloudifyBaseException () {} - - public CloudifyBaseException(String message) { - super(message); - } - - public CloudifyBaseException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClient.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClient.java deleted file mode 100644 index 03f5a9907b..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClient.java +++ /dev/null @@ -1,130 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -import java.util.Properties; - -import org.openecomp.mso.cloudify.connector.http.HttpClientConnector; - -public class CloudifyClient { - - protected String managerEndpoint; - protected String tenant = "default_tenant"; // Note - only default_tenant supported in community edition - - protected CloudifyTokenProvider tokenProvider; - - protected static int AUTHENTICATION_RETRIES = 1; - - protected CloudifyClientConnector connector; - - protected Properties properties = new Properties(); - - public CloudifyClient(String managerEndpoint) { - this.managerEndpoint = managerEndpoint; - this.connector = new HttpClientConnector(); - } - - public CloudifyClient(String managerEndpoint, String tenant) { - this.managerEndpoint = managerEndpoint; - this.tenant = tenant; - this.connector = new HttpClientConnector(); - } - - public CloudifyClient(String managerEndpoint, CloudifyClientConnector connector) { - this.managerEndpoint = managerEndpoint; - this.connector = connector; - } - - /** - * Execute a Cloudify request by making the REST API call. Return the - * complete CloudifyResponse structure, which includes the complete - * HTTP response. - * @param request a CloudifyRequest object - * @return a CloudifyResponse object - */ - public CloudifyResponse request(CloudifyRequest request) { - CloudifyResponseException authException = null; - - for (int i = 0; i <= AUTHENTICATION_RETRIES; i++) { - request.endpoint(managerEndpoint); - request.header("Tenant", tenant); - if (tokenProvider != null) - request.header("Authentication-Token", tokenProvider.getToken()); - - try { - return connector.request(request); - } catch (CloudifyResponseException e) { - if (e.getStatus() != CloudifyResponseStatus.NOT_AUTHORIZED - || tokenProvider == null) { - throw e; - } - authException = e; - tokenProvider.expireToken(); - } - } - - throw authException; - } - - /** - * Execute a CloudifyRequest by sending the REST API call to the Cloudify - * Manager endpoint. The return type is a JSON POJO object containing the - * response body entity. - * @param request - * @return a JSON POJO object specific to the request type - */ - public T execute(CloudifyRequest request) { - CloudifyResponse response = request(request); - return (request.returnType() != null && request.returnType() != Void.class) ? response.getEntity(request.returnType()) : null; - } - - public void property(String property, String value) { - properties.put(property, value); - } - - /** - * Set a Token Provider. This class should be able to produce an - * authentication token on-demand. - * @param tokenProvider - */ - public void setTokenProvider(CloudifyTokenProvider tokenProvider) { - this.tokenProvider = tokenProvider; - } - - /** - * Manually set the authentication token to use for this client. - * @param token - */ - public void setToken(String token) { - setTokenProvider(new CloudifySimpleTokenProvider(token)); - } - - /** - * Perform a simple GET request with no request message body - * @param path - * @param returnType - * @return An object of Class - */ - public CloudifyRequest get(String path, Class returnType) { - return new CloudifyRequest(this, HttpMethod.GET, path, null, returnType); - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientConnector.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientConnector.java deleted file mode 100644 index 12162c3d4f..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientConnector.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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.cloudify.base.client; - - -public interface CloudifyClientConnector { - - public CloudifyResponse request(CloudifyRequest request); - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProvider.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProvider.java deleted file mode 100644 index 946720bb45..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProvider.java +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -import java.util.Date; - -import org.apache.commons.lang.time.DateUtils; - -import org.openecomp.mso.cloudify.v3.client.Cloudify; -import org.openecomp.mso.cloudify.v3.client.TokensResource.GetToken; -import org.openecomp.mso.cloudify.v3.model.Token; - -/** - * Cloudify Token Provider that uses the Cloudify client API itself to obtain a token - * - * @author JC1348 - * - */ -public class CloudifyClientTokenProvider implements CloudifyTokenProvider { - - String user; - String password; - String token; - Date expiration; - Cloudify cloudify = null; - - public CloudifyClientTokenProvider(String cloudifyEndpoint, String user, String password) { - this.user = user; - this.password = password; - - cloudify = new Cloudify (cloudifyEndpoint); - } - - @Override - public String getToken() { - Date now = new Date(); - if (token != null && expiration != null && expiration.after(now)) { - return token; - } - - // Create a "Get Token" request. Force basic authentication to acquire the token itself. - GetToken tokenRequest = cloudify.tokens().token(); - tokenRequest.setBasicAuthentication(user, password); - Token newToken = tokenRequest.execute(); - - token = newToken.getValue(); - - if (expiration == null) { - expiration = new Date(); - } - // TODO: Make this property driven (or see if it comes back somehow in response) - expiration = DateUtils.addMinutes(expiration, 10); - - return token; - } - - @Override - /** - * This doesn't actually expire the token in Cloudify. It just prevents this token provider - * from using it. - */ - public void expireToken() { - expiration = null; - token = null; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyConnectException.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyConnectException.java deleted file mode 100644 index 3b28b6e3f9..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyConnectException.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -/** - * Custom RuntimeException to report connection errors to Openstack endpoints. - * Must be a RuntimeException to conform with OpenstackClient interface, which - * does not declare specific Exceptions. - */ -public class CloudifyConnectException extends CloudifyBaseException { - - private static final long serialVersionUID = 7294957362769575271L; - - public CloudifyConnectException(String message) { - super(message); - } - - public CloudifyConnectException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyRequest.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyRequest.java deleted file mode 100644 index 6b0a4c1d13..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyRequest.java +++ /dev/null @@ -1,188 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.ArrayList; -import java.util.Map; - -public class CloudifyRequest { - - private CloudifyClient client; - - public CloudifyRequest() { - - } - - public CloudifyRequest(CloudifyClient client, HttpMethod method, CharSequence path, Entity entity, Class returnType) { - this.client = client; - this.method = method; - this.path = new StringBuilder(path); - this.entity = entity; - this.returnType = returnType; - header("Accept", "application/json"); - } - - private String endpoint; - - private HttpMethod method; - - private StringBuilder path = new StringBuilder(); - - private Map> headers = new HashMap>(); - - private Entity entity; - - private Class returnType; - - private boolean basicAuth = false; - private String user = null; - private String password = null; - - public CloudifyRequest endpoint(String endpoint) { - this.endpoint = endpoint; - return this; - } - - public String endpoint() { - return endpoint; - } - - public CloudifyRequest method(HttpMethod method) { - this.method = method; - return this; - } - - public HttpMethod method() { - return method; - } - - public CloudifyRequest path(String path) { - this.path.append(path); - return this; - } - - public String path() { - return path.toString(); - } - - public CloudifyRequest header(String name, Object value) { - if(value != null) { - headers.put(name, Arrays.asList(value)); - } - return this; - } - - public Map> headers() { - return headers; - } - - public Entity entity(T entity, String contentType) { - return new Entity(entity, contentType); - } - - public Entity entity() { - return entity; - } - - public Entity json(T entity) { - return entity(entity, "application/json"); - } - - public void returnType(Class returnType) { - this.returnType = returnType; - } - - public Class returnType() { - return returnType; - } - - /* - * Use Basic Authentication for this request. If not set, the client will use Token authentication - * if a token provider is defined. Otherwise, no authentication will be applied. - */ - public void setBasicAuthentication (String user, String password) { - this.basicAuth = true; - this.user = user; - this.password= password; - } - - public boolean isBasicAuth () { - return this.basicAuth; - } - - public String getUser() { - return user; - } - - public String getPassword() { - return password; - } - - public R execute() { - return client.execute(this); - } - - public CloudifyResponse request() { - return client.request(this); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "CloudifyRequest [endpoint=" + endpoint + ", method=" + method - + ", path=" + path + ", headers=" + headers + ", entity=" - + entity + ", returnType=" + returnType + "]"; - } - - private Map > queryParams = new LinkedHashMap >(); - - public Map > queryParams() { - return queryParams; - } - - public CloudifyRequest queryParam(String key, Object value) { - if (queryParams.containsKey(key)) { - List values = queryParams.get(key); - values.add(value); - } else { - List values = new ArrayList(); - values.add(value); - queryParams.put(key, values); - } - - return this; - } - - protected static String buildPath(String ... elements) { - StringBuilder stringBuilder = new StringBuilder(); - for (String element : elements) { - stringBuilder.append(element); - } - - return stringBuilder.toString(); - } -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponse.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponse.java deleted file mode 100644 index 7ddeaa8c4b..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -import java.io.InputStream; -import java.util.Map; - -public interface CloudifyResponse { - - public T getEntity(Class returnType); - - public T getErrorEntity(Class returnType); - - public InputStream getInputStream(); - - public String getHeader(String name); - - public Map headers(); - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseException.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseException.java deleted file mode 100644 index 27e61f9581..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseException.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -import org.openecomp.mso.cloudify.v3.model.CloudifyError; - -public class CloudifyResponseException extends CloudifyBaseException { - - private static final long serialVersionUID = 7294957362769575271L; - - protected String message; - protected int status; - - // Make the response available for exception handling (includes body) - protected CloudifyResponse response; - - public CloudifyResponseException(String message, int status) { - this.message = message; - this.status = status; - this.response = null; - } - - // Include the response message itself. The body is a CloudifyError JSON structure. - public CloudifyResponseException(String message, int status, CloudifyResponse response) { - CloudifyError error = response.getErrorEntity(CloudifyError.class); - this.message = message + ": " + error.getErrorCode(); - this.status = status; - this.response = response; - } - - public String getMessage() { - return message; - } - - public int getStatus() { - return status; - } - - public CloudifyResponse getResponse() { - return response; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseStatus.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseStatus.java deleted file mode 100644 index 38079d6f26..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyResponseStatus.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -public class CloudifyResponseStatus { - - public static final int OK = 200; - - public static final int ACCEPTED = 201; - - public static final int BAD_REQUEST = 400; - - public static final int NOT_AUTHORIZED = 401; - - public static final int NOT_FOUND = 404; - - public static final int CONFLICT = 409; - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifySimpleTokenProvider.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifySimpleTokenProvider.java deleted file mode 100644 index 8f37e069d9..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifySimpleTokenProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -public class CloudifySimpleTokenProvider implements CloudifyTokenProvider { - - String token; - - public CloudifySimpleTokenProvider(String token) { - this.token = token; - } - - @Override - public String getToken() { - return this.token; - } - - @Override - public void expireToken() { - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyTokenProvider.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyTokenProvider.java deleted file mode 100644 index ee32f9321d..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/CloudifyTokenProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -public interface CloudifyTokenProvider { - - String getToken(); - - void expireToken(); - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/Entity.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/Entity.java deleted file mode 100644 index db2587937b..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/Entity.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -public class Entity { - - private T entity; - - private String contentType; - - public static Entity json(T entity) { - return new Entity(entity, "application/json"); - } - - public static Entity stream(T entity) { - return new Entity(entity, "application/octet-stream"); - } - - public Entity(T entity, String contentType) { - super(); - this.entity = entity; - this.contentType = contentType; - } - - /** - * @return the entity - */ - public T getEntity() { - return entity; - } - - /** - * @param entity the entity to set - */ - public void setEntity(T entity) { - this.entity = entity; - } - - /** - * @return the contentType - */ - public String getContentType() { - return contentType; - } - - /** - * @param contentType the contentType to set - */ - public void setContentType(String contentType) { - this.contentType = contentType; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/HttpMethod.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/HttpMethod.java deleted file mode 100644 index a8c0cab2d8..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/base/client/HttpMethod.java +++ /dev/null @@ -1,25 +0,0 @@ -/*- - * ============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.cloudify.base.client; - -public enum HttpMethod { - HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientConnector.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientConnector.java deleted file mode 100644 index 17904adf7b..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientConnector.java +++ /dev/null @@ -1,245 +0,0 @@ -/*- - * ============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.cloudify.connector.http; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.UnknownHostException; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpStatus; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.HttpResponseException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.InputStreamEntity; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.openecomp.mso.cloudify.base.client.CloudifyClientConnector; -import org.openecomp.mso.cloudify.base.client.CloudifyConnectException; -import org.openecomp.mso.cloudify.base.client.CloudifyRequest; -import org.openecomp.mso.cloudify.base.client.CloudifyResponse; -import org.openecomp.mso.cloudify.base.client.CloudifyResponseException; -import org.openecomp.mso.logger.MsoLogger; - -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonRootName; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; - -public class HttpClientConnector implements CloudifyClientConnector { - - public static ObjectMapper DEFAULT_MAPPER; - public static ObjectMapper WRAPPED_MAPPER; - - private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); - - static { - DEFAULT_MAPPER = new ObjectMapper(); - - DEFAULT_MAPPER.setSerializationInclusion(Include.NON_NULL); - DEFAULT_MAPPER.disable(SerializationFeature.INDENT_OUTPUT); - DEFAULT_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); - DEFAULT_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - - WRAPPED_MAPPER = new ObjectMapper(); - - WRAPPED_MAPPER.setSerializationInclusion(Include.NON_NULL); - WRAPPED_MAPPER.disable(SerializationFeature.INDENT_OUTPUT); - WRAPPED_MAPPER.enable(SerializationFeature.WRAP_ROOT_VALUE); - WRAPPED_MAPPER.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); - WRAPPED_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); - WRAPPED_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - } - - protected static ObjectMapper getObjectMapper (Class type) { - return type.getAnnotation(JsonRootName.class) == null ? DEFAULT_MAPPER : WRAPPED_MAPPER; - } - - public CloudifyResponse request(CloudifyRequest request) { - - CloseableHttpClient httpClient = null; //HttpClients.createDefault(); - - if (request.isBasicAuth()) { - // Use Basic Auth for this request. - CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); - credentialsProvider.setCredentials(AuthScope.ANY, - new UsernamePasswordCredentials (request.getUser(), request.getPassword())); - - httpClient = HttpClients.custom().setRedirectStrategy(new HttpClientRedirectStrategy()).setDefaultCredentialsProvider(credentialsProvider).build(); - } - else { - // Don't use basic authentication. The Client will attempt Token-based authentication - httpClient = HttpClients.custom().setRedirectStrategy(new HttpClientRedirectStrategy()).build(); - } - - URI uri = null; - - // Build the URI with query params - try { - URIBuilder uriBuilder = new URIBuilder(request.endpoint() + request.path()); - - for(Map.Entry > entry : request.queryParams().entrySet()) { - for (Object o : entry.getValue()) { - uriBuilder.setParameter(entry.getKey(), String.valueOf(o)); - } - } - - uri = uriBuilder.build(); - } catch (URISyntaxException e) { - throw new HttpClientException (e); - } - - HttpEntity entity = null; - if (request.entity() != null) { - // Special handling for streaming input - if (request.entity().getEntity() instanceof InputStream) { - // Entity is an InputStream - entity = new InputStreamEntity ((InputStream) request.entity().getEntity()); - } - else { - // Assume to be JSON. Flatten the entity to a Json string - try { - // Get appropriate mapper, based on existence of a root element in Entity class - ObjectMapper mapper = getObjectMapper (request.entity().getEntity().getClass()); - - String entityJson = mapper.writeValueAsString (request.entity().getEntity()); - entity = new StringEntity(entityJson, ContentType.create(request.entity().getContentType())); - - LOGGER.debug ("Request JSON Body: " + entityJson.replaceAll("\"password\":\"[^\"]*\"", "\"password\":\"***\"")); - - } catch (JsonProcessingException e) { - throw new HttpClientException ("Json processing error on request entity", e); - } catch (IOException e) { - throw new HttpClientException ("Json IO error on request entity", e); - } - } - } - - // Determine the HttpRequest class based on the method - HttpUriRequest httpRequest; - - switch (request.method()) { - case POST: - HttpPost post = new HttpPost(uri); - post.setEntity (entity); - httpRequest = post; - break; - - case GET: - httpRequest = new HttpGet(uri); - break; - - case PUT: - HttpPut put = new HttpPut(uri); - put.setEntity (entity); - httpRequest = put; - break; - - case DELETE: - httpRequest = new HttpDelete(uri); - break; - - default: - throw new HttpClientException ("Unrecognized HTTP Method: " + request.method()); - } - - for (Entry> h : request.headers().entrySet()) { - StringBuilder sb = new StringBuilder(); - for (Object v : h.getValue()) { - sb.append(String.valueOf(v)); - } - httpRequest.addHeader(h.getKey(), sb.toString()); - } - - // Get the Response. But don't get the body entity yet, as this response - // will be wrapped in an HttpClientResponse. The HttpClientResponse - // buffers the body in constructor, so can close the response here. - HttpClientResponse httpClientResponse = null; - CloseableHttpResponse httpResponse = null; - - // Catch known HttpClient exceptions, and wrap them in OpenStack Client Exceptions - // so calling functions can distinguish. Only RuntimeExceptions are allowed. - try { - httpResponse = httpClient.execute(httpRequest); - - LOGGER.debug ("Response status: " + httpResponse.getStatusLine().getStatusCode()); - - httpClientResponse = new HttpClientResponse (httpResponse); - - int status = httpResponse.getStatusLine().getStatusCode(); - if (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || - status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_ACCEPTED) - { - return httpClientResponse; - } - } - catch (HttpResponseException e) { - // What exactly does this mean? It does not appear to get thrown for - // non-2XX responses as documented. - throw new CloudifyResponseException(e.getMessage(), e.getStatusCode()); - } - catch (UnknownHostException e) { - throw new CloudifyConnectException("Unknown Host: " + e.getMessage()); - } - catch (IOException e) { - // Catch all other IOExceptions and throw as OpenStackConnectException - throw new CloudifyConnectException(e.getMessage()); - } - catch (Exception e) { - // Catchall for anything else, must throw as a RuntimeException - LOGGER.error("Client exception", e); - throw new RuntimeException("Unexpected client exception", e); - } - finally { - // Have the body. Close the stream - if (httpResponse != null) - try { - httpResponse.close(); - } catch (IOException e) { - LOGGER.debug("Unable to close HTTP Response: " + e); - } - } - - // Get here on an error response (4XX-5XX) - throw new CloudifyResponseException(httpResponse.getStatusLine().getReasonPhrase(), - httpResponse.getStatusLine().getStatusCode(), - httpClientResponse); - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientException.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientException.java deleted file mode 100644 index d5eb675257..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientException.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============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.cloudify.connector.http; - -/* - * Declare a RuntimeException since the Interface does not declare any - * throwables. Any caught exception will be wrapped in HttpClientException - */ -public class HttpClientException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public HttpClientException (String s) { - super (s); - } - - public HttpClientException (Exception e) { - super ("Caught nested exception in HttpClient", e); - } - - public HttpClientException (String s, Exception e) { - super (s, e); - } -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientRedirectStrategy.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientRedirectStrategy.java deleted file mode 100644 index 809c5d0175..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientRedirectStrategy.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============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.cloudify.connector.http; - -import java.net.URI; - -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.ProtocolException; -import org.apache.http.annotation.Immutable; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpHead; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.methods.RequestBuilder; -import org.apache.http.impl.client.DefaultRedirectStrategy; -import org.apache.http.protocol.HttpContext; - -/** - * Custom {@link org.apache.http.client.RedirectStrategy} implementation - * that automatically redirects all HEAD, GET and DELETE requests. - * The {@link org.apache.http.client.DefaultRedirectStrategy} only - * redirects GET and HEAD automatically, per the HTTP specification - * (POST and PUT typically have bodies and thus cannot be redirected). - * - * A custom strategy is needed for the Openstack API, which can also send - * 302 on a DELETE (by name) request, expecting the client to follow the - * redirect to perform the actual deletion. - */ -@Immutable -public class HttpClientRedirectStrategy extends DefaultRedirectStrategy { - - /** - * Redirectable methods. - */ - private static final String[] REDIRECT_METHODS = new String[] { - HttpGet.METHOD_NAME, - HttpDelete.METHOD_NAME, - HttpHead.METHOD_NAME - }; - - /** - * Determine if the request should be redirected. - * This may not actually be needed, since the REDIRECT_METHODS - * array has been updated with the DELETE. - */ - @Override - protected boolean isRedirectable(final String method) { - for (final String m: REDIRECT_METHODS) { - if (m.equalsIgnoreCase(method)) { - return true; - } - } - return false; - } - - /** - * Override the default redirect handling method. As implemented - * in HttpClient, it does not preserve the method on 301 or 302 - * responses, always redirecting to a GET. - */ - @Override - public HttpUriRequest getRedirect( - final HttpRequest request, - final HttpResponse response, - final HttpContext context) throws ProtocolException { - - final URI uri = getLocationURI(request, response, context); - final String method = request.getRequestLine().getMethod(); - if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) { - return new HttpHead(uri); - } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) { - return new HttpGet(uri); - } else { - - final int status = response.getStatusLine().getStatusCode(); - - HttpUriRequest newRequest = null; - if (status == HttpStatus.SC_TEMPORARY_REDIRECT || status == HttpStatus.SC_MOVED_TEMPORARILY) { - newRequest = RequestBuilder.copy(request).setUri(uri).build(); - } else { - newRequest = new HttpGet(uri); - } - return newRequest; - } - } -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientResponse.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientResponse.java deleted file mode 100644 index a49f96cf0d..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/connector/http/HttpClientResponse.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============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.cloudify.connector.http; - -import org.apache.http.Header; -import org.apache.http.HttpResponse; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.openecomp.mso.cloudify.base.client.CloudifyResponse; -import org.openecomp.mso.logger.MsoLogger; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; - -public class HttpClientResponse implements CloudifyResponse { - - private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); - - private HttpResponse response = null; - private String entityBody = null; - - public HttpClientResponse(HttpResponse response) - { - this.response = response; - - // Read the body so InputStream can be closed - if (response.getEntity() == null) { - // No body - LOGGER.debug ("No Response Body"); - return; - } - - ByteArrayOutputStream responseBody = new ByteArrayOutputStream(); - try { - response.getEntity().writeTo(responseBody); - } catch (IOException e) { - throw new HttpClientException ("Error Reading Response Body", e); - } - entityBody = responseBody.toString(); - LOGGER.debug (entityBody); - } - - - @Override - public T getEntity (Class returnType) { - // Get appropriate mapper, based on existence of a root element - ObjectMapper mapper = HttpClientConnector.getObjectMapper (returnType); - - T resp = null; - try { - resp = mapper.readValue(entityBody, returnType); - } catch (Exception e) { - throw new HttpClientException ("Caught exception in getEntity", e); - } - return resp; - } - - @Override - public T getErrorEntity(Class returnType) { - return getEntity(returnType); - } - - @Override - public InputStream getInputStream() { - return new ByteArrayInputStream (entityBody.getBytes()); - } - - @Override - public String getHeader(String name) { - return response.getFirstHeader(name).getValue(); - } - - @Override - public Map headers() { - Map headers = new HashMap(); - - Header responseHeaders[] = response.getAllHeaders(); - for (Header h : responseHeaders) { - headers.put(h.getName(), h.getValue()); - } - - return headers; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResource.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResource.java deleted file mode 100644 index 988f8214d1..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResource.java +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * ============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.cloudify.v3.client; - -import java.io.InputStream; - -import org.openecomp.mso.cloudify.v3.model.Blueprint; -import org.openecomp.mso.cloudify.v3.model.Blueprints; -import org.openecomp.mso.cloudify.base.client.Entity; -import org.openecomp.mso.cloudify.base.client.HttpMethod; -import org.openecomp.mso.cloudify.base.client.CloudifyClient; -import org.openecomp.mso.cloudify.base.client.CloudifyRequest; - -public class BlueprintsResource { - - private final CloudifyClient client; - - public BlueprintsResource(CloudifyClient client) { - this.client = client; - } - - /* - * Upload a blueprint package directly. The blueprint must be a ZIP archive. - * However, this method will not validate this. - */ - public UploadBlueprint uploadFromStream (String blueprintId, String mainFileName, InputStream blueprint) { - return new UploadBlueprint (blueprintId, mainFileName, blueprint, null); - } - - public UploadBlueprint uploadFromUrl (String blueprintId, String mainFileName, String blueprintUrl) { - return new UploadBlueprint (blueprintId, mainFileName, null, blueprintUrl); - } - - public ListBlueprints list() { - return new ListBlueprints(); - } - - public GetBlueprint getById(String id) { - return new GetBlueprint(id, null); - } - - // Return all of the metadata, but not the plan - public GetBlueprint getMetadataById(String id) { - return new GetBlueprint(id, "?_include=id,main_file_name,description,tenant_name,created_at,updated_at"); - } - - public DeleteBlueprint deleteById(String id) { - return new DeleteBlueprint(id); - } - - public class UploadBlueprint extends CloudifyRequest { - public UploadBlueprint(String blueprintId, String mainFileName, InputStream blueprint, String blueprintUrl) { - // Initialize the request elements dynamically. - // Either a blueprint input stream or a URL will be provided. - // If a URL is provided, add it to the query string - // If a Stream is provided, set it as the Entity body - super(client, HttpMethod.PUT, - "/api/v3/blueprints/" + blueprintId + "?application_file_name=" + mainFileName + ((blueprintUrl != null) ? "&blueprint_archive=" + blueprintUrl : ""), - ((blueprint != null) ? Entity.stream(blueprint) : null), - Blueprint.class); - } - } - - public class DeleteBlueprint extends CloudifyRequest { - public DeleteBlueprint(String blueprintId) { - super(client, HttpMethod.DELETE, "/api/v3/blueprints/" + blueprintId, null, Blueprint.class); - } - } - - public class GetBlueprint extends CloudifyRequest { - public GetBlueprint(String id, String queryArgs) { - super(client, HttpMethod.GET, "/api/v3/blueprints/" + id + queryArgs, null, Blueprint.class); - } - } - - public class ListBlueprints extends CloudifyRequest { - public ListBlueprints() { - super(client, HttpMethod.GET, "/api/v3/blueprints", null, Blueprints.class); - } - } - - // TODO: DownloadBlueprint is not supported, as it needs to return an input stream - // containing the full blueprint ZIP. - // For a full client library, this will require returning an open stream as the entity... -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/Cloudify.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/Cloudify.java deleted file mode 100644 index c0669b9919..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/Cloudify.java +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * ============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.cloudify.v3.client; - -import org.openecomp.mso.cloudify.base.client.CloudifyClient; -import org.openecomp.mso.cloudify.base.client.CloudifyClientConnector; - -/** - * Reference: http://docs.getcloudify.org/api/v3/ - */ -public class Cloudify extends CloudifyClient { - - private final DeploymentsResource deployments; - private final BlueprintsResource blueprints; - private final TokensResource tokens; - private final NodeInstancesResource nodeInstances; - private final ExecutionsResource executions; - -/* Not supporting dynamic connectors - public Cloudify(String endpoint, CloudifyClientConnector connector) { - super(endpoint, connector); - deployments = new DeploymentsResource(this); - blueprints = new BlueprintsResource(this); - nodeInstances = new NodeInstancesResource(this); - tokens = new TokensResource(this); - } -*/ - public Cloudify(String endpoint, String tenant) { - super(endpoint, tenant); - deployments = new DeploymentsResource(this); - blueprints = new BlueprintsResource(this); - nodeInstances = new NodeInstancesResource(this); - executions = new ExecutionsResource(this); - tokens = new TokensResource(this); - } - - public Cloudify(String endpoint) { - super(endpoint); - deployments = new DeploymentsResource(this); - blueprints = new BlueprintsResource(this); - nodeInstances = new NodeInstancesResource(this); - executions = new ExecutionsResource(this); - tokens = new TokensResource(this); - } - - public DeploymentsResource deployments() { - return this.deployments; - } - - public BlueprintsResource blueprints() { - return this.blueprints; - } - - public NodeInstancesResource nodeInstances() { - return this.nodeInstances; - } - - public ExecutionsResource executions() { - return this.executions; - } - - public TokensResource tokens() { - return this.tokens; - } -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/DeploymentsResource.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/DeploymentsResource.java deleted file mode 100644 index e115370243..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/DeploymentsResource.java +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * ============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.cloudify.v3.client; - -import org.openecomp.mso.cloudify.v3.model.CreateDeploymentParams; -import org.openecomp.mso.cloudify.v3.model.Deployment; -import org.openecomp.mso.cloudify.v3.model.DeploymentOutputs; -import org.openecomp.mso.cloudify.v3.model.Deployments; -import org.openecomp.mso.cloudify.base.client.Entity; -import org.openecomp.mso.cloudify.base.client.HttpMethod; -import org.openecomp.mso.cloudify.base.client.CloudifyClient; -import org.openecomp.mso.cloudify.base.client.CloudifyRequest; - -public class DeploymentsResource { - - private final CloudifyClient client; - - public DeploymentsResource(CloudifyClient client) { - this.client = client; - } - - public CreateDeployment create(String deploymentId, CreateDeploymentParams body) { - return new CreateDeployment(deploymentId, body); - } - - public ListDeployments list() { - return new ListDeployments(); - } - - public GetDeployment byId(String id) { - return new GetDeployment(id); - } - - public GetDeploymentOutputs outputsById(String id) { - return new GetDeploymentOutputs(id); - } - - public DeleteDeployment deleteByName(String name) { - return new DeleteDeployment(name); - } - - public class CreateDeployment extends CloudifyRequest { - public CreateDeployment(String deploymentId, CreateDeploymentParams body) { - super(client, HttpMethod.PUT, "/api/v3/deployments/" + deploymentId, Entity.json(body), Deployment.class); - } - } - - public class DeleteDeployment extends CloudifyRequest { - public DeleteDeployment(String deploymentId) { - super(client, HttpMethod.DELETE, "/api/v3/deployments/" + deploymentId, null, Deployment.class); - } - } - - public class GetDeployment extends CloudifyRequest { - public GetDeployment(String id) { - super(client, HttpMethod.GET, "/api/v3/deployments/" + id, null, Deployment.class); - } - } - - public class GetDeploymentOutputs extends CloudifyRequest { - public GetDeploymentOutputs(String id) { - super(client, HttpMethod.GET, "/api/v3/deployments/" + id + "/outputs", null, DeploymentOutputs.class); - } - } - - public class ListDeployments extends CloudifyRequest { - public ListDeployments() { - super(client, HttpMethod.GET, "/api/v3/deployments", null, Deployments.class); - } - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResource.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResource.java deleted file mode 100644 index 43bc82b0b3..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResource.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============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.cloudify.v3.client; - -import org.openecomp.mso.cloudify.v3.model.CancelExecutionParams; -import org.openecomp.mso.cloudify.v3.model.Execution; -import org.openecomp.mso.cloudify.v3.model.Executions; -import org.openecomp.mso.cloudify.v3.model.StartExecutionParams; -import org.openecomp.mso.cloudify.v3.model.UpdateExecutionParams; -import org.openecomp.mso.cloudify.base.client.Entity; -import org.openecomp.mso.cloudify.base.client.HttpMethod; -import org.openecomp.mso.cloudify.base.client.CloudifyClient; -import org.openecomp.mso.cloudify.base.client.CloudifyRequest; - -public class ExecutionsResource { - - private final CloudifyClient client; - - public ExecutionsResource(CloudifyClient client) { - this.client = client; - } - - public ListExecutions list() { - return new ListExecutions(null); - } - - public ListExecutions listSorted (String sortBy) { - return new ListExecutions("?_sort=" + sortBy); - } - - // Return a filtered list. - // The filter parameter should be a query string of filter criteria (without leading "?") - public ListExecutions listFiltered (String filter, String sortBy) { - String listParams = "?" + filter; - if (sortBy != null) listParams += "&_sort=" + sortBy; - return new ListExecutions(listParams); - } - - public GetExecution byId(String id) { - return new GetExecution(id); - } - - public StartExecution start(StartExecutionParams params) { - return new StartExecution(params); - } - - public UpdateExecution updateStatus(String id, String status) { - UpdateExecutionParams params = new UpdateExecutionParams(); - params.setStatus(status); - return new UpdateExecution(id, params); - } - - public CancelExecution cancel(String executionId, CancelExecutionParams params) { - return new CancelExecution(executionId, params); - } - - - public class GetExecution extends CloudifyRequest { - public GetExecution (String id) { - super(client, HttpMethod.GET, "/api/v3/executions/" + id, null, Execution.class); - } - } - - public class ListExecutions extends CloudifyRequest { - public ListExecutions(String listParams) { - super(client, HttpMethod.GET, "/api/v3/executions" + ((listParams!=null) ? listParams : ""), null, Executions.class); - } - } - - public class StartExecution extends CloudifyRequest { - public StartExecution(StartExecutionParams body) { - super(client, HttpMethod.POST, "/api/v3/executions", Entity.json(body), Execution.class); - } - } - - public class UpdateExecution extends CloudifyRequest { - public UpdateExecution(String executionId, UpdateExecutionParams body) { - super(client, HttpMethod.PATCH, "/api/v3/executions/" + executionId, Entity.json(body), Execution.class); - } - } - - public class CancelExecution extends CloudifyRequest { - public CancelExecution(String executionId, CancelExecutionParams body) { - super(client, HttpMethod.POST, "/api/v3/executions/" + executionId, Entity.json(body), Execution.class); - } - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/NodeInstancesResource.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/NodeInstancesResource.java deleted file mode 100644 index 19f7958434..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/NodeInstancesResource.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============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.cloudify.v3.client; - -import org.openecomp.mso.cloudify.v3.model.UpdateNodeInstanceParams; -import org.openecomp.mso.cloudify.v3.model.NodeInstance; -import org.openecomp.mso.cloudify.v3.model.NodeInstances; -import org.openecomp.mso.cloudify.base.client.Entity; -import org.openecomp.mso.cloudify.base.client.HttpMethod; -import org.openecomp.mso.cloudify.base.client.CloudifyClient; -import org.openecomp.mso.cloudify.base.client.CloudifyRequest; - -public class NodeInstancesResource { - - private final CloudifyClient client; - - public NodeInstancesResource(CloudifyClient client) { - this.client = client; - } - - public ListNodeInstances list() { - return new ListNodeInstances(); - } - - public GetNodeInstance byId(String id) { - return new GetNodeInstance(id); - } - - public UpdateNodeInstance update(String id, UpdateNodeInstanceParams params) { - return new UpdateNodeInstance(id, params); - } - - - public class GetNodeInstance extends CloudifyRequest { - public GetNodeInstance (String id) { - super(client, HttpMethod.GET, "/api/v3/node-instances/" + id, null, NodeInstance.class); - } - } - - public class ListNodeInstances extends CloudifyRequest { - public ListNodeInstances() { - super(client, HttpMethod.GET, "/api/v3/node-instances", null, NodeInstances.class); - } - } - - public class UpdateNodeInstance extends CloudifyRequest { - public UpdateNodeInstance(String nodeInstanceId, UpdateNodeInstanceParams body) { - super(client, HttpMethod.PATCH, "/api/v3/node-instances/" + nodeInstanceId, Entity.json(body), NodeInstance.class); - } - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/TokensResource.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/TokensResource.java deleted file mode 100644 index 80e5fb0065..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/client/TokensResource.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============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.cloudify.v3.client; - -import org.openecomp.mso.cloudify.v3.model.Token; -import org.openecomp.mso.cloudify.base.client.HttpMethod; -import org.openecomp.mso.cloudify.base.client.CloudifyClient; -import org.openecomp.mso.cloudify.base.client.CloudifyRequest; - -public class TokensResource { - - private final CloudifyClient client; - - public TokensResource(CloudifyClient client) { - this.client = client; - } - - /* - * Get a new token for a user - * TODO: User ID/Password logic need to be in the Client. - * Results of a token query should also be able to add to the Client - */ - public GetToken token() { - return new GetToken(); - } - - public class GetToken extends CloudifyRequest { - public GetToken() { - super(client, HttpMethod.GET, "/api/v3/tokens", null, Token.class); - } - } -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/AzureConfig.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/AzureConfig.java deleted file mode 100644 index ddfd1fd6a4..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/AzureConfig.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============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.v3.model; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class AzureConfig implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("subscription_id") - String subscriptionId; - - @JsonProperty("tenant_id") - String tenantId; - - @JsonProperty("client_id") - String clientId; - - @JsonProperty("client_secret") - String clientSecret; - - public String getSubscriptionId() { - return subscriptionId; - } - - public void setSubscriptionId(String subscriptionId) { - this.subscriptionId = subscriptionId; - } - - public String getTenantId() { - return tenantId; - } - - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } - - public String getClientId() { - return clientId; - } - - public void setClientId(String clientId) { - this.clientId = clientId; - } - - public String getClientSecret() { - return clientSecret; - } - - public void setClientSecret(String clientSecret) { - this.clientSecret = clientSecret; - } - -} \ No newline at end of file diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Blueprint.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Blueprint.java deleted file mode 100644 index 468195909f..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Blueprint.java +++ /dev/null @@ -1,159 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.IOException; -import java.io.Serializable; -import java.util.Date; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; - -@JsonIgnoreProperties(ignoreUnknown = true) -//@JsonRootName("blueprint") -public class Blueprint implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("created_at") - private Date createdAt; - - @JsonProperty("description") - private String description; - - @JsonProperty("id") - private String id; - - @JsonProperty("main_file_name") - private String mainFileName; - - @JsonProperty("plan") - private Map plan = null; - - @JsonProperty("tenant_name") - private String tenantName; - - @JsonProperty("updated_at") - private Date updatedAt; - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getMainFileName() { - return mainFileName; - } - - public void setMainFileName(String mainFileName) { - this.mainFileName = mainFileName; - } - - public Map getPlan() { - return this.plan; - } - - public void setPlan(Map plan) { - this.plan = plan; - } - - public String getTenantName() { - return tenantName; - } - - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - - /* - * Return an output as a Json-mapped Object of the provided type. - * This is useful for json-object outputs. - */ - public T getMapValue (Map map, String key, Class type) - { - - ObjectMapper mapper = new ObjectMapper(); - - if (map.containsKey(key)) { - try { - String s = mapper.writeValueAsString(map.get(key)); - return (mapper.readValue(s, type)); - } - catch (IOException e) { - return null; - } - } - return null; - } - - @Override - public String toString() { - return "Deployment{" + - "id='" + id + '\'' + - ", description='" + description + '\'' + - ", createdAt=" + createdAt + - ", updatedAt=" + updatedAt + - ", mainFileName='" + mainFileName + '\'' + - ", tenantName='" + tenantName + '\'' + - '}'; - } - - /* Add a definition of the Cloudify "plan" attribute once we know what it is. - - @JsonIgnoreProperties(ignoreUnknown=true) - public static final class Plan { - } - -*/ - - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Blueprints.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Blueprints.java deleted file mode 100644 index bf9b376eaa..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Blueprints.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.Serializable; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Blueprints implements Serializable{ - - private static final long serialVersionUID = 1L; - - @JsonProperty("items") - private List items; - - @JsonProperty("metadata") - private Metadata metadata; - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CancelExecutionParams.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CancelExecutionParams.java deleted file mode 100644 index 5d7672549b..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CancelExecutionParams.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class CancelExecutionParams implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("action") - private String action; - - public final static String CANCEL_ACTION = "cancel"; - public final static String FORCE_CANCEL_ACTION = "force-cancel"; - - public String getAction() { - return action; - } - - public void setAction(String action) { - this.action = action; - } - - - @Override - public String toString() { - return "CancelExecutionParams{" + - "action='" + action + '\'' + - '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CloudifyError.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CloudifyError.java deleted file mode 100644 index fcd9120c78..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CloudifyError.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * This class represents a generic Cloudify error response body. - * These responses have a common format: - * { - * "message": "", - * "error_code": "". - * "server_traceback": "" - * } - * - * @author jc1348 - */ -public class CloudifyError implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("message") - private String message; - - @JsonProperty("error_code") - private String errorCode; - - @JsonProperty("server_traceback") - private String serverTraceback; - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getErrorCode() { - return errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } - - public String getServerTraceback() { - return serverTraceback; - } - - public void setServerTraceback(String serverTraceback) { - this.serverTraceback = serverTraceback; - } -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CreateDeploymentParams.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CreateDeploymentParams.java deleted file mode 100644 index f33b7afe4c..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/CreateDeploymentParams.java +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.io.Serializable; -import java.util.Map; - -public class CreateDeploymentParams implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("blueprint_id") - private String blueprintId; - - @JsonProperty("inputs") - private Map inputs; - - public String getBlueprintId() { - return blueprintId; - } - - public void setBlueprintId(String blueprintId) { - this.blueprintId = blueprintId; - } - - public Map getInputs() { - return inputs; - } - - public void setInputs(Map inputs) { - this.inputs = inputs; - } - - @Override - public String toString() { - return "CreateDeploymentBody{" + - "blueprintId='" + blueprintId + '\'' + - ", inputs=" + inputs + - '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Deployment.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Deployment.java deleted file mode 100644 index 515e8a0be1..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Deployment.java +++ /dev/null @@ -1,365 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.IOException; -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; - -@JsonIgnoreProperties(ignoreUnknown = true) -//@JsonRootName("deployment") -public class Deployment implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("blueprint_id") - private String blueprintId; - - @JsonProperty("created_at") - private Date createdAt; - - @JsonProperty("created_by") - private String createdBy; - - @JsonProperty("description") - private String description; - - @JsonProperty("groups") - private Map groups = null; - - @JsonProperty("id") - private String id; - - @JsonProperty("inputs") - private Map inputs = null; - - // TODO: Expand the definition of a PolicyTrigger - @JsonProperty("policy_triggers") - private List policyTriggers; - - // TODO: Expand the definition of a PolicyType - @JsonProperty("policy_types") - private List policyTypes; - - @JsonProperty("scaling_groups") - private Map scalingGroups = null; - - @JsonProperty("tenant_name") - private String tenantName; - - @JsonProperty("updated_at") - private Date updatedAt; - - @JsonProperty("workflows") - private List workflows; - - public List getPolicyTriggers() { - return policyTriggers; - } - - public void setPolicyTriggers(List policyTriggers) { - this.policyTriggers = policyTriggers; - } - - public List getPolicyTypes() { - return policyTypes; - } - - public void setPolicyTypes(List policyTypes) { - this.policyTypes = policyTypes; - } - - public String getBlueprintId() { - return blueprintId; - } - - public void setBlueprintId(String blueprintId) { - this.blueprintId = blueprintId; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public String getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Map getGroups() { - return this.groups; - } - - public void setGroups(Map groups) { - this.groups = groups; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Map getInputs() { - return this.inputs; - } - public void setInputs(Map inputs) { - this.inputs = inputs; - } - - public String getTenantName() { - return tenantName; - } - - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public Map getScalingGroups() { - return scalingGroups; - } - - public void setScalingGroups(Map scalingGroups) { - this.scalingGroups = scalingGroups; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - public List getWorkflows() { - return workflows; - } - - public void setWorkflows(List workflows) { - this.workflows = workflows; - } - - /* - * Nested subclasses for Group definitions - */ - public static final class Group { - @JsonProperty ("policies") - Object policies; - - @JsonProperty("members") - List members; - - public Object getPolicies() { - return policies; - } - - public void setPolicies(Object policies) { - this.policies = policies; - } - - public List getMembers() { - return members; - } - - public void setMembers(List members) { - this.members = members; - } - } - - /* - * Nested subclasses for Scaling Group definitions - */ - public static final class ScalingGroup { - @JsonProperty ("properties") - ScalingGroupProperties properties; - - @JsonProperty("members") - List members; - - public ScalingGroupProperties getProperties() { - return properties; - } - - public void setProperties(ScalingGroupProperties properties) { - this.properties = properties; - } - - public List getMembers() { - return members; - } - - public void setMembers(List members) { - this.members = members; - } - } - - public static final class ScalingGroupProperties { - @JsonProperty("current_instances") - int currentInstances; - - @JsonProperty("default_instances") - int defaultInstances; - - @JsonProperty("max_instances") - int maxInstances; - - @JsonProperty("min_instances") - int minInstances; - - @JsonProperty("planned_instances") - int plannedInstances; - - public int getCurrentInstances() { - return currentInstances; - } - - public void setCurrentInstances(int currentInstances) { - this.currentInstances = currentInstances; - } - - public int getDefaultInstances() { - return defaultInstances; - } - - public void setDefaultInstances(int defaultInstances) { - this.defaultInstances = defaultInstances; - } - - public int getMaxInstances() { - return maxInstances; - } - - public void setMaxInstances(int maxInstances) { - this.maxInstances = maxInstances; - } - - public int getMinInstances() { - return minInstances; - } - - public void setMinInstances(int minInstances) { - this.minInstances = minInstances; - } - - public int getPlannedInstances() { - return plannedInstances; - } - - public void setPlannedInstances(int plannedInstances) { - this.plannedInstances = plannedInstances; - } - } - - /* - * Nested subclass for Deployment Workflow entities. - * Note that Blueprint class also contains a slightly different Workflow structure. - */ - public static final class Workflow { - @JsonProperty("name") - private String name; - @JsonProperty("created_at") - private Date createdAt; - @JsonProperty("parameters") - private Map parameters; - - public Workflow() {} - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public Date getCreatedAt() { - return createdAt; - } - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - public Map getParameters() { - return parameters; - } - public void setParameters(Map parameters) { - this.parameters = parameters; - } - } - - /* - * Return an output as a Json-mapped Object of the provided type. - * This is useful for json-object outputs. - */ - public T getMapValue (Map map, String key, Class type) - { - - ObjectMapper mapper = new ObjectMapper(); - if (map.containsKey(key)) { - try { - String s = mapper.writeValueAsString(map.get(key)); - return (mapper.readValue(s, type)); - } - catch (IOException e) { - return null; - } - } - return null; - } - - @Override - public String toString() { - return "Deployment{" + - "id='" + id + '\'' + - ", description='" + description + '\'' + - ", blueprintId='" + blueprintId + '\'' + - ", createdBy='" + createdBy + '\'' + - ", tenantName='" + tenantName + '\'' + - ", createdAt=" + createdAt + - ", updatedAt=" + updatedAt + - ", inputs='" + inputs + '\'' + - ", workflows=" + workflows + - ", groups=" + groups + - '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/DeploymentOutputs.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/DeploymentOutputs.java deleted file mode 100644 index 26d2ae20bc..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/DeploymentOutputs.java +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.IOException; -import java.io.Serializable; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; - -@JsonIgnoreProperties(ignoreUnknown = true) -//@JsonRootName("outputs") -public class DeploymentOutputs implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("deployment_id") - private String deploymentId; - - @JsonProperty("outputs") - private Map outputs = null; - - public Map getOutputs() { - return this.outputs; - } - public void setOutputs(Map outputs) { - this.outputs = outputs; - } - - public String getDeploymentId() { - return deploymentId; - } - public void setDeploymentId(String deploymentId) { - this.deploymentId = deploymentId; - } - - /* - * Return an output as a Json-mapped Object of the provided type. - * This is useful for json-object outputs. - */ - public T getMapValue (Map map, String key, Class type) - { - - ObjectMapper mapper = new ObjectMapper(); - - if (map.containsKey(key)) { - try { - String s = mapper.writeValueAsString(map.get(key)); - return (mapper.readValue(s, type)); - } - catch (IOException e) { - return null; - } - } - return null; - } - - @Override - public String toString() { - return "DeploymentOutputs{" + - "deploymentId='" + deploymentId + '\'' + - ", outputs='" + outputs + '\'' + - '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Deployments.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Deployments.java deleted file mode 100644 index eb49848869..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Deployments.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.io.Serializable; -import java.util.List; - -public class Deployments implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("items") - private List items; - - @JsonProperty("metadata") - private Metadata metadata; - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Execution.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Execution.java deleted file mode 100644 index 65a1015539..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Execution.java +++ /dev/null @@ -1,174 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.Serializable; -import java.util.Date; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonIgnoreProperties(ignoreUnknown = true) -// @JsonRootName("execution") -public class Execution implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("blueprint_id") - private String blueprintId; - - @JsonProperty("created_at") - private Date createdAt; - - @JsonProperty("created_by") - private String createdBy; - - @JsonProperty("deployment_id") - private String deploymentId; - - @JsonProperty("error") - private String error; - - @JsonProperty("id") - private String id; - - @JsonProperty("is_system_workflow") - private boolean isSystemWorkflow; - - @JsonProperty("parameters") - private Map parameters; - - @JsonProperty("status") - private String status; - - @JsonProperty("tenant_name") - private String tenantName; - - @JsonProperty("workflow_id") - private String workflowId; - - public String getBlueprintId() { - return blueprintId; - } - - public void setBlueprintId(String blueprintId) { - this.blueprintId = blueprintId; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public String getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - - public String getDeploymentId() { - return deploymentId; - } - - public void setDeploymentId(String deploymentId) { - this.deploymentId = deploymentId; - } - - public String getError() { - return error; - } - - public void setError(String error) { - this.error = error; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public boolean isSystemWorkflow() { - return isSystemWorkflow; - } - - public void setSystemWorkflow(boolean isSystemWorkflow) { - this.isSystemWorkflow = isSystemWorkflow; - } - - public Map getParameters() { - return parameters; - } - - public void setParameters(Map parameters) { - this.parameters = parameters; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getTenantName() { - return tenantName; - } - - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public String getWorkflowId() { - return workflowId; - } - - public void setWorkflowId(String workflowId) { - this.workflowId = workflowId; - } - - @Override - public String toString() { - return "Execution{" + - "id='" + id + '\'' + - ", blueprintId='" + blueprintId + '\'' + - ", createdBy='" + createdBy + '\'' + - ", createdAt=" + createdAt + - ", deploymentId='" + deploymentId + '\'' + - ", error=" + error + - ", isSystemWorkflow=" + isSystemWorkflow + - ", status=" + status + - ", tenantName='" + tenantName + '\'' + - ", parameters=" + parameters + - '}'; - } - - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Executions.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Executions.java deleted file mode 100644 index a1d9077864..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Executions.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.io.Serializable; -import java.util.List; - -public class Executions implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("items") - private List items; - - @JsonProperty("metadata") - private Metadata metadata; - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Metadata.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Metadata.java deleted file mode 100644 index 31e3b0dbe3..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Metadata.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.io.Serializable; - -/** - * This class represents a generic Cloudify response to a GET command. - * These responses have a common format: - * { - * "items": [ - * List of objects of the requested type - * ], - * "metadata": { - * } - * } - * - * @author jc1348 - * - */ -public class Metadata implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("pagination") - private Pagination pagination; - - - public Pagination getPagination() { - return pagination; - } - - public void setPagination(Pagination pagination) { - this.pagination = pagination; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/NodeInstance.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/NodeInstance.java deleted file mode 100644 index f23d9bebd5..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/NodeInstance.java +++ /dev/null @@ -1,205 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.Serializable; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonRootName; - -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonRootName("node_instance") -public class NodeInstance implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("created_by") - private String createdBy; - - @JsonProperty("deployment_id") - private String deploymentId; - - @JsonProperty("host_id") - private String hostId; - - @JsonProperty("id") - private String id; - - @JsonProperty("node_id") - private String nodeId; - - @JsonProperty("relationships") - private List relationships = null; - - @JsonProperty("runtime_properties") - private Map runtimeProperties = null; - - @JsonProperty("scaling_groups") - private List scalingGroups; - - @JsonProperty("state") - private String state; - - @JsonProperty("tenant_name") - private String tenantName; - - @JsonProperty("version") - private String version; - - public String getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - - public String getDeploymentId() { - return deploymentId; - } - - public void setDeploymentId(String deploymentId) { - this.deploymentId = deploymentId; - } - - public String getHostId() { - return hostId; - } - - public void setHostId(String hostId) { - this.hostId = hostId; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getNodeId() { - return nodeId; - } - - public void setNodeId(String nodeId) { - this.nodeId = nodeId; - } - - public List getRelationships() { - return relationships; - } - - public void setRelationships(List relationships) { - this.relationships = relationships; - } - - public Map getRuntimeProperties() { - return runtimeProperties; - } - - public void setRuntimeProperties(Map runtimeProperties) { - this.runtimeProperties = runtimeProperties; - } - - public List getScalingGroups() { - return scalingGroups; - } - - public void setScalingGroups(List scalingGroups) { - this.scalingGroups = scalingGroups; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getTenantName() { - return tenantName; - } - - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - /* - * Nested structure representing scaling groups in which this node is a member - */ - public static final class ScalingGroupIdentifier - { - @JsonProperty("name") - private String name; - - @JsonProperty("id") - private String id; - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - - public String toString() { - return "Scaling Group{ name=" + name + ", id=" + id + "}"; - } - } - - @Override - public String toString() { - return "Deployment{" + - "id='" + id + '\'' + - "nodeId='" + nodeId + '\'' + - ", createdBy='" + createdBy + '\'' + - ", tenantName='" + tenantName + '\'' + - ", state=" + state + - ", deploymentId=" + deploymentId + - ", hostId='" + hostId + '\'' + - ", version='" + version + '\'' + - ", relationships=" + relationships + - ", runtimeProperties=" + runtimeProperties + - ", scalingGroups=" + scalingGroups + - '}'; - } - - // TODO: Need an object structure for Relationships -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/NodeInstances.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/NodeInstances.java deleted file mode 100644 index bac826cda0..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/NodeInstances.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.io.Serializable; -import java.util.List; - -public class NodeInstances implements Serializable{ - - private static final long serialVersionUID = 1L; - - @JsonProperty("items") - private List items; - - @JsonProperty("metadata") - private Metadata metadata; - - public List getItems() { - return items; - } - - public void setItems(List items) { - this.items = items; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/OpenstackConfig.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/OpenstackConfig.java deleted file mode 100644 index 2d927e64e6..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/OpenstackConfig.java +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class OpenstackConfig implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("username") - String username; - - @JsonProperty("password") - String password; - - @JsonProperty("tenant_name") - String tenantName; - - @JsonProperty("auth_url") - String authUrl; - - @JsonProperty("region") - String region; - - // NOTE: Not supporting "custom_configuration" - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getTenantName() { - return tenantName; - } - - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public String getAuthUrl() { - return authUrl; - } - - public void setAuthUrl(String authUrl) { - this.authUrl = authUrl; - } - - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Pagination.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Pagination.java deleted file mode 100644 index a79f053ca2..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Pagination.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Pagination { - @JsonProperty("total") - private int total; - @JsonProperty("offset") - private int offset; - @JsonProperty("size") - private int size; - - public int getTotal() { - return total; - } - public void setTotal(int total) { - this.total = total; - } - public int getOffset() { - return offset; - } - public void setOffset(int offset) { - this.offset = offset; - } - public int getSize() { - return size; - } - public void setSize(int size) { - this.size = size; - } -} \ No newline at end of file diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/ParameterDefinition.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/ParameterDefinition.java deleted file mode 100644 index 677c982621..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/ParameterDefinition.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class ParameterDefinition implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("type") - private String type; - @JsonProperty("description") - private String description; - @JsonProperty("default") - private Object defaultValue; - - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - public Object getDefaultValue() { - return defaultValue; - } - public void setDefaultValue(Object defaultValue) { - this.defaultValue = defaultValue; - } -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/StartExecutionParams.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/StartExecutionParams.java deleted file mode 100644 index 397f867e7d..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/StartExecutionParams.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.Serializable; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class StartExecutionParams implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("workflow_id") - private String workflowId; - - @JsonProperty("deployment_id") - private String deploymentId; - - @JsonProperty("allow_custom_parameters") - private boolean allowCustomParameters; - - @JsonProperty("force") - private boolean force; - - @JsonProperty("parameters") - private Map parameters; - - public String getWorkflowId() { - return workflowId; - } - - public void setWorkflowId(String workflowId) { - this.workflowId = workflowId; - } - - public String getDeploymentId() { - return deploymentId; - } - - public void setDeploymentId(String deploymentId) { - this.deploymentId = deploymentId; - } - - public boolean isAllowCustomParameters() { - return allowCustomParameters; - } - - public void setAllowCustomParameters(boolean allowCustomParameters) { - this.allowCustomParameters = allowCustomParameters; - } - - public boolean isForce() { - return force; - } - - public void setForce(boolean force) { - this.force = force; - } - - public Map getParameters() { - return parameters; - } - - public void setParameters(Map parameters) { - this.parameters = parameters; - } - - @Override - public String toString() { - return "UpdateExecutionParams{" + - "workflowId='" + workflowId + '\'' + - "deploymentId='" + deploymentId + '\'' + - "allowCustomParameters='" + allowCustomParameters + '\'' + - "force='" + force + '\'' + - "parameters='" + parameters + '\'' + - '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Token.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Token.java deleted file mode 100644 index ddf264c290..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/Token.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonIgnoreProperties(ignoreUnknown = true) -//@JsonRootName("token") -// The Token object is returned without a root element -public class Token implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("role") - private String role; - - @JsonProperty("value") - private String value; - - // Any expiration? Maybe something in the Headers? - - public String getRole() { - return role; - } - - public void setRole(String role) { - this.role = role; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - - @Override - public String toString() { - return "Token{" + - "role='" + role + '\'' + - ", value='" + value + '\'' + - '}'; - } -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/UpdateExecutionParams.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/UpdateExecutionParams.java deleted file mode 100644 index db827e9761..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/UpdateExecutionParams.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class UpdateExecutionParams implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("status") - private String status; - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - - @Override - public String toString() { - return "UpdateExecutionParams{" + - "status='" + status + '\'' + - '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/UpdateNodeInstanceParams.java b/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/UpdateNodeInstanceParams.java deleted file mode 100644 index c7f6557f7c..0000000000 --- a/cloudify-client/src/main/java/org/openecomp/mso/cloudify/v3/model/UpdateNodeInstanceParams.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============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.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.io.Serializable; -import java.util.Map; - -public class UpdateNodeInstanceParams implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("state") - private String state; - - @JsonProperty("version") - private String version; - - @JsonProperty("runtime_properties") - private Map runtimeProperties; - - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public Map getRuntimeProperties() { - return runtimeProperties; - } - - public void setRuntimeProperties(Map runtimeProperties) { - this.runtimeProperties = runtimeProperties; - } - - - @Override - public String toString() { - return "UpdateNodeInstanceParams{" + - "state='" + state + '\'' + - "version='" + version + '\'' + - ", runtimeProperties=" + runtimeProperties + - '}'; - } - -} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java new file mode 100644 index 0000000000..d38c7468db --- /dev/null +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.onap.so.cloudify; +import org.junit.Before; +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterEnum; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class BeanMultiTest { + + Validator validator; + PojoClassFilter enumFilter; + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Before + public void setup(){ + enumFilter = new FilterEnum(); + validator = ValidatorBuilder.create() + .with(new SetterMustExistRule(), + new GetterMustExistRule()) + .with(new SetterTester(), + new GetterTester()) + .build(); + } + @Test + public void validateBeansMsoApihandlerBeans() { + + validator.validate("org.onap.so.cloudify.v3.model",enumFilter); + } + + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/src/test/java"); + } + } +} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java new file mode 100644 index 0000000000..fc55eaf19c --- /dev/null +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java @@ -0,0 +1,103 @@ +/*- + * ============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.onap.so.cloudify.base.client; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.Assert.assertEquals; + +import org.apache.http.HttpStatus; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.cloudify.v3.model.Execution; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; + +public class CloudifyClientTest { + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void clientCreate(){ + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + CloudifyClient cc = new CloudifyClient("http://localhost:"+port); + cc.setToken("token"); + CloudifyRequest crx = cc.get("/testUrl", Execution.class); + Execution x = crx.execute(); + assertEquals("123", x.getId()); + } + + @Test + public void clientCreateWithBadConnector(){ + thrown.expect(CloudifyResponseException.class); + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + CloudifyClientConnector ccc = new CloudifyClientConnector(){ + @Override + public CloudifyResponse request(CloudifyRequest request) { + throw new CloudifyResponseException("test case", 401); + }}; + CloudifyClient cc = new CloudifyClient("http://localhost:"+port, ccc); +// cc.setToken("token"); + CloudifyRequest crx = cc.get("/testUrl", Execution.class); + Execution x = crx.execute(); + } + + @Test + public void clientCreateWithBadConnectorAndToken(){ + thrown.expect(CloudifyResponseException.class); + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + CloudifyClientConnector ccc = new CloudifyClientConnector(){ + @Override + public CloudifyResponse request(CloudifyRequest request) { + throw new CloudifyResponseException("test case", 401); + }}; + CloudifyClient cc = new CloudifyClient("http://localhost:"+port, ccc); + cc.setToken("token"); + CloudifyRequest crx = cc.get("/testUrl", Execution.class); + Execution x = crx.execute(); + } + + @Test + public void clientCreateWithTenant(){ + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + CloudifyClient cc = new CloudifyClient("http://localhost:"+port, "other_tenant"); + cc.setToken("token"); + cc.property("property", "value"); + CloudifyRequest crx = cc.get("/testUrl", Execution.class); + Execution x = crx.execute(); + assertEquals("123", x.getId()); + } + +} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java new file mode 100644 index 0000000000..ba43dc9e78 --- /dev/null +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.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.onap.so.cloudify.base.client; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.Assert.assertEquals; + +import org.apache.http.HttpStatus; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; + +public class CloudifyClientTokenProviderTest { + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void createTokenProvider() { + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl/api/v3/tokens")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("{\"role\": \"user\", \"value\": \"tokenVal\"}").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + + CloudifyClientTokenProvider cctp = new CloudifyClientTokenProvider("http://localhost:"+port+"/testUrl", "user", "pswd"); + String token = cctp.getToken(); + assertEquals("tokenVal", token); + token = cctp.getToken(); + assertEquals("tokenVal", token); + cctp.expireToken(); + } +} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java new file mode 100644 index 0000000000..4475fff093 --- /dev/null +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java @@ -0,0 +1,254 @@ +/*- + * ============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.onap.so.cloudify.connector.http; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; + +import com.github.tomakehurst.wiremock.http.Fault; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.verify; +import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.deleteRequestedFor; +import org.apache.http.HttpStatus; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +import org.onap.so.cloudify.base.client.CloudifyConnectException; +import org.onap.so.cloudify.base.client.CloudifyRequest; +import org.onap.so.cloudify.base.client.CloudifyResponseException; +import org.onap.so.cloudify.base.client.Entity; +import org.onap.so.cloudify.base.client.HttpMethod; +import org.onap.so.cloudify.v3.model.Deployment; + +public class HttpClientConnectorTest { + + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void sunnyDay_POST(){ + wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest request = new CloudifyRequest(); + Deployment deployment = new Deployment(); + deployment.setId("id"); + request.entity(deployment, "application/json"); + request.endpoint("http://localhost:"+port+"/testUrl"); + request.setBasicAuthentication("USER","PASSWORD"); + request.header("Content-Type","application/json"); + request.method(HttpMethod.POST); + conector.request(request); + verify(postRequestedFor(urlEqualTo("/testUrl"))); + } + + + @Test + public void sunnyDay_GET(){ + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest request = new CloudifyRequest(); + request.endpoint("http://localhost:"+port+"/testUrl"); + request.setBasicAuthentication("USER","PASSWORD"); + request.method(HttpMethod.GET); + conector.request(request); + verify(getRequestedFor(urlEqualTo("/testUrl"))); + } + + @Test + public void sunnyDay_PUT(){ + wireMockRule.stubFor(put(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest request = new CloudifyRequest(); + request.endpoint("http://localhost:"+port+"/testUrl"); + request.setBasicAuthentication("USER","PASSWORD"); + request.method(HttpMethod.PUT); + conector.request(request); + verify(putRequestedFor(urlEqualTo("/testUrl"))); + } + + + @Test + public void sunnyDay_DELETE(){ + wireMockRule.stubFor(delete(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest request = new CloudifyRequest(); + request.endpoint("http://localhost:"+port+"/testUrl"); + request.setBasicAuthentication("USER","PASSWORD"); + request.method(HttpMethod.DELETE); + conector.request(request); + verify(deleteRequestedFor(urlEqualTo("/testUrl"))); + } + + + @Test + public void rainyDay_PATCH(){ + thrown.expect(HttpClientException.class); + thrown.expectMessage("Unrecognized HTTP Method: PATCH"); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest request = new CloudifyRequest(); + request.endpoint("http://localhost:123123/testUrl"); + request.setBasicAuthentication("USER","PASSWORD"); + request.method(HttpMethod.PATCH); + conector.request(request); + + } + + @Test + public void rainyDayRunTimeException(){ + wireMockRule.stubFor(post(urlEqualTo("/503")).willReturn( + aResponse().withStatus(503).withHeader("Content-Type", "text/plain").withBody("failure"))); + thrown.expect(RuntimeException.class); + thrown.expectMessage("Unexpected client exception"); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest request = new CloudifyRequest(); + request.endpoint("http://localhost:123123/503"); + request.setBasicAuthentication("USER","PASSWORD"); + request.method(HttpMethod.POST); + conector.request(request); + + } + + @Test + public void rainyDayBadUri() { + wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + thrown.expect(HttpClientException.class); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest request = new CloudifyRequest(); + Deployment deployment = new Deployment(); + deployment.setId("id"); + request.entity(deployment, "application/json"); + request.endpoint("(@#$@(#*$&asfasdf"); + request.setBasicAuthentication("USER","PASSWORD"); + request.header("Content-Type","application/json"); + request.method(HttpMethod.POST); + conector.request(request); + } + + @Test + public void sunnyDayWithJsonEntity_POST(){ + wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + + Deployment deployment = new Deployment(); + deployment.setId("id"); + + CloudifyRequest request = new CloudifyRequest(null, HttpMethod.POST, "/", Entity.json(deployment), null); + + request.endpoint("http://localhost:"+port); + request.path("testUrl"); + request.header("Content-Type","application/json"); + request.header("Content-Type", null); + + request.returnType(Deployment.class); + assertEquals(Deployment.class, request.returnType()); + + Entity t = request.json(deployment); + assertEquals(t.getEntity().getId(), "id"); + + request.queryParam("test", "one").queryParam("test", "two"); + + conector.request(request); + + verify(postRequestedFor(urlEqualTo("/testUrl?test=two"))); + } + + @Test + public void sunnyDayWithStreamEntity_POST() { + wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + + InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); + + CloudifyRequest request = new CloudifyRequest(null, HttpMethod.POST, "/testUrl", Entity.stream(is), null); + + request.endpoint("http://localhost:"+port); + request.setBasicAuthentication("USER","PASSWORD"); + request.header("Content-Type","application/json"); + + conector.request(request); + verify(postRequestedFor(urlEqualTo("/testUrl"))); + } + + @Test + public void rainyDayGarbageData(){ + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn( + aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE))); + thrown.expect(CloudifyConnectException.class); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest request = new CloudifyRequest(); + request.endpoint("http://localhost:"+port+"/testUrl"); + request.setBasicAuthentication("USER","PASSWORD"); + request.method(HttpMethod.GET); + conector.request(request); + } + + @Test + public void rainyDayEmptyResponse(){ + wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_NOT_FOUND))); + + thrown.expect(HttpClientException.class); + int port = wireMockRule.port(); + HttpClientConnector conector = new HttpClientConnector(); + CloudifyRequest request = new CloudifyRequest(); + request.endpoint("http://localhost:"+port+"/testUrl"); + request.setBasicAuthentication("USER","PASSWORD"); + request.method(HttpMethod.GET); + conector.request(request); // gets down to "Get here on an error response (4XX-5XX)", then tries to throw a CloudifyResponseException, which calls getEntity, which tries to parse an HTML error page as a JSON, which causes the HttpClientException. + } + + +} \ No newline at end of file diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java new file mode 100644 index 0000000000..6155cf287c --- /dev/null +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java @@ -0,0 +1,147 @@ +/*- + * ============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.onap.so.cloudify.v3.client; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.Assert.assertEquals; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +import org.apache.http.HttpStatus; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.cloudify.v3.client.BlueprintsResource.DeleteBlueprint; +import org.onap.so.cloudify.v3.client.BlueprintsResource.GetBlueprint; +import org.onap.so.cloudify.v3.client.BlueprintsResource.ListBlueprints; +import org.onap.so.cloudify.v3.client.BlueprintsResource.UploadBlueprint; +import org.onap.so.cloudify.v3.model.Blueprint; +import org.onap.so.cloudify.v3.model.Blueprints; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; + +public class BlueprintsResourceTest { + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void cloudifyClientBlueprintFromStream() { + wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"id\": \"123\"}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + BlueprintsResource br = c.blueprints(); + InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); + UploadBlueprint ub = br.uploadFromStream("123", "blueprint.json", is); + Blueprint b = ub.execute(); + assertEquals("123", b.getId()); + } + + @Test + public void cloudifyClientBlueprintFromUrl() { + wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"id\": \"123\"}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + BlueprintsResource br = c.blueprints(); + UploadBlueprint ub = br.uploadFromUrl("123", "blueprint.json", "http://localhost:"+port+"/blueprint"); + Blueprint b = ub.execute(); + assertEquals("123", b.getId()); + } + + @Test + public void cloudifyClientBlueprintDelete() { + wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"id\": \"123\"}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + BlueprintsResource br = c.blueprints(); + DeleteBlueprint db = br.deleteById("123"); + Blueprint b = db.execute(); + assertEquals("123", b.getId()); + } + + @Test + public void cloudifyClientBlueprintList() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"items\": [{\"id\": \"123\"}]}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + BlueprintsResource br = c.blueprints(); + ListBlueprints lb = br.list(); + Blueprints b = lb.execute(); + assertEquals("123", b.getItems().get(0).getId()); + } + + @Test + public void cloudifyClientBlueprintGetById() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"id\": \"123\"}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + BlueprintsResource br = c.blueprints(); + GetBlueprint gb = br.getById("123"); + Blueprint b = gb.execute(); + assertEquals("123", b.getId()); + } + + @Test + public void cloudifyClientBlueprintGetMetadataById() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"id\": \"123\"}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + BlueprintsResource br = c.blueprints(); + GetBlueprint gb = br.getMetadataById("123"); + Blueprint b = gb.execute(); + assertEquals("123", b.getId()); + } + + +} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java new file mode 100644 index 0000000000..071b7638e6 --- /dev/null +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java @@ -0,0 +1,148 @@ +/*- + * ============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.onap.so.cloudify.v3.client; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.http.HttpStatus; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.cloudify.v3.client.DeploymentsResource.CreateDeployment; +import org.onap.so.cloudify.v3.client.DeploymentsResource.DeleteDeployment; +import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeployment; +import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeploymentOutputs; +import org.onap.so.cloudify.v3.client.DeploymentsResource.ListDeployments; +import org.onap.so.cloudify.v3.model.CreateDeploymentParams; +import org.onap.so.cloudify.v3.model.Deployment; +import org.onap.so.cloudify.v3.model.Deployments; +import org.onap.so.cloudify.v3.model.DeploymentOutputs; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; + +public class DeploymentsResourceTest { + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void cloudifyDeploymentsCreate() { + wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/deployments/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + DeploymentsResource br = c.deployments(); + + CreateDeploymentParams cdp = new CreateDeploymentParams(); + cdp.setBlueprintId("123"); + Map inputs = new HashMap(); + cdp.setInputs(inputs); + CreateDeployment cd = br.create("123", cdp); + Deployment d = cd.execute(); + assertEquals("123", d.getId()); + } + + @Test + public void cloudifyDeploymentsList() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"items\": {\"id\": \"123\" } } ") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + DeploymentsResource br = c.deployments(); + ListDeployments ld = br.list(); + Deployments d = ld.execute(); + assertEquals("123", d.getItems().get(0).getId()); + } + + @Test + public void cloudifyDeploymentsGet() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + DeploymentsResource br = c.deployments(); + GetDeployment gd = br.byId("123"); + Deployment d = gd.execute(); + assertEquals("123", d.getId()); + } + + @Test + public void cloudifyDeploymentsGetOutputs() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123/outputs")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"deployment_id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + DeploymentsResource br = c.deployments(); + GetDeploymentOutputs gdo = br.outputsById("123"); + DeploymentOutputs d = gdo.execute(); + assertEquals("123", d.getDeploymentId()); + + Map map = new HashMap(); + map.put("test", "answer"); + assertEquals("answer", d.getMapValue(map, "test", String.class)); + + Integer i = d.getMapValue(map, "nil", Integer.class); + assertNull( i ); + + i = d.getMapValue(map, "test", Integer.class); + assertNull( i ); + } + + @Test + public void cloudifyDeploymentsDelete() { + wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/deployments/name")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + DeploymentsResource br = c.deployments(); + DeleteDeployment cd = br.deleteByName("name"); + Deployment d = cd.execute(); + assertEquals("123", d.getId()); + } + +} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java new file mode 100644 index 0000000000..098b5cf387 --- /dev/null +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java @@ -0,0 +1,170 @@ +/*- + * ============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.onap.so.cloudify.v3.client; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.patch; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.Assert.assertEquals; + +import org.apache.http.HttpStatus; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.cloudify.connector.http.HttpClientException; +import org.onap.so.cloudify.v3.client.ExecutionsResource.CancelExecution; +import org.onap.so.cloudify.v3.client.ExecutionsResource.GetExecution; +import org.onap.so.cloudify.v3.client.ExecutionsResource.ListExecutions; +import org.onap.so.cloudify.v3.client.ExecutionsResource.StartExecution; +import org.onap.so.cloudify.v3.client.ExecutionsResource.UpdateExecution; +import org.onap.so.cloudify.v3.model.CancelExecutionParams; +import org.onap.so.cloudify.v3.model.Execution; +import org.onap.so.cloudify.v3.model.Executions; +import org.onap.so.cloudify.v3.model.StartExecutionParams; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; + +public class ExecutionsResourceTest { + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void cloudifyClientExecutions() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"items\": [{ \"id\": \"345\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + ExecutionsResource xr = c.executions(); + ListExecutions lx = xr.list(); + Executions x = lx.execute(); + assertEquals("123", x.getItems().get(1).getId()); + } + + @Test + public void cloudifyClientExecutionsSorted() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"items\": [{ \"id\": \"123\" }, { \"id\": \"345\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + ExecutionsResource xr = c.executions(); + ListExecutions lx = xr.listSorted("id"); + Executions x = lx.execute(); + assertEquals("345", x.getItems().get(1).getId()); + } + + @Test + public void cloudifyClientExecutionsFilter() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{\"items\": [{ \"id\": \"121\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + ExecutionsResource xr = c.executions(); + ListExecutions lx = xr.listFiltered("a=b", "id"); + Executions x = lx.execute(); + assertEquals("123", x.getItems().get(1).getId()); + } + + @Test + public void cloudifyClientExecutionById() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + ExecutionsResource xr = c.executions(); + GetExecution gx = xr.byId("123"); + Execution x = gx.execute(); + assertEquals("123", x.getId()); + } + + @Test + public void cloudifyClientStartExecution() { + wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + ExecutionsResource xr = c.executions(); + + StartExecutionParams params = new StartExecutionParams(); + StartExecution sx = xr.start(params); + Execution x = sx.execute(); + assertEquals("123", x.getId()); + } + + @Test + public void cloudifyClientUpdateExecution() { + thrown.expect(HttpClientException.class); + thrown.expectMessage("Unrecognized HTTP Method: PATCH"); + + wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + ExecutionsResource xr = c.executions(); + + UpdateExecution ux = xr.updateStatus("123", "good"); + Execution x = ux.execute(); + assertEquals("123", x.getId()); + } + + @Test + public void cloudifyClientCancelExecution() { + wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"id\": \"123\" }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + ExecutionsResource xr = c.executions(); + + CancelExecutionParams params = new CancelExecutionParams(); + CancelExecution cx = xr.cancel("123", params); + Execution x = cx.execute(); + assertEquals("123", x.getId()); + } + + + +} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java new file mode 100644 index 0000000000..c5f3be4ce2 --- /dev/null +++ b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java @@ -0,0 +1,98 @@ +/*- + * ============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.onap.so.cloudify.v3.client; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.patch; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.Assert.assertEquals; + +import org.apache.http.HttpStatus; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.cloudify.connector.http.HttpClientException; +import org.onap.so.cloudify.v3.client.NodeInstancesResource.GetNodeInstance; +import org.onap.so.cloudify.v3.client.NodeInstancesResource.ListNodeInstances; +import org.onap.so.cloudify.v3.client.NodeInstancesResource.UpdateNodeInstance; +import org.onap.so.cloudify.v3.model.NodeInstance; +import org.onap.so.cloudify.v3.model.NodeInstances; +import org.onap.so.cloudify.v3.model.UpdateNodeInstanceParams; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; + +public class NodeInstancesResourceTest { + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void nodeInstanceGet() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances/123")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"node_instance\": { \"id\": \"123\" } }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + NodeInstancesResource nir = c.nodeInstances(); + GetNodeInstance gni = nir.byId("123"); + NodeInstance ni = gni.execute(); + assertEquals("123", ni.getId()); + } + + @Test + public void nodeInstanceList() { + wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances")).willReturn(aResponse().withHeader("Content-Type", "application/json") +// .withBody(" { \"items\": [ { \"node_instance\": { \"id\": \"123\" } } ] } ") + .withBody(" { \"items\": [ { \"id\": \"123\" } ] } ") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + NodeInstancesResource nir = c.nodeInstances(); + ListNodeInstances lni = nir.list(); + NodeInstances ni = lni.execute(); + assertEquals("123", ni.getItems().get(0).getId()); + } + + @Test + public void nodeInstanceUpdate() { + wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/node-instances/")).willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"node_instance\": { \"id\": \"123\" } }") + .withStatus(HttpStatus.SC_OK))); + + int port = wireMockRule.port(); + + Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); + NodeInstancesResource nir = c.nodeInstances(); + UpdateNodeInstanceParams params = new UpdateNodeInstanceParams(); + + UpdateNodeInstance uni = nir.update("123", params); + thrown.expect(HttpClientException.class); /// ??????? + NodeInstance ni = uni.execute(); + } +} diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/BeanMultiTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/BeanMultiTest.java deleted file mode 100644 index 5eaa27f11f..0000000000 --- a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/BeanMultiTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============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.cloudify; - -import org.junit.Before; -import org.junit.Test; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.PojoClassFilter; -import com.openpojo.reflection.filters.FilterEnum; -import com.openpojo.reflection.impl.PojoClassFactory; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; - -public class BeanMultiTest { - - Validator validator; - PojoClassFilter enumFilter; - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - - @Before - public void setup(){ - enumFilter = new FilterEnum(); - validator = ValidatorBuilder.create() - .with(new SetterMustExistRule(), - new GetterMustExistRule()) - .with(new SetterTester(), - new GetterTester()) - .build(); - } - @Test - public void validateBeansMsoApihandlerBeans() { - validator.validate("org.openecomp.mso.cloudify.v3.model",enumFilter); - } - - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/src/test/java"); - } - } -} \ No newline at end of file diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTest.java deleted file mode 100644 index 1836bc5d6e..0000000000 --- a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * ============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.base.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; - -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.openecomp.mso.cloudify.v3.model.Execution; - -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class CloudifyClientTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void clientCreate(){ - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClient cc = new CloudifyClient("http://localhost:"+port); - cc.setToken("token"); - CloudifyRequest crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void clientCreateWithBadConnector(){ - thrown.expect(CloudifyResponseException.class); - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClientConnector ccc = new CloudifyClientConnector(){ - @Override - public CloudifyResponse request(CloudifyRequest request) { - throw new CloudifyResponseException("test case", 401); - }}; - CloudifyClient cc = new CloudifyClient("http://localhost:"+port, ccc); -// cc.setToken("token"); - CloudifyRequest crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - } - - @Test - public void clientCreateWithBadConnectorAndToken(){ - thrown.expect(CloudifyResponseException.class); - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClientConnector ccc = new CloudifyClientConnector(){ - @Override - public CloudifyResponse request(CloudifyRequest request) { - throw new CloudifyResponseException("test case", 401); - }}; - CloudifyClient cc = new CloudifyClient("http://localhost:"+port, ccc); - cc.setToken("token"); - CloudifyRequest crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - } - - @Test - public void clientCreateWithTenant(){ - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClient cc = new CloudifyClient("http://localhost:"+port, "other_tenant"); - cc.setToken("token"); - cc.property("property", "value"); - CloudifyRequest crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - assertEquals("123", x.getId()); - } - -} diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProviderTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProviderTest.java deleted file mode 100644 index c28b6b91aa..0000000000 --- a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/base/client/CloudifyClientTokenProviderTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============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.base.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; - -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class CloudifyClientTokenProviderTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void createTokenProvider() { - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("{\"role\": \"user\", \"value\": \"tokenVal\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - - CloudifyClientTokenProvider cctp = new CloudifyClientTokenProvider("http://localhost:"+port+"/testUrl", "user", "pswd"); - String token = cctp.getToken(); - assertEquals("tokenVal", token); - token = cctp.getToken(); - assertEquals("tokenVal", token); - cctp.expireToken(); - } -} diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/connector/http/HttpClientConnectorTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/connector/http/HttpClientConnectorTest.java deleted file mode 100644 index 72d2de6e9d..0000000000 --- a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/connector/http/HttpClientConnectorTest.java +++ /dev/null @@ -1,251 +0,0 @@ -/*- - * ============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.cloudify.connector.http; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; - -import com.github.tomakehurst.wiremock.http.Fault; -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.delete; -import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; -import static com.github.tomakehurst.wiremock.client.WireMock.verify; -import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; -import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor; -import static com.github.tomakehurst.wiremock.client.WireMock.deleteRequestedFor; -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertEquals; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; - -import org.openecomp.mso.cloudify.base.client.CloudifyConnectException; -import org.openecomp.mso.cloudify.base.client.CloudifyRequest; -import org.openecomp.mso.cloudify.base.client.CloudifyResponseException; -import org.openecomp.mso.cloudify.base.client.Entity; -import org.openecomp.mso.cloudify.base.client.HttpMethod; -import org.openecomp.mso.cloudify.v3.model.Deployment; - -public class HttpClientConnectorTest { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void sunnyDay_POST(){ - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest request = new CloudifyRequest(); - Deployment deployment = new Deployment(); - deployment.setId("id"); - request.entity(deployment, "application/json"); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.header("Content-Type","application/json"); - request.method(HttpMethod.POST); - conector.request(request); - verify(postRequestedFor(urlEqualTo("/testUrl"))); - } - - - @Test - public void sunnyDay_GET(){ - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest request = new CloudifyRequest(); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.GET); - conector.request(request); - verify(getRequestedFor(urlEqualTo("/testUrl"))); - } - - @Test - public void sunnyDay_PUT(){ - wireMockRule.stubFor(put(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest request = new CloudifyRequest(); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.PUT); - conector.request(request); - verify(putRequestedFor(urlEqualTo("/testUrl"))); - } - - - @Test - public void sunnyDay_DELETE(){ - wireMockRule.stubFor(delete(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest request = new CloudifyRequest(); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.DELETE); - conector.request(request); - verify(deleteRequestedFor(urlEqualTo("/testUrl"))); - } - - - @Test - public void rainyDay_PATCH(){ - thrown.expect(HttpClientException.class); - thrown.expectMessage("Unrecognized HTTP Method: PATCH"); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest request = new CloudifyRequest(); - request.endpoint("http://localhost:123123/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.PATCH); - conector.request(request); - - } - - @Test - public void rainyDayRunTimeException(){ - wireMockRule.stubFor(post(urlEqualTo("/503")).willReturn( - aResponse().withStatus(503).withHeader("Content-Type", "text/plain").withBody("failure"))); - thrown.expect(RuntimeException.class); - thrown.expectMessage("Unexpected client exception"); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest request = new CloudifyRequest(); - request.endpoint("http://localhost:123123/503"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.POST); - conector.request(request); - - } - - @Test - public void rainyDayBadUri() { - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - thrown.expect(HttpClientException.class); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest request = new CloudifyRequest(); - Deployment deployment = new Deployment(); - deployment.setId("id"); - request.entity(deployment, "application/json"); - request.endpoint("(@#$@(#*$&asfasdf"); - request.setBasicAuthentication("USER","PASSWORD"); - request.header("Content-Type","application/json"); - request.method(HttpMethod.POST); - conector.request(request); - } - - @Test - public void sunnyDayWithJsonEntity_POST(){ - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - - Deployment deployment = new Deployment(); - deployment.setId("id"); - - CloudifyRequest request = new CloudifyRequest(null, HttpMethod.POST, "/", Entity.json(deployment), null); - - request.endpoint("http://localhost:"+port); - request.path("testUrl"); - request.header("Content-Type","application/json"); - request.header("Content-Type", null); - - request.returnType(Deployment.class); - assertEquals(Deployment.class, request.returnType()); - - Entity t = request.json(deployment); - assertEquals(t.getEntity().getId(), "id"); - - request.queryParam("test", "one").queryParam("test", "two"); - - conector.request(request); - - verify(postRequestedFor(urlEqualTo("/testUrl?test=two"))); - } - - @Test - public void sunnyDayWithStreamEntity_POST() { - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - - InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); - - CloudifyRequest request = new CloudifyRequest(null, HttpMethod.POST, "/testUrl", Entity.stream(is), null); - - request.endpoint("http://localhost:"+port); - request.setBasicAuthentication("USER","PASSWORD"); - request.header("Content-Type","application/json"); - - conector.request(request); - verify(postRequestedFor(urlEqualTo("/testUrl"))); - } - - @Test - public void rainyDayGarbageData(){ - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn( - aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE))); - thrown.expect(CloudifyConnectException.class); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest request = new CloudifyRequest(); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.GET); - conector.request(request); - } - - @Test - public void rainyDayEmptyResponse(){ - thrown.expect(HttpClientException.class); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest request = new CloudifyRequest(); - request.endpoint("http://localhost:"+port+"/testUrl"); - request.setBasicAuthentication("USER","PASSWORD"); - request.method(HttpMethod.GET); - conector.request(request); // gets down to "Get here on an error response (4XX-5XX)", then tries to throw a CloudifyResponseException, which calls getEntity, which tries to parse an HTML error page as a JSON, which causes the HttpClientException. - } - - -} \ No newline at end of file diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResourceTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResourceTest.java deleted file mode 100644 index 5e443a5c69..0000000000 --- a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/BlueprintsResourceTest.java +++ /dev/null @@ -1,147 +0,0 @@ -/*- - * ============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.v3.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.delete; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; - -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.openecomp.mso.cloudify.v3.client.BlueprintsResource.DeleteBlueprint; -import org.openecomp.mso.cloudify.v3.client.BlueprintsResource.GetBlueprint; -import org.openecomp.mso.cloudify.v3.client.BlueprintsResource.ListBlueprints; -import org.openecomp.mso.cloudify.v3.client.BlueprintsResource.UploadBlueprint; -import org.openecomp.mso.cloudify.v3.model.Blueprint; -import org.openecomp.mso.cloudify.v3.model.Blueprints; - -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class BlueprintsResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void cloudifyClientBlueprintFromStream() { - wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); - UploadBlueprint ub = br.uploadFromStream("123", "blueprint.json", is); - Blueprint b = ub.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintFromUrl() { - wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - UploadBlueprint ub = br.uploadFromUrl("123", "blueprint.json", "http://localhost:"+port+"/blueprint"); - Blueprint b = ub.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintDelete() { - wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/blueprints/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - DeleteBlueprint db = br.deleteById("123"); - Blueprint b = db.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintList() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"items\": [{\"id\": \"123\"}]}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - ListBlueprints lb = br.list(); - Blueprints b = lb.execute(); - assertEquals("123", b.getItems().get(0).getId()); - } - - @Test - public void cloudifyClientBlueprintGetById() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - GetBlueprint gb = br.getById("123"); - Blueprint b = gb.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintGetMetadataById() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - BlueprintsResource br = c.blueprints(); - GetBlueprint gb = br.getMetadataById("123"); - Blueprint b = gb.execute(); - assertEquals("123", b.getId()); - } - - -} diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/DeploymentsResourceTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/DeploymentsResourceTest.java deleted file mode 100644 index f4741b9b08..0000000000 --- a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/DeploymentsResourceTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/*- - * ============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.v3.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.delete; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.openecomp.mso.cloudify.v3.client.DeploymentsResource.CreateDeployment; -import org.openecomp.mso.cloudify.v3.client.DeploymentsResource.DeleteDeployment; -import org.openecomp.mso.cloudify.v3.client.DeploymentsResource.GetDeployment; -import org.openecomp.mso.cloudify.v3.client.DeploymentsResource.GetDeploymentOutputs; -import org.openecomp.mso.cloudify.v3.client.DeploymentsResource.ListDeployments; -import org.openecomp.mso.cloudify.v3.model.CreateDeploymentParams; -import org.openecomp.mso.cloudify.v3.model.Deployment; -import org.openecomp.mso.cloudify.v3.model.Deployments; -import org.openecomp.mso.cloudify.v3.model.DeploymentOutputs; - -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class DeploymentsResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void cloudifyDeploymentsCreate() { - wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/deployments/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - DeploymentsResource br = c.deployments(); - - CreateDeploymentParams cdp = new CreateDeploymentParams(); - cdp.setBlueprintId("123"); - Map inputs = new HashMap(); - cdp.setInputs(inputs); - CreateDeployment cd = br.create("123", cdp); - Deployment d = cd.execute(); - assertEquals("123", d.getId()); - } - - @Test - public void cloudifyDeploymentsList() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"items\": {\"id\": \"123\" } } ") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - DeploymentsResource br = c.deployments(); - ListDeployments ld = br.list(); - Deployments d = ld.execute(); - assertEquals("123", d.getItems().get(0).getId()); - } - - @Test - public void cloudifyDeploymentsGet() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - DeploymentsResource br = c.deployments(); - GetDeployment gd = br.byId("123"); - Deployment d = gd.execute(); - assertEquals("123", d.getId()); - } - - @Test - public void cloudifyDeploymentsGetOutputs() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"deployment_id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - DeploymentsResource br = c.deployments(); - GetDeploymentOutputs gdo = br.outputsById("123"); - DeploymentOutputs d = gdo.execute(); - assertEquals("123", d.getDeploymentId()); - - Map map = new HashMap(); - map.put("test", "answer"); - assertEquals("answer", d.getMapValue(map, "test", String.class)); - - Integer i = d.getMapValue(map, "nil", Integer.class); - assertNull( i ); - - i = d.getMapValue(map, "test", Integer.class); - assertNull( i ); - } - - @Test - public void cloudifyDeploymentsDelete() { - wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/deployments/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - DeploymentsResource br = c.deployments(); - DeleteDeployment cd = br.deleteByName("name"); - Deployment d = cd.execute(); - assertEquals("123", d.getId()); - } - -} diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResourceTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResourceTest.java deleted file mode 100644 index 93f5473159..0000000000 --- a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/ExecutionsResourceTest.java +++ /dev/null @@ -1,170 +0,0 @@ -/*- - * ============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.v3.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.patch; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; - -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.openecomp.mso.cloudify.connector.http.HttpClientException; -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.client.ExecutionsResource.UpdateExecution; -import org.openecomp.mso.cloudify.v3.model.CancelExecutionParams; -import org.openecomp.mso.cloudify.v3.model.Execution; -import org.openecomp.mso.cloudify.v3.model.Executions; -import org.openecomp.mso.cloudify.v3.model.StartExecutionParams; - -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class ExecutionsResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void cloudifyClientExecutions() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"items\": [{ \"id\": \"345\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - ListExecutions lx = xr.list(); - Executions x = lx.execute(); - assertEquals("123", x.getItems().get(1).getId()); - } - - @Test - public void cloudifyClientExecutionsSorted() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"items\": [{ \"id\": \"123\" }, { \"id\": \"345\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - ListExecutions lx = xr.listSorted("id"); - Executions x = lx.execute(); - assertEquals("345", x.getItems().get(1).getId()); - } - - @Test - public void cloudifyClientExecutionsFilter() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"items\": [{ \"id\": \"121\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - ListExecutions lx = xr.listFiltered("a=b", "id"); - Executions x = lx.execute(); - assertEquals("123", x.getItems().get(1).getId()); - } - - @Test - public void cloudifyClientExecutionById() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - GetExecution gx = xr.byId("123"); - Execution x = gx.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void cloudifyClientStartExecution() { - wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - - StartExecutionParams params = new StartExecutionParams(); - StartExecution sx = xr.start(params); - Execution x = sx.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void cloudifyClientUpdateExecution() { - thrown.expect(HttpClientException.class); - thrown.expectMessage("Unrecognized HTTP Method: PATCH"); - - wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - - UpdateExecution ux = xr.updateStatus("123", "good"); - Execution x = ux.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void cloudifyClientCancelExecution() { - wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - ExecutionsResource xr = c.executions(); - - CancelExecutionParams params = new CancelExecutionParams(); - CancelExecution cx = xr.cancel("123", params); - Execution x = cx.execute(); - assertEquals("123", x.getId()); - } - - - -} diff --git a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/NodeInstancesResourceTest.java b/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/NodeInstancesResourceTest.java deleted file mode 100644 index 66616e9c8a..0000000000 --- a/cloudify-client/src/test/java/org/openecomp/mso/cloudify/v3/client/NodeInstancesResourceTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ============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.v3.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.patch; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; - -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.openecomp.mso.cloudify.connector.http.HttpClientException; -import org.openecomp.mso.cloudify.v3.client.NodeInstancesResource.GetNodeInstance; -import org.openecomp.mso.cloudify.v3.client.NodeInstancesResource.ListNodeInstances; -import org.openecomp.mso.cloudify.v3.client.NodeInstancesResource.UpdateNodeInstance; -import org.openecomp.mso.cloudify.v3.model.NodeInstance; -import org.openecomp.mso.cloudify.v3.model.NodeInstances; -import org.openecomp.mso.cloudify.v3.model.UpdateNodeInstanceParams; - -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class NodeInstancesResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void nodeInstanceGet() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"node_instance\": { \"id\": \"123\" } }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - NodeInstancesResource nir = c.nodeInstances(); - GetNodeInstance gni = nir.byId("123"); - NodeInstance ni = gni.execute(); - assertEquals("123", ni.getId()); - } - - @Test - public void nodeInstanceList() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances")).willReturn(aResponse().withHeader("Content-Type", "application/json") -// .withBody(" { \"items\": [ { \"node_instance\": { \"id\": \"123\" } } ] } ") - .withBody(" { \"items\": [ { \"id\": \"123\" } ] } ") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - NodeInstancesResource nir = c.nodeInstances(); - ListNodeInstances lni = nir.list(); - NodeInstances ni = lni.execute(); - assertEquals("123", ni.getItems().get(0).getId()); - } - - @Test - public void nodeInstanceUpdate() { - wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/node-instances/")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"node_instance\": { \"id\": \"123\" } }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:"+port, "tenant"); - NodeInstancesResource nir = c.nodeInstances(); - UpdateNodeInstanceParams params = new UpdateNodeInstanceParams(); - - UpdateNodeInstance uni = nir.update("123", params); - thrown.expect(HttpClientException.class); /// ??????? - NodeInstance ni = uni.execute(); - } -} -- cgit 1.2.3-korg