Containerization feature of SO
[so.git] / cloudify-client / src / main / java / org / onap / so / cloudify / v3 / client / BlueprintsResource.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.cloudify.v3.client;
22
23 import java.io.InputStream;
24
25 import org.onap.so.cloudify.v3.model.Blueprint;
26 import org.onap.so.cloudify.v3.model.Blueprints;
27 import org.onap.so.cloudify.base.client.Entity;
28 import org.onap.so.cloudify.base.client.HttpMethod;
29 import org.onap.so.cloudify.base.client.CloudifyClient;
30 import org.onap.so.cloudify.base.client.CloudifyRequest;
31
32 public class BlueprintsResource {
33
34     private final CloudifyClient client;
35
36     public BlueprintsResource(CloudifyClient client) {
37         this.client = client;
38     }
39
40     /*
41      * Upload a blueprint package directly.  The blueprint must be a ZIP archive.
42      * However, this method will not validate this.  
43      */
44     public UploadBlueprint uploadFromStream (String blueprintId, String mainFileName, InputStream blueprint) {
45         return new UploadBlueprint (blueprintId, mainFileName, blueprint, null);
46     }
47
48     public UploadBlueprint uploadFromUrl (String blueprintId, String mainFileName, String blueprintUrl) {
49         return new UploadBlueprint (blueprintId, mainFileName, null, blueprintUrl);
50     }
51
52     public ListBlueprints list() {
53         return new ListBlueprints();
54     }
55
56     public GetBlueprint getById(String id) {
57         return new GetBlueprint(id, "");
58     }
59
60     // Return all of the metadata, but not the plan
61     public GetBlueprint getMetadataById(String id) {
62         return new GetBlueprint(id, "?_include=id,main_file_name,description,tenant_name,created_at,updated_at");
63     }
64
65     public DeleteBlueprint deleteById(String id) {
66         return new DeleteBlueprint(id);
67     }
68
69     public class UploadBlueprint extends CloudifyRequest<Blueprint> {
70         public UploadBlueprint(String blueprintId, String mainFileName, InputStream blueprint, String blueprintUrl) {
71                 // Initialize the request elements dynamically.
72                 // Either a blueprint input stream or a URL will be provided.
73                 // If a URL is provided, add it to the query string
74                 // If a Stream is provided, set it as the Entity body
75                 super(client, HttpMethod.PUT,
76                                 "/api/v3/blueprints/" + blueprintId + "?application_file_name=" + mainFileName + ((blueprintUrl != null) ? "&blueprint_archive=" + blueprintUrl : ""),
77                                 ((blueprint != null) ? Entity.stream(blueprint) : null),
78                                 Blueprint.class);
79         }
80     }
81
82     public class DeleteBlueprint extends CloudifyRequest<Blueprint> {
83         public DeleteBlueprint(String blueprintId) {
84             super(client, HttpMethod.DELETE, "/api/v3/blueprints/" + blueprintId, null, Blueprint.class);
85         }
86     }
87
88     public class GetBlueprint extends CloudifyRequest<Blueprint> {
89         public GetBlueprint(String id, String queryArgs) {
90             super(client, HttpMethod.GET, "/api/v3/blueprints/" + id + queryArgs, null, Blueprint.class);
91         }
92     }
93
94     public class ListBlueprints extends CloudifyRequest<Blueprints> {
95         public ListBlueprints() {
96             super(client, HttpMethod.GET, "/api/v3/blueprints", null, Blueprints.class);
97        }
98     }
99
100     // TODO:  DownloadBlueprint is not supported, as it needs to return an input stream
101     //        containing the full blueprint ZIP.
102     //        For a full client library, this will require returning an open stream as the entity...
103 }