2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.cloudify.v3.client;
23 import java.io.InputStream;
24 import org.onap.so.cloudify.v3.model.Blueprint;
25 import org.onap.so.cloudify.v3.model.Blueprints;
26 import org.onap.so.cloudify.base.client.Entity;
27 import org.onap.so.cloudify.base.client.HttpMethod;
28 import org.onap.so.cloudify.base.client.CloudifyClient;
29 import org.onap.so.cloudify.base.client.CloudifyRequest;
31 public class BlueprintsResource {
33 private final CloudifyClient client;
35 public BlueprintsResource(CloudifyClient client) {
40 * Upload a blueprint package directly. The blueprint must be a ZIP archive. However, this method will not validate
43 public UploadBlueprint uploadFromStream(String blueprintId, String mainFileName, InputStream blueprint) {
44 return new UploadBlueprint(blueprintId, mainFileName, blueprint, null);
47 public UploadBlueprint uploadFromUrl(String blueprintId, String mainFileName, String blueprintUrl) {
48 return new UploadBlueprint(blueprintId, mainFileName, null, blueprintUrl);
51 public ListBlueprints list() {
52 return new ListBlueprints();
55 public GetBlueprint getById(String id) {
56 return new GetBlueprint(id, "");
59 // Return all of the metadata, but not the plan
60 public GetBlueprint getMetadataById(String id) {
61 return new GetBlueprint(id, "?_include=id,main_file_name,description,tenant_name,created_at,updated_at");
64 public DeleteBlueprint deleteById(String id) {
65 return new DeleteBlueprint(id);
68 public class UploadBlueprint extends CloudifyRequest<Blueprint> {
69 public UploadBlueprint(String blueprintId, String mainFileName, InputStream blueprint, String blueprintUrl) {
70 // Initialize the request elements dynamically.
71 // Either a blueprint input stream or a URL will be provided.
72 // If a URL is provided, add it to the query string
73 // If a Stream is provided, set it as the Entity body
74 super(client, HttpMethod.PUT,
75 "/api/v3/blueprints/" + blueprintId + "?application_file_name=" + mainFileName
76 + ((blueprintUrl != null) ? "&blueprint_archive=" + blueprintUrl : ""),
77 ((blueprint != null) ? Entity.stream(blueprint) : null), Blueprint.class);
81 public class DeleteBlueprint extends CloudifyRequest<Blueprint> {
82 public DeleteBlueprint(String blueprintId) {
83 super(client, HttpMethod.DELETE, "/api/v3/blueprints/" + blueprintId, null, Blueprint.class);
87 public class GetBlueprint extends CloudifyRequest<Blueprint> {
88 public GetBlueprint(String id, String queryArgs) {
89 super(client, HttpMethod.GET, "/api/v3/blueprints/" + id + queryArgs, null, Blueprint.class);
93 public class ListBlueprints extends CloudifyRequest<Blueprints> {
94 public ListBlueprints() {
95 super(client, HttpMethod.GET, "/api/v3/blueprints", null, Blueprints.class);
99 // TODO: DownloadBlueprint is not supported, as it needs to return an input stream
100 // containing the full blueprint ZIP.
101 // For a full client library, this will require returning an open stream as the entity...