aboutsummaryrefslogtreecommitdiffstats
path: root/ccsdk-app-overlay/src/main/webapp/app/ccsdk/inventory/blueprint-service.js
blob: b553c9e475ecbd0304df0a943ec6a50139495ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
appDS2.factory('InventoryBlueprintService', function ($http, $q, $log) {
	return {
		/**
		 * Gets one page of blue prints objects.
		 * @param {Number} pageNum - page number; e.g., 1 
		 * @param {Number} viewPerPage - number of items per page; e.g., 25
		 * @return {JSON} Response object from remote side
		 */
		getBlueprints: function(pageNum,viewPerPage,sortBy,searchBy) {
			// cache control for IE
			let  cc = "&cc=" + new Date().getTime().toString();
			let url = null;
			if (sortBy && searchBy) {
				url = 'inventory/dcae-service-types?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&sortBy=' + sortBy + '&searchBy=' + searchBy + cc;
			} else if (sortBy) {
				url = 'inventory/dcae-service-types?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&sortBy=' + sortBy + cc;
			} else if (searchBy) {
				url = 'inventory/dcae-service-types?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + '&searchBy=' + searchBy + cc;
			} else {
				url = 'inventory/dcae-service-types?pageNum=' + pageNum + '&viewPerPage=' + viewPerPage + cc;
			}
			return $http({
					method: 'GET',
					url: url,
					cache: false,
					responseType: 'json' 
			}).then(function(response) {
				if (response.data == null || typeof response.data != 'object') 
					return $q.reject('InventoryBlueprintService.getBlueprints: response.data null or not object');
				else 
					return response.data;
			}, 
			function(error) {
				$log.error('InventoryBlueprintService.getBlueprints failed: ' + JSON.stringify(error));
				return $q.reject(error.statusText);
			});
		},
		/**
		 *  get deployments for a blueprint
		 */
		getDeploymentForBp: function(bpArr) {
			let url = 'inventory/dcae-services/typeIds';	
			return $http({
				method: 'POST',
				url: url,
				data: bpArr,
				responseType: 'json' 
				}).then(function(response) {
			if (response.data == null) 
				return $q.reject('InventoryBlueprintService.getDeploymentForBp: response.data null or not object');
			else {
                console.log(response.data);
                return response.data;
			}
            },
			function(error) {
				$log.error('InventoryBlueprintService.getDeploymentForBp failed: ' + JSON.stringify(error));
				return $q.reject(error.statusText);
			});
		},
		/** get all secrets
		 * 
		 */
		getSecrets: function(tenant_name) {
			let url = 'secrets?tenant=' + tenant_name;
			return $http({
				method: 'GET',
				url: url,
				cache: false,
				responseType: 'json' 
		}).then(function(response) {
			if (response.data == null) 
				return $q.reject('InventoryBlueprintService.getSecrets: response.data null or not object');
			else {
                console.log(response.data);
                return response.data;
            }
		}, 
		function(error) {
			$log.error('InventoryBlueprintService.getSecrets failed: ' + JSON.stringify(error));
			return $q.reject(error.statusText);
		});
		},
		/** get secret
		 * 
		 */
		getSecret: function(secret_name, tenant_name) {
			let url = 'secrets/' + secret_name + '?tenant=' + tenant_name;
			return $http({
				method: 'GET',
				url: url,
				cache: false,
				responseType: 'json' 
		}).then(function(response) {
			if (response.data == null) 
				return $q.reject('InventoryBlueprintService.getSecret: response.data null or not object');
			else {
                console.log(response.data);
                return response.data;
            }
		}, 
		function(error) {
			$log.error('InventoryBlueprintService.getSecret failed: ' + JSON.stringify(error));
			return $q.reject(error.statusText);
		});
		},
		/**
		 * create a cloudify secret
		 */
		createSecret: function(secretUploadRequest) {
			let url = 'secrets';
			return $http({
				method: 'POST',
				url: url,
				data: secretUploadRequest,
				responseType: 'json' 
		}).then(function(response) {
			// This is called on response code 200..299.
			// On success, response.data is null.
			// On failure, response.data has an error message.
			return response.data;
		}, 
		function(error) {
			$log.error('InventoryDeploymentService.createSecret failed: ' + JSON.stringify(error));
			return $q.reject(error.statusText);
		});
		},
		/**
		 * Get user apps
		 * @return {JSON} Response object from remote side
		 */
		getApps: function() {
			// cache control for IE
			let url = 'user-apps';
			return $http({
					method: 'GET',
					url: url,
					cache: false,
					responseType: 'json' 
			}).then(function(response) {
				if (response.data == null) 
					return $q.reject('InventoryBlueprintService.getApps: response.data null or not object');
				else {
                    console.log(response.data);
                    return response.data;
                }
			}, 
			function(error) {
				$log.error('InventoryBlueprintService.getApps failed: ' + JSON.stringify(error));
				return $q.reject(error.statusText);
			});
		},
		/**
		 * Gets blueprint components.
		 * @return {JSON} Response object from remote side
		 */
		getComponents: function() {
			// cache control for IE
			let url = 'components';
			return $http({
					method: 'GET',
					url: url,
					cache: false,
					responseType: 'json' 
			}).then(function(response) {
				if (response.data == null) 
					return $q.reject('InventoryBlueprintService.viewBlueprint: response.data null or not object');
				else {
                    console.log(response.data);
                    return response.data;
                }
			}, 
			function(error) {
				$log.error('InventoryBlueprintService.getComponents failed: ' + JSON.stringify(error));
				return $q.reject(error.statusText);
			});
		},

		insertComponent: function(componentName, displayName) {
			let url = 'components';
			let component = {
				"cname": componentName,
				"dname": displayName
			};
            return $http({
                method: 'POST',
                url: url,
				data: component,
                cache: false,
                responseType: 'json'
            }).then(function(response) {
                    if (response.data == null)
                        return $q.reject('InventoryBlueprintService.insertComponent: response.data null or not object');
                    else {
                        console.log(response);
                        return response.data;
                    }
                },
                function(error) {
                    $log.error('InventoryBlueprintService.insertComponent failed: ' + JSON.stringify(error));
                    return $q.reject(error.statusText);
                });
		},
		
		/**
		 * Gets blueprint content.
		 * @return {JSON} Response object from remote side
		 */
		viewBlueprint: function(typeId) {
			// cache control for IE
			let url = 'inventory/dcae-service-type-blueprint/' + typeId;
			return $http({
					method: 'GET',
					url: url,
					cache: false,
					responseType: 'json' 
			}).then(function(response) {
				if (response.data == null) 
					return $q.reject('InventoryBlueprintService.viewBlueprint: response.data null or not object');
				else 
					return response.data;
			}, 
			function(error) {
				$log.error('InventoryBlueprintService.viewBlueprint failed: ' + JSON.stringify(error));
				return $q.reject(error.statusText);
			});
		},

		updateBlueprint: function(serviceType) {
			let url = 'inventory/dcae-service-types/update';
			return $http({
					method: 'POST',
					url: url,
					data: serviceType,
					responseType: 'json' 
			}).then(function(response) {
				// This is called on response code 200..299.
				// On success, response.data is null.
				// On failure, response.data has an error message.
				return response.data;
			}, 
			function(error) {
				$log.error('InventoryBlueprintService.updateBlueprint failed: ' + JSON.stringify(error));
				return $q.reject(error.statusText);
			});
		},
		
		uploadBlueprint: function(serviceTypeRequest) {
			let url = 'inventory/dcae-service-types/upload';
		    let deferred = $q.defer();
		    $http({
		       method: "POST",
		       url: url,
		       data: serviceTypeRequest
		    })
		    .then( res => {
		                       deferred.resolve(res.data);
		         })
		    .catch( status => {
		                    $log.error('InventoryBlueprintService.uploadBlueprint failed: ' + status);
		                    deferred.reject(status);
		                });
		      return deferred.promise;
		},
/*
			return $http({
					method: 'POST',
					url: url,
					data: serviceTypeRequest,
					responseType: 'json' 
			}).then(function(response) {
				// This is called on response code 200..299.
				// On success, response.data is null.
				// On failure, response.data has an error message.
				return response.data;
			}, 
			function(error) {
				$log.error('InventoryBlueprintService.uploadBlueprint failed: ' + JSON.stringify(error));
				return $q.reject(error.statusText);
			});
		},	
*/		
		deleteBlueprint: function(typeId) {
			let url = 'inventory/dcae-service-types/' + typeId;
			return $http({
					method: 'DELETE',
					url: url,
					cache: false,
					responseType: 'json' 
			}).then(function(response) {
				// This is called on response code 200..299.
				// On success, response.data is null.
				// On failure, response.data has an error message.
				return response.data;
			}, 
			function(error) {
				$log.error('InventoryBlueprintService.deleteBlueprint failed: ' + JSON.stringify(error));
				return $q.reject(error.statusText);
			});
		},		
		
	};
});