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.openecomp.sdc.be.servlets;
23 import com.fasterxml.jackson.core.JsonProcessingException;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import com.fasterxml.jackson.databind.SerializationFeature;
26 import com.google.gson.Gson;
27 import com.google.gson.GsonBuilder;
28 import com.google.gson.reflect.TypeToken;
29 import com.jcabi.aspects.Loggable;
30 import fj.data.Either;
31 import io.swagger.v3.oas.annotations.OpenAPIDefinition;
32 import io.swagger.v3.oas.annotations.Operation;
33 import io.swagger.v3.oas.annotations.Parameter;
34 import io.swagger.v3.oas.annotations.info.Info;
35 import io.swagger.v3.oas.annotations.media.ArraySchema;
36 import io.swagger.v3.oas.annotations.media.Content;
37 import io.swagger.v3.oas.annotations.media.Schema;
38 import io.swagger.v3.oas.annotations.responses.ApiResponse;
39 import io.swagger.v3.oas.annotations.responses.ApiResponses;
40 import org.apache.commons.io.IOUtils;
41 import org.apache.commons.lang.StringUtils;
42 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
43 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
44 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
45 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
46 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
47 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
48 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
49 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
50 import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
51 import org.openecomp.sdc.be.config.BeEcompErrorManager;
52 import org.openecomp.sdc.be.dao.api.ActionStatus;
53 import org.openecomp.sdc.be.datamodel.ForwardingPaths;
54 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
55 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
56 import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
57 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
58 import org.openecomp.sdc.be.impl.ComponentsUtils;
59 import org.openecomp.sdc.be.impl.ServletUtils;
60 import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
61 import org.openecomp.sdc.be.info.GroupDefinitionInfo;
62 import org.openecomp.sdc.be.model.ComponentInstance;
63 import org.openecomp.sdc.be.model.ComponentInstanceInput;
64 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
65 import org.openecomp.sdc.be.model.PropertyConstraint;
66 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
67 import org.openecomp.sdc.be.model.Service;
68 import org.openecomp.sdc.be.model.User;
69 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
70 import org.openecomp.sdc.be.user.UserBusinessLogic;
71 import org.openecomp.sdc.common.api.Constants;
72 import org.openecomp.sdc.common.datastructure.Wrapper;
73 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
74 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
75 import org.openecomp.sdc.common.log.enums.StatusCode;
76 import org.openecomp.sdc.common.log.wrappers.Logger;
77 import org.openecomp.sdc.exception.ResponseFormat;
78 import org.springframework.stereotype.Controller;
80 import javax.inject.Inject;
81 import javax.servlet.http.HttpServletRequest;
82 import javax.ws.rs.Consumes;
83 import javax.ws.rs.DELETE;
84 import javax.ws.rs.GET;
85 import javax.ws.rs.HeaderParam;
86 import javax.ws.rs.POST;
87 import javax.ws.rs.PUT;
88 import javax.ws.rs.Path;
89 import javax.ws.rs.PathParam;
90 import javax.ws.rs.Produces;
91 import javax.ws.rs.QueryParam;
92 import javax.ws.rs.core.Context;
93 import javax.ws.rs.core.MediaType;
94 import javax.ws.rs.core.Response;
95 import java.io.IOException;
96 import java.io.InputStream;
97 import java.lang.reflect.Type;
98 import java.util.ArrayList;
99 import java.util.Arrays;
100 import java.util.List;
101 import java.util.Map;
102 import java.util.Set;
105 * Root resource (exposed at "/" path) .json
107 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
109 @OpenAPIDefinition(info = @Info(title = "Resource Instance Servlet"))
111 public class ComponentInstanceServlet extends AbstractValidationsServlet {
113 private static final String FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID = "Failed to get properties of component instance ID: {} in {} with ID: {}";
114 private static final String GET_GROUP_ARTIFACT_BY_ID = "getGroupArtifactById";
115 private static final String GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION = "getGroupArtifactById unexpected exception";
116 private static final String GET_START_HANDLE_REQUEST_OF = "(GET) Start handle request of {}";
117 private static final String START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS = "Start handle request of updateResourceInstanceProperty. Received property is {}";
118 private static final String UPDATE_RESOURCE_INSTANCE = "Update Resource Instance";
119 private static final String RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE = "Resource Instance - updateResourceInstance";
120 private static final String UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION = "update resource instance with exception";
121 private static final String FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT = "Failed to convert received data to BE format.";
122 private static final String EMPTY_BODY_WAS_SENT = "Empty body was sent.";
123 private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
124 private static final String UNSUPPORTED_COMPONENT_TYPE = "Unsupported component type {}";
125 private static final String CREATE_AND_ASSOCIATE_RI_FAILED_WITH_EXCEPTION = "create and associate RI failed with exception: {}";
126 private static final Logger log = Logger.getLogger(ComponentInstanceServlet.class);
127 private static final Type PROPERTY_CONSTRAINT_TYPE = new TypeToken<PropertyConstraint>() {}.getType();
128 private static final Gson gsonDeserializer = new GsonBuilder().registerTypeAdapter(PROPERTY_CONSTRAINT_TYPE, new PropertyConstraintDeserialiser()).create();
129 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ComponentInstanceServlet.class.getName());
131 private final GroupBusinessLogic groupBL;
132 private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
133 private final ServiceBusinessLogic serviceBusinessLogic;
137 public ComponentInstanceServlet(UserBusinessLogic userBusinessLogic,
138 GroupBusinessLogic groupBL, ComponentInstanceBusinessLogic componentInstanceBL,
139 ComponentsUtils componentsUtils, ServletUtils servletUtils,
140 ResourceImportManager resourceImportManager,
141 ServiceBusinessLogic serviceBusinessLogic) {
142 super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
143 this.groupBL = groupBL;
144 this.componentInstanceBusinessLogic = componentInstanceBL;
145 this.serviceBusinessLogic = serviceBusinessLogic;
149 @Path("/{containerComponentType}/{componentId}/resourceInstance")
150 @Consumes(MediaType.APPLICATION_JSON)
151 @Produces(MediaType.APPLICATION_JSON)
152 @Operation(description = "Create ComponentInstance", method = "POST", summary = "Returns created ComponentInstance",
153 responses = @ApiResponse(
154 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
155 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Component created"),
156 @ApiResponse(responseCode = "403", description = "Restricted operation"),
157 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
158 @ApiResponse(responseCode = "409", description = "Component instance already exist")})
159 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
160 public Response createComponentInstance(@Parameter(description = "RI object to be created", required = true) String data,
161 @PathParam("componentId") final String containerComponentId,
162 @Parameter(description = "valid values: resources / services",
163 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
164 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
165 @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
166 required = true) String userId,
167 @Context final HttpServletRequest request) {
169 validateNotEmptyBody(data);
170 ComponentInstance componentInstance = null;
172 componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
173 componentInstance.setInvariantName(null);
174 componentInstance.setCreatedFrom(CreatedFrom.UI);
175 } catch (Exception e) {
176 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Component Instance");
177 log.debug("create component instance failed with exception", e);
178 throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
180 loggerSupportability.log(LoggerSupportabilityActions.CREATE_INSTANCE, StatusCode.STARTED,"Starting to create component instance by {}",userId);
181 if (componentInstanceBusinessLogic == null) {
182 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
183 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
185 ComponentInstance actionResponse = componentInstanceBusinessLogic.createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance);
186 loggerSupportability.log(LoggerSupportabilityActions.CREATE_INSTANCE,actionResponse.getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"Ending to create component instance by user {}",userId);
187 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse);
192 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}")
193 @Consumes(MediaType.APPLICATION_JSON)
194 @Produces(MediaType.APPLICATION_JSON)
195 @Operation(description = "Update resource instance", method = "POST", summary = "Returns updated resource instance",
196 responses = @ApiResponse(
197 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
198 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource instance updated"),
199 @ApiResponse(responseCode = "403", description = "Restricted operation"),
200 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
201 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
202 public Response updateComponentInstanceMetadata(@PathParam("componentId") final String componentId,
203 @PathParam("componentInstanceId") final String componentInstanceId,
204 @Parameter(description = "valid values: resources / services / products",
205 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
206 ComponentTypeEnum.SERVICE_PARAM_NAME,
207 ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
208 @Context final HttpServletRequest request) throws IOException {
210 String url = request.getMethod() + " " + request.getRequestURI();
211 log.debug(START_HANDLE_REQUEST_OF, url);
212 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE,StatusCode.STARTED,"update Component Instance Metadata");
215 log.debug(START_HANDLE_REQUEST_OF, url);
217 InputStream inputStream = request.getInputStream();
219 byte[] bytes = IOUtils.toByteArray(inputStream);
221 if (bytes == null || bytes.length == 0) {
222 log.info(EMPTY_BODY_WAS_SENT);
223 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
226 String userId = request.getHeader(Constants.USER_ID_HEADER);
228 String data = new String(bytes);
229 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
230 if (componentInstanceBusinessLogic == null) {
231 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
232 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
234 Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
236 if (convertResponse.isRight()) {
237 BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
238 log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
239 return buildErrorResponse(convertResponse.right().value());
242 ComponentInstance resourceInstance = convertResponse.left().value();
243 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.updateComponentInstanceMetadata(containerComponentType, componentId, componentInstanceId, userId, resourceInstance);
244 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE,actionResponse.left().value().getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"update Component Instance Metadata by {}",userId);
245 if (actionResponse.isRight()) {
246 return buildErrorResponse(actionResponse.right().value());
248 ComponentInstance resultValue = actionResponse.left().value();
249 if (componentTypeEnum.equals(ComponentTypeEnum.SERVICE)){
250 boolean shouldCreateServiceFilter = resourceInstance.getDirectives() != null && resourceInstance.getDirectives().contains(
251 DirectivesUtils.SELECTABLE);
253 if(shouldCreateServiceFilter) {
254 Either<CINodeFilterDataDefinition, ResponseFormat> either =
255 serviceBusinessLogic.createIfNotAlreadyExistServiceFilter(componentId, componentInstanceId, userId,
257 if (either.isRight()){
258 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance Failed to create service filter.");
259 log.debug("Failed to create service filter.");
260 return buildErrorResponse(convertResponse.right().value());
262 resultValue.setNodeFilter(either.left().value());
264 Either<String, ResponseFormat> either = serviceBusinessLogic.deleteIfNotAlreadyDeletedServiceFilter(componentId, componentInstanceId, userId,true);
265 if (either.isRight()){
266 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance Failed to delete service filter.");
267 log.debug("Failed to delete service filter.");
268 return buildErrorResponse(convertResponse.right().value());
270 resultValue.setNodeFilter(null);
274 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
276 } catch (Exception e) {
277 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
278 log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
285 @Path("/{containerComponentType}/{componentId}/resourceInstance/multipleComponentInstance")
286 @Consumes(MediaType.APPLICATION_JSON)
287 @Produces(MediaType.APPLICATION_JSON)
288 @Operation(description = "Update resource instance multiple component", method = "POST",
289 summary = "Returns updated resource instance", responses = @ApiResponse(
290 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
291 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource instance updated"),
292 @ApiResponse(responseCode = "403", description = "Restricted operation"),
293 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
294 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
295 public Response updateMultipleComponentInstance(@PathParam("componentId") final String componentId, @Parameter(
296 description = "valid values: resources / services / products",
297 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
298 ComponentTypeEnum.SERVICE_PARAM_NAME,
299 ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
300 @Context final HttpServletRequest request, @Parameter(description = "Component Instance JSON Array",
301 required = true) final String componentInstanceJsonArray) {
303 String url = request.getMethod() + " " + request.getRequestURI();
304 log.debug(START_HANDLE_REQUEST_OF, url);
307 log.debug(START_HANDLE_REQUEST_OF, url);
309 if (componentInstanceJsonArray == null || componentInstanceJsonArray.length() == 0) {
310 log.info("Empty JSON list was sent.");
311 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
314 String userId = request.getHeader(Constants.USER_ID_HEADER);
316 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
317 if (componentInstanceBusinessLogic == null) {
318 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
319 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
322 Either<List<ComponentInstance>, ResponseFormat> convertResponse = convertToMultipleResourceInstance(componentInstanceJsonArray);
324 if (convertResponse.isRight()) {
325 // Using both ECOMP error methods, show to Sofer
326 BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
327 log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
328 return buildErrorResponse(convertResponse.right().value());
331 List<ComponentInstance> componentInstanceList = convertResponse.left().value();
333 List<ComponentInstance> actionResponse = componentInstanceBusinessLogic.updateComponentInstance(containerComponentType, null, componentId, userId, componentInstanceList, true);
334 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse);
336 } catch (Exception e) {
337 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
338 log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
345 @Path("/{containerComponentType}/{componentId}/resourceInstance/{resourceInstanceId}")
346 @Consumes(MediaType.APPLICATION_JSON)
347 @Produces(MediaType.APPLICATION_JSON)
348 @Operation(description = "Delete ResourceInstance", method = "DELETE", summary = "Returns delete resourceInstance",
349 responses = @ApiResponse(
350 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
351 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "ResourceInstance deleted"),
352 @ApiResponse(responseCode = "403", description = "Restricted operation"),
353 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
354 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
355 public Response deleteResourceInstance(@PathParam("componentId") final String componentId,
356 @PathParam("resourceInstanceId") final String resourceInstanceId,
357 @Parameter(description = "valid values: resources / services / products",
358 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
359 ComponentTypeEnum.SERVICE_PARAM_NAME,
360 ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
361 @Context final HttpServletRequest request) {
363 String url = request.getMethod() + " " + request.getRequestURI();
366 log.debug(START_HANDLE_REQUEST_OF, url);
367 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
368 if (componentInstanceBusinessLogic == null) {
369 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
370 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
372 String userId = request.getHeader(Constants.USER_ID_HEADER);
373 ComponentInstance actionResponse = componentInstanceBusinessLogic.deleteComponentInstance(containerComponentType, componentId, resourceInstanceId, userId);
374 loggerSupportability.log(LoggerSupportabilityActions.DELETE_COMPONENT_INSTANCE,actionResponse.getComponentMetadataForSupportLog(),StatusCode.STARTED,"DELETE_COMPONENT_INSTANCE by user {}", userId);
375 loggerSupportability.log(LoggerSupportabilityActions.DELETE_COMPONENT_INSTANCE,actionResponse.getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"DELETE_COMPONENT_INSTANCE by user {}", userId);
376 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse);
377 } catch (Exception e) {
378 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource Instance");
379 log.debug("delete resource instance with exception", e);
384 @Parameter(description = "allowed values are resources /services / products",
385 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
386 ComponentTypeEnum.SERVICE_PARAM_NAME,
387 ComponentTypeEnum.PRODUCT_PARAM_NAME}),
390 @Path("/{containerComponentType}/{componentId}/resourceInstance/associate")
391 @Consumes(MediaType.APPLICATION_JSON)
392 @Produces(MediaType.APPLICATION_JSON)
393 @Operation(description = "Associate RI to RI", method = "POST", summary = "Returns created RelationshipInfo",
394 responses = @ApiResponse(
395 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
396 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship created"),
397 @ApiResponse(responseCode = "403", description = "Missing information"),
398 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
399 @ApiResponse(responseCode = "409", description = "Relationship already exist")})
400 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
401 public Response associateRIToRI(@Parameter(
402 description = "unique id of the container component") @PathParam("componentId") final String componentId,
403 @Parameter(description = "allowed values are resources /services / products",
404 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
405 ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME}),
406 required = true) @PathParam("containerComponentType") final String containerComponentType,
407 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
408 @Parameter(description = "RelationshipInfo", required = true) String data,
409 @Context final HttpServletRequest request) {
411 String url = request.getMethod() + " " + request.getRequestURI();
412 log.debug(START_HANDLE_REQUEST_OF, url);
413 Response response = null;
414 loggerSupportability.log(LoggerSupportabilityActions.ASSOCIATE_RI_TO_RI, StatusCode.STARTED,"Starting to associate RI To RI for component {} ",componentId + " by " + userId );
417 log.debug(START_HANDLE_REQUEST_OF, url);
419 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
420 if (componentInstanceBusinessLogic == null) {
421 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
422 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
425 RequirementCapabilityRelDef requirementDef = convertToRequirementCapabilityRelDef(data);
426 requirementDef.setOriginUI(true);
428 RequirementCapabilityRelDef actionResponse = componentInstanceBusinessLogic.associateRIToRI(componentId, userId, requirementDef, componentTypeEnum);
429 loggerSupportability.log(LoggerSupportabilityActions.ASSOCIATE_RI_TO_RI, StatusCode.COMPLETE,"Ended associate RI To RI for component {} ",componentId + " by " + userId );
430 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse);
432 } catch (Exception e) {
433 if(!e.getClass().equals(ComponentException.class)) {
434 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Associate Resource Instance");
435 log.debug("associate resource instance to another RI with exception", e);
436 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
443 @Path("/{containerComponentType}/{componentId}/resourceInstance/dissociate")
444 @Consumes(MediaType.APPLICATION_JSON)
445 @Produces(MediaType.APPLICATION_JSON)
446 @Operation(description = "Dissociate RI from RI", method = "PUT", summary = "Returns deleted RelationshipInfo",
447 responses = @ApiResponse(
448 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
449 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship deleted"),
450 @ApiResponse(responseCode = "403", description = "Missing information"),
451 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
452 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
453 public Response dissociateRIFromRI(
454 @Parameter(description = "allowed values are resources /services / products",
455 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
456 ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME}),
457 required = true) @PathParam("containerComponentType") final String containerComponentType,
459 description = "unique id of the container component") @PathParam("componentId") final String componentId,
460 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
461 @Parameter(description = "RelationshipInfo", required = true) String data,
462 @Context final HttpServletRequest request) {
464 String url = request.getMethod() + " " + request.getRequestURI();
465 log.debug(START_HANDLE_REQUEST_OF, url);
466 loggerSupportability.log(LoggerSupportabilityActions.UN_ASSOCIATE_RI_TO_RI, StatusCode.STARTED,"Starting to undo associate RI To RI for component {} ",componentId + " by " + userId );
469 log.debug(START_HANDLE_REQUEST_OF, url);
471 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
472 if (componentInstanceBusinessLogic == null) {
473 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
474 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
477 RequirementCapabilityRelDef requirementDef = convertToRequirementCapabilityRelDef(data);
478 RequirementCapabilityRelDef actionResponse = componentInstanceBusinessLogic.dissociateRIFromRI(componentId, userId, requirementDef, componentTypeEnum);
479 loggerSupportability.log(LoggerSupportabilityActions.UN_ASSOCIATE_RI_TO_RI, StatusCode.COMPLETE,"Ended undo associate RI To RI for component {} ",componentId + " by " + userId );
480 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse);
482 } catch (Exception e) {
483 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Dissociate Resource Instance");
484 log.debug("dissociate resource instance from service failed with exception", e);
490 @Path("/{containerComponentType}/{componentId}/resourceInstance/createAndAssociate")
491 @Consumes(MediaType.APPLICATION_JSON)
492 @Produces(MediaType.APPLICATION_JSON)
493 @Operation(description = "Create RI and associate RI to RI", method = "POST",
494 summary = "Returns created RI and RelationshipInfo", responses = @ApiResponse(
495 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
496 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "RI created"),
497 @ApiResponse(responseCode = "403", description = "Restricted operation"),
498 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
499 @ApiResponse(responseCode = "409", description = "Relationship already exist")})
500 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
501 public Response createAndAssociateRIToRI(@PathParam("componentId") final String componentId, @Parameter(
502 description = "valid values: resources / services",
503 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
504 ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
505 @Context final HttpServletRequest request) throws IOException {
507 String url = request.getMethod() + " " + request.getRequestURI();
508 log.debug(START_HANDLE_REQUEST_OF, url);
511 log.debug(START_HANDLE_REQUEST_OF, url);
513 InputStream inputStream = request.getInputStream();
515 byte[] bytes = IOUtils.toByteArray(inputStream);
517 if (bytes == null || bytes.length == 0) {
518 log.info(EMPTY_BODY_WAS_SENT);
519 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
522 String userId = request.getHeader(Constants.USER_ID_HEADER);
524 String data = new String(bytes);
526 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
527 if (componentInstanceBusinessLogic == null) {
528 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
529 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
532 Either<CreateAndAssotiateInfo, ActionStatus> convertStatus = convertJsonToObject(data, CreateAndAssotiateInfo.class);
533 if (convertStatus.isRight()) {
534 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - createAndAssociateRIToRI");
535 log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
536 Either<Object, ResponseFormat> formattedResponse = Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
537 return buildErrorResponse(formattedResponse.right().value());
540 CreateAndAssotiateInfo createAndAssotiateInfo = convertStatus.left().value();
541 RequirementCapabilityRelDef requirementDef = createAndAssotiateInfo.getAssociate();
542 requirementDef.setOriginUI(true);
543 Either<CreateAndAssotiateInfo, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createAndAssociateRIToRI(containerComponentType, componentId, userId, createAndAssotiateInfo);
545 if (actionResponse.isRight()) {
546 return buildErrorResponse(actionResponse.right().value());
548 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
549 } catch (Exception e) {
550 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create and Associate Resource Instance");
551 log.debug("create and associate RI failed with exception", e);
557 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/properties")
558 @Consumes(MediaType.APPLICATION_JSON)
559 @Produces(MediaType.APPLICATION_JSON)
560 @Operation(description = "Update resource instance property", method = "POST",
561 summary = "Returns updated resource instance property", responses = @ApiResponse(
562 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
563 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
564 @ApiResponse(responseCode = "403", description = "Restricted operation"),
565 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
566 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
567 public Response updateResourceInstanceProperties(
568 @Parameter(description = "service id") @PathParam("componentId") final String componentId,
569 @Parameter(description = "valid values: resources / services",
570 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
571 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
573 description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
574 @Parameter(description = "id of user initiating the operation") @HeaderParam(
575 value = Constants.USER_ID_HEADER) String userId,
576 @Context final HttpServletRequest request,
577 @Parameter(description = "Component Instance Properties JSON Array",
578 required = true) final String componentInstancePropertiesJsonArray) {
580 String url = request.getMethod() + " " + request.getRequestURI();
581 log.debug(START_HANDLE_REQUEST_OF, url);
582 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE, StatusCode.STARTED,"Starting to update Resource Instance Properties for component {} ",componentId + " by " + userId );
584 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
585 List<ComponentInstanceProperty> propertiesToUpdate = new ArrayList<>();
586 if (errorWrapper.isEmpty()) {
587 Either<List<ComponentInstanceProperty>, ResponseFormat> propertiesToUpdateEither = convertMultipleProperties(componentInstancePropertiesJsonArray);
588 if (propertiesToUpdateEither.isRight()) {
589 errorWrapper.setInnerElement(propertiesToUpdateEither.right().value());
591 propertiesToUpdate = propertiesToUpdateEither.left().value();
594 if (!errorWrapper.isEmpty()) {
595 return buildErrorResponse(errorWrapper.getInnerElement());
597 log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, propertiesToUpdate);
599 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
600 if (componentInstanceBusinessLogic == null) {
601 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
602 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
604 Either<List<ComponentInstanceProperty>, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createOrUpdatePropertiesValues(componentTypeEnum, componentId, componentInstanceId, propertiesToUpdate, userId);
605 if (actionResponse.isRight()) {
606 return buildErrorResponse(actionResponse.right().value());
608 List<ComponentInstanceProperty> resourceInstanceProperties = actionResponse.left().value();
609 ObjectMapper mapper = new ObjectMapper();
611 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE, StatusCode.COMPLETE,"Ended update Resource Instance Properties for component {} ",componentId + " by " + userId );
613 result = mapper.writeValueAsString(resourceInstanceProperties);
614 } catch (JsonProcessingException e) {
615 log.error(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e.getMessage(), e);
616 throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
618 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE, StatusCode.COMPLETE,"Ended update Resource Instance Properties for component {} ",componentId + " by user " + userId );
619 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
623 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/inputs")
624 @Consumes(MediaType.APPLICATION_JSON)
625 @Produces(MediaType.APPLICATION_JSON)
626 @Operation(description = "Update resource instance property", method = "POST",
627 summary = "Returns updated resource instance property", responses = @ApiResponse(
628 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
629 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
630 @ApiResponse(responseCode = "403", description = "Restricted operation"),
631 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
632 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
633 public Response updateResourceInstanceInput(
634 @Parameter(description = "service id") @PathParam("componentId") final String componentId,
635 @Parameter(description = "valid values: resources / services",
636 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
637 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
639 description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
640 @Parameter(description = "id of user initiating the operation") @HeaderParam(
641 value = Constants.USER_ID_HEADER) String userId,
642 @Context final HttpServletRequest request,
643 @Parameter(description = "Component Instance Properties JSON Array",
644 required = true) final String componentInstanceInputsJsonArray) {
646 String url = request.getMethod() + " " + request.getRequestURI();
647 log.debug(START_HANDLE_REQUEST_OF, url);
649 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
650 List<ComponentInstanceInput> inputsToUpdate = new ArrayList<>();
651 if (errorWrapper.isEmpty()) {
652 Either<List<ComponentInstanceInput>, ResponseFormat> inputsToUpdateEither = convertMultipleInputs(componentInstanceInputsJsonArray);
653 if (inputsToUpdateEither.isRight()) {
654 errorWrapper.setInnerElement(inputsToUpdateEither.right().value());
656 inputsToUpdate = inputsToUpdateEither.left().value();
659 if (!errorWrapper.isEmpty()) {
660 return buildErrorResponse(errorWrapper.getInnerElement());
662 log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, inputsToUpdate);
664 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
665 if (componentInstanceBusinessLogic == null) {
666 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
667 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
669 Either<List<ComponentInstanceInput>, ResponseFormat> actionResponse =
670 componentInstanceBusinessLogic.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, componentInstanceId, inputsToUpdate, userId);
671 if (actionResponse.isRight()) {
672 return buildErrorResponse(actionResponse.right().value());
674 List<ComponentInstanceInput> resourceInstanceInput = actionResponse.left().value();
675 ObjectMapper mapper = new ObjectMapper();
676 mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
678 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.COMPLETE,"Ending update Resource Instance Input for component {} ",componentId + " by " + userId );
680 result = mapper.writeValueAsString(resourceInstanceInput);
681 } catch (JsonProcessingException e) {
682 log.error(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e.getMessage(), e);
683 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
685 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.COMPLETE, "Ending update Resource Instance Input for component {} ", componentId + " by user " + userId);
686 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
690 * Updates ResourceInstance Attribute
693 * @param containerComponentType
694 * @param componentInstanceId
700 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/attribute")
701 @Consumes(MediaType.APPLICATION_JSON)
702 @Produces(MediaType.APPLICATION_JSON)
703 @Operation(description = "Update resource instance attribute", method = "POST",
704 summary = "Returns updated resource instance attribute", responses = @ApiResponse(
705 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
706 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
707 @ApiResponse(responseCode = "403", description = "Restricted operation"),
708 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
709 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
710 public Response updateResourceInstanceAttribute(
711 @Parameter(description = "service id") @PathParam("componentId") final String componentId,
712 @Parameter(description = "valid values: resources / services",
713 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
714 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
716 description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
717 @Parameter(description = "id of user initiating the operation") @HeaderParam(
718 value = Constants.USER_ID_HEADER) String userId,
719 @Context final HttpServletRequest request) throws IOException {
721 String url = request.getMethod() + " " + request.getRequestURI();
722 log.debug(START_HANDLE_REQUEST_OF, url);
723 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_RESOURCE, StatusCode.STARTED,"Starting to update Resource Instance Attribute for component {} ",componentId + " by " + userId );
726 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
727 Wrapper<String> dataWrapper = new Wrapper<>();
728 Wrapper<ComponentInstanceProperty> attributeWrapper = new Wrapper<>();
729 Wrapper<ComponentInstanceBusinessLogic> blWrapper = new Wrapper<>();
731 validateInputStream(request, dataWrapper, errorWrapper);
733 if (errorWrapper.isEmpty()) {
734 validateClassParse(dataWrapper.getInnerElement(), attributeWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
737 if (errorWrapper.isEmpty()) {
738 validateComponentInstanceBusinessLogic(request, containerComponentType, blWrapper, errorWrapper);
741 if (errorWrapper.isEmpty()) {
742 ComponentInstanceBusinessLogic componentInstanceLogic = blWrapper.getInnerElement();
743 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
744 log.debug("Start handle request of ComponentInstanceAttribute. Received attribute is {}", attributeWrapper.getInnerElement());
745 Either<ComponentInstanceProperty, ResponseFormat> eitherAttribute = componentInstanceLogic.createOrUpdateAttributeValue(componentTypeEnum, componentId, componentInstanceId, attributeWrapper.getInnerElement(), userId);
746 if (eitherAttribute.isRight()) {
747 errorWrapper.setInnerElement(eitherAttribute.right().value());
749 attributeWrapper.setInnerElement(eitherAttribute.left().value());
752 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_RESOURCE, StatusCode.COMPLETE,"Ended update Resource Instance Attribute for component {} ",componentId + " by " + userId );
753 return buildResponseFromElement(errorWrapper, attributeWrapper);
755 } catch (Exception e) {
756 log.error(CREATE_AND_ASSOCIATE_RI_FAILED_WITH_EXCEPTION, e.getMessage(), e);
763 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/property/{propertyId}")
764 @Consumes(MediaType.APPLICATION_JSON)
765 @Produces(MediaType.APPLICATION_JSON)
766 @Operation(description = "Update resource instance", method = "DELETE",
767 summary = "Returns deleted resource instance property", responses = @ApiResponse(
768 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
769 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
770 @ApiResponse(responseCode = "403", description = "Restricted operation"),
771 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
772 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
773 public Response deleteResourceInstanceProperty(
774 @Parameter(description = "service id") @PathParam("componentId") final String componentId,
775 @Parameter(description = "valid values: resources / services",
776 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
777 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
779 description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
780 @Parameter(description = "property id") @PathParam("propertyId") final String propertyId,
781 @Parameter(description = "id of user initiating the operation") @HeaderParam(
782 value = Constants.USER_ID_HEADER) String userId,
783 @Context final HttpServletRequest request) {
786 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.STARTED,"Starting to delete Resource Instance Property for component {} ",componentId + " by " + userId );
787 String url = request.getMethod() + " " + request.getRequestURI();
788 log.debug(START_HANDLE_REQUEST_OF, url);
791 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
792 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.COMPLETE,"Ended delete Resource Instance Property for component {} ",componentId + " by " + userId );
793 if (componentInstanceBusinessLogic == null) {
794 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
795 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
798 Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceBusinessLogic.deletePropertyValue(componentTypeEnum, componentId, componentInstanceId, propertyId, userId);
799 if (actionResponse.isRight()) {
800 return buildErrorResponse(actionResponse.right().value());
802 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
803 } catch (Exception e) {
804 log.error(CREATE_AND_ASSOCIATE_RI_FAILED_WITH_EXCEPTION, e.getMessage(), e);
811 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/changeVersion")
812 @Consumes(MediaType.APPLICATION_JSON)
813 @Produces(MediaType.APPLICATION_JSON)
814 @Operation(description = "Update resource instance", method = "POST", summary = "Returns updated resource instance",
815 responses = @ApiResponse(
816 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
817 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
818 @ApiResponse(responseCode = "403", description = "Restricted operation"),
819 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
820 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
821 public Response changeResourceInstanceVersion(@PathParam("componentId") final String componentId,
822 @PathParam("componentInstanceId") final String componentInstanceId,
823 @Parameter(description = "valid values: resources / services",
824 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
825 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
826 @Context final HttpServletRequest request) throws IOException {
828 String url = request.getMethod() + " " + request.getRequestURI();
829 log.debug(START_HANDLE_REQUEST_OF, url);
831 InputStream inputStream = request.getInputStream()) {
833 byte[] bytes = IOUtils.toByteArray(inputStream);
835 if (bytes == null || bytes.length == 0) {
836 log.info(EMPTY_BODY_WAS_SENT);
837 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
840 String userId = request.getHeader(Constants.USER_ID_HEADER);
842 String data = new String(bytes);
844 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
845 if (componentInstanceBusinessLogic == null) {
846 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
847 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
850 Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
852 if (convertResponse.isRight()) {
853 BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
854 log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
855 return buildErrorResponse(convertResponse.right().value());
858 ComponentInstance newResourceInstance = convertResponse.left().value();
859 ComponentInstance actionResponse = componentInstanceBusinessLogic.changeComponentInstanceVersion(containerComponentType, componentId, componentInstanceId, userId, newResourceInstance);
861 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse);
863 } catch (Exception e) {
864 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
865 log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
872 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}/property")
873 @Consumes(MediaType.APPLICATION_JSON)
874 @Produces(MediaType.APPLICATION_JSON)
875 @Operation(description = "Update resource instance property", method = "POST",
876 summary = "Returns updated resource instance property", responses = @ApiResponse(
877 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
878 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
879 @ApiResponse(responseCode = "403", description = "Restricted operation"),
880 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
881 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
882 public Response updateGroupInstanceProperty(
883 @Parameter(description = "service id") @PathParam("componentId") final String componentId,
884 @Parameter(description = "valid values: resources / services",
885 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
886 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
888 description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
889 @Parameter(description = "group instance id") @PathParam("groupInstanceId") final String groupInstanceId,
890 @Parameter(description = "id of user initiating the operation") @HeaderParam(
891 value = Constants.USER_ID_HEADER) String userId,
892 @Context final HttpServletRequest request) throws IOException {
894 String url = request.getMethod() + " " + request.getRequestURI();
895 log.debug(START_HANDLE_REQUEST_OF, url);
898 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.STARTED,"Starting update Group Instance Property for component {} ",componentId + " by " + userId );
899 Wrapper<String> dataWrapper = new Wrapper<>();
900 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
901 Wrapper<ComponentInstanceProperty> propertyWrapper = new Wrapper<>();
903 validateInputStream(request, dataWrapper, errorWrapper);
905 if (errorWrapper.isEmpty()) {
906 validateClassParse(dataWrapper.getInnerElement(), propertyWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
909 if (!errorWrapper.isEmpty()) {
910 return buildErrorResponse(errorWrapper.getInnerElement());
913 ComponentInstanceProperty property = propertyWrapper.getInnerElement();
915 log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, property);
919 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
920 if (componentInstanceBusinessLogic == null) {
921 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
922 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
925 Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, componentInstanceId, groupInstanceId, property, userId);
926 if (actionResponse.isRight()) {
927 return buildErrorResponse(actionResponse.right().value());
930 ComponentInstanceProperty resourceInstanceProperty = actionResponse.left().value();
931 ObjectMapper mapper = new ObjectMapper();
932 String result = mapper.writeValueAsString(resourceInstanceProperty);
933 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.COMPLETE,"Ended update Group Instance Property for component {} ",componentId + " by " + userId );
934 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
936 } catch (Exception e) {
937 log.error(CREATE_AND_ASSOCIATE_RI_FAILED_WITH_EXCEPTION, e.getMessage(), e);
943 @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstId}")
944 @Consumes(MediaType.APPLICATION_JSON)
945 @Produces(MediaType.APPLICATION_JSON)
946 @Operation(description = "Get group artifacts ", method = "GET",
947 summary = "Returns artifacts metadata according to groupInstId", responses = @ApiResponse(
948 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
949 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "group found"),
950 @ApiResponse(responseCode = "403", description = "Restricted operation"),
951 @ApiResponse(responseCode = "404", description = "Group not found")})
952 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
953 public Response getGroupArtifactById(@PathParam("containerComponentType") final String containerComponentType,
954 @PathParam("componentId") final String componentId,
955 @PathParam("componentInstanceId") final String componentInstanceId,
956 @PathParam("groupInstId") final String groupInstId, @Context final HttpServletRequest request,
957 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
958 String url = request.getMethod() + " " + request.getRequestURI();
959 log.debug(GET_START_HANDLE_REQUEST_OF, url);
963 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
964 Either<GroupDefinitionInfo, ResponseFormat> actionResponse = groupBL.getGroupInstWithArtifactsById(componentTypeEnum, componentId, componentInstanceId, groupInstId, userId, false);
966 if (actionResponse.isRight()) {
967 log.debug("failed to get all non abstract {}", containerComponentType);
968 return buildErrorResponse(actionResponse.right().value());
971 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
973 } catch (Exception e) {
974 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
975 log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
983 @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/properties")
984 @Consumes(MediaType.APPLICATION_JSON)
985 @Produces(MediaType.APPLICATION_JSON)
986 @Operation(description = "Get component instance properties", method = "GET",
987 summary = "Returns component instance properties", responses = @ApiResponse(
988 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
989 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Properties found"),
990 @ApiResponse(responseCode = "403", description = "Restricted operation"),
991 @ApiResponse(responseCode = "404", description = "Component/Component Instance - not found")})
992 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
993 public Response getInstancePropertiesById(@PathParam("containerComponentType") final String containerComponentType,
994 @PathParam("containerComponentId") final String containerComponentId,
995 @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId,
996 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
999 String url = request.getMethod() + " " + request.getRequestURI();
1000 log.debug(GET_START_HANDLE_REQUEST_OF, url);
1002 List<ComponentInstanceProperty> componentInstancePropertiesById = componentInstanceBusinessLogic.getComponentInstancePropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId, userId);
1003 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), componentInstancePropertiesById);
1008 @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/capability/{capabilityType}/capabilityName/{capabilityName}/ownerId/{ownerId}/properties")
1009 @Consumes(MediaType.APPLICATION_JSON)
1010 @Produces(MediaType.APPLICATION_JSON)
1011 @Operation(description = "Get component instance capability properties", method = "GET",
1012 summary = "Returns component instance capability properties", responses = @ApiResponse(
1013 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
1014 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Properties found"),
1015 @ApiResponse(responseCode = "403", description = "Restricted operation"),
1016 @ApiResponse(responseCode = "404", description = "Component/Component Instance/Capability - not found")})
1017 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
1018 public Response getInstanceCapabilityPropertiesById(
1019 @PathParam("containerComponentType") final String containerComponentType,
1020 @PathParam("containerComponentId") final String containerComponentId,
1021 @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId,
1022 @PathParam("capabilityType") final String capabilityType,
1023 @PathParam("capabilityName") final String capabilityName, @PathParam("ownerId") final String ownerId,
1024 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
1027 String url = request.getMethod() + " " + request.getRequestURI();
1028 log.debug(GET_START_HANDLE_REQUEST_OF, url);
1031 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1033 List<ComponentInstanceProperty> componentInstancePropertiesById = componentInstanceBusinessLogic.getComponentInstanceCapabilityPropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId,
1034 capabilityType, capabilityName, ownerId, userId);
1036 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), componentInstancePropertiesById);
1037 } catch (Exception e) {
1038 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
1039 log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
1047 @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/capability/{capabilityType}/capabilityName/{capabilityName}/ownerId/{ownerId}/properties")
1048 @Consumes(MediaType.APPLICATION_JSON)
1049 @Produces(MediaType.APPLICATION_JSON)
1050 @Operation(description = "Update Instance Capabilty Property", method = "PUT",
1051 summary = "Returns updated property", responses = @ApiResponse(
1052 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
1054 value = {@ApiResponse(responseCode = "200", description = "Resource instance capabilty property updated"),
1055 @ApiResponse(responseCode = "403", description = "Restricted operation"),
1056 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
1057 @ApiResponse(responseCode = "404", description = "Component/Component Instance/Capability - not found")})
1058 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
1059 public Response updateInstanceCapabilityProperty(
1060 @PathParam("containerComponentType") final String containerComponentType,
1061 @PathParam("containerComponentId") final String containerComponentId,
1062 @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId,
1063 @PathParam("capabilityType") final String capabilityType,
1064 @PathParam("capabilityName") final String capabilityName, @PathParam("ownerId") final String ownerId,
1065 @Parameter(description = "Instance capabilty property to update", required = true) String data,
1066 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
1067 String url = request.getMethod() + " " + request.getRequestURI();
1068 log.debug("(PUT) Start handle request of {}", url);
1069 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_INSTANCE_CAPABILITY_PROPERTY, StatusCode.STARTED," Starting to update Instance Capability Property for component instance {} " , componentInstanceUniqueId + " by " + userId);
1071 Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
1072 List<ComponentInstanceProperty> propertiesToUpdate = new ArrayList<>();
1073 if (errorWrapper.isEmpty()) {
1074 Either<List<ComponentInstanceProperty>, ResponseFormat> propertiesToUpdateEither = convertMultipleProperties(data);
1075 if (propertiesToUpdateEither.isRight()) {
1076 errorWrapper.setInnerElement(propertiesToUpdateEither.right().value());
1078 propertiesToUpdate = propertiesToUpdateEither.left().value();
1082 if (!errorWrapper.isEmpty()) {
1083 return buildErrorResponse(errorWrapper.getInnerElement());
1086 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1088 Either<List<ComponentInstanceProperty>, ResponseFormat> updateCICapProperty = componentInstanceBusinessLogic.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, propertiesToUpdate, userId);
1090 if (updateCICapProperty.isRight()) {
1091 log.debug(FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID, componentInstanceUniqueId, containerComponentType, containerComponentId);
1092 return buildErrorResponse(updateCICapProperty.right().value());
1094 loggerSupportability.log(LoggerSupportabilityActions.UPDATE_INSTANCE_CAPABILITY_PROPERTY, StatusCode.COMPLETE," Ended to update Instance Capability Property for component instance {} " , componentInstanceUniqueId + " by " + userId);
1095 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updateCICapProperty.left().value());
1096 } catch (Exception e) {
1097 BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
1098 log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
1104 @Path("/{containerComponentType}/{containerComponentId}/serviceProxy")
1105 @Consumes(MediaType.APPLICATION_JSON)
1106 @Produces(MediaType.APPLICATION_JSON)
1107 @Operation(description = "Create service proxy", method = "POST", summary = "Returns created service proxy",
1108 responses = @ApiResponse(
1109 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
1110 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service proxy created"),
1111 @ApiResponse(responseCode = "403", description = "Restricted operation"),
1112 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
1113 @ApiResponse(responseCode = "409", description = "Service proxy already exist")})
1114 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
1115 public Response createServiceProxy(@Parameter(description = "RI object to be created", required = true) String data,
1116 @PathParam("containerComponentId") final String containerComponentId,
1117 @Parameter(description = "valid values: resources / services",
1118 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
1119 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
1120 @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
1121 required = true) String userId,
1122 @Context final HttpServletRequest request) {
1126 ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
1127 componentInstance.setInvariantName(null);
1128 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1129 if (componentTypeEnum != ComponentTypeEnum.SERVICE) {
1130 log.debug("Unsupported container component type {}", containerComponentType);
1131 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1133 if (componentInstanceBusinessLogic == null) {
1134 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
1135 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1137 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createServiceProxy();
1139 if (actionResponse.isRight()) {
1140 return buildErrorResponse(actionResponse.right().value());
1142 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
1144 } catch (Exception e) {
1145 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create service proxy");
1146 log.debug("Create service proxy failed with exception", e);
1152 @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}")
1153 @Consumes(MediaType.APPLICATION_JSON)
1154 @Produces(MediaType.APPLICATION_JSON)
1155 @Operation(description = "Delete service proxy", method = "DELETE", summary = "Returns delete service proxy",
1156 responses = @ApiResponse(
1157 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
1158 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service proxy deleted"),
1159 @ApiResponse(responseCode = "403", description = "Restricted operation"),
1160 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
1161 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
1162 public Response deleteServiceProxy(@PathParam("containerComponentId") final String containerComponentId,
1163 @PathParam("serviceProxyId") final String serviceProxyId,
1164 @Parameter(description = "valid values: resources / services / products",
1165 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
1166 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
1167 @Context final HttpServletRequest request) {
1169 String url = request.getMethod() + " " + request.getRequestURI();
1171 log.debug(START_HANDLE_REQUEST_OF, url);
1172 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1173 if (componentInstanceBusinessLogic == null) {
1174 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
1175 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1177 String userId = request.getHeader(Constants.USER_ID_HEADER);
1178 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.deleteServiceProxy();
1180 if (actionResponse.isRight()) {
1181 return buildErrorResponse(actionResponse.right().value());
1183 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
1185 } catch (Exception e) {
1186 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete service proxy");
1187 log.debug("Delete service proxy failed with exception", e);
1193 @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}/changeVersion/{newServiceId}")
1194 @Consumes(MediaType.APPLICATION_JSON)
1195 @Produces(MediaType.APPLICATION_JSON)
1196 @Operation(description = "Update service proxy with new version", method = "POST",
1197 summary = "Returns updated service proxy", responses = @ApiResponse(
1198 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
1199 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service proxy created"),
1200 @ApiResponse(responseCode = "403", description = "Restricted operation"),
1201 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
1202 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
1203 public Response changeServiceProxyVersion(@PathParam("containerComponentId") final String containerComponentId,
1204 @PathParam("serviceProxyId") final String serviceProxyId,
1205 @Parameter(description = "valid values: resources / services",
1206 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
1207 ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
1208 @Context final HttpServletRequest request) {
1211 String url = request.getMethod() + " " + request.getRequestURI();
1212 log.debug(START_HANDLE_REQUEST_OF, url);
1215 String userId = request.getHeader(Constants.USER_ID_HEADER);
1217 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1218 if (componentInstanceBusinessLogic == null) {
1219 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
1220 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1222 Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.changeServiceProxyVersion();
1224 if (actionResponse.isRight()) {
1225 return buildErrorResponse(actionResponse.right().value());
1227 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
1229 } catch (Exception e) {
1230 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update service proxy with new version");
1231 log.debug("Update service proxy with new version failed with exception", e);
1236 * REST API GET relation by Id
1237 * Allows to get relation contained in specified component according to received Id
1238 * @param containerComponentType
1239 * @param componentId
1246 @Path("/{containerComponentType}/{componentId}/relationId/{relationId}")
1247 @Consumes(MediaType.APPLICATION_JSON)
1248 @Produces(MediaType.APPLICATION_JSON)
1249 @Operation(description = "Get relation", method = "GET",
1250 summary = "Returns relation metadata according to relationId",responses = @ApiResponse(
1251 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
1252 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "relation found"),
1253 @ApiResponse(responseCode = "403", description = "Restricted operation"),
1254 @ApiResponse(responseCode = "404", description = "Relation not found")})
1255 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
1256 public Response getRelationById(@PathParam("containerComponentType") final String containerComponentType,
1257 @PathParam("componentId") final String componentId, @PathParam("relationId") final String relationId,
1258 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
1261 String url = request.getMethod() + " " + request.getRequestURI();
1262 log.debug(GET_START_HANDLE_REQUEST_OF, url);
1264 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1265 if (componentTypeEnum == null) {
1266 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
1267 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1270 Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceBusinessLogic.getRelationById(componentId, relationId, userId, componentTypeEnum);
1271 if (actionResponse.isRight()) {
1272 return buildErrorResponse(actionResponse.right().value());
1274 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
1275 } catch (Exception e) {
1276 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getRelationById");
1277 log.debug("getRelationById unexpected exception", e);
1282 private Either<ComponentInstance, ResponseFormat> convertToResourceInstance(String data) {
1284 Either<ComponentInstance, ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), ComponentInstance.class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1285 if (convertStatus.isRight()) {
1286 return Either.right(convertStatus.right().value());
1288 ComponentInstance resourceInstanceInfo = convertStatus.left().value();
1290 return Either.left(resourceInstanceInfo);
1293 private Either<List<ComponentInstance>, ResponseFormat> convertToMultipleResourceInstance(String dataList) {
1295 Either<ComponentInstance[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstance[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1296 if (convertStatus.isRight()) {
1297 return Either.right(convertStatus.right().value());
1300 return Either.left(Arrays.asList(convertStatus.left().value()));
1303 private Either<List<ComponentInstanceProperty>, ResponseFormat> convertMultipleProperties(String dataList) {
1304 if (StringUtils.isEmpty(dataList)) {
1305 return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_BODY));
1307 Either<ComponentInstanceProperty[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstanceProperty[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1308 if (convertStatus.isRight()) {
1309 return Either.right(convertStatus.right().value());
1311 return Either.left(Arrays.asList(convertStatus.left().value()));
1314 private Either<List<ComponentInstanceInput>, ResponseFormat> convertMultipleInputs(String dataList) {
1315 if (StringUtils.isEmpty(dataList)) {
1316 return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_BODY));
1318 Either<ComponentInstanceInput[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstanceInput[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
1319 if (convertStatus.isRight()) {
1320 return Either.right(convertStatus.right().value());
1322 return Either.left(Arrays.asList(convertStatus.left().value()));
1326 private RequirementCapabilityRelDef convertToRequirementCapabilityRelDef(String data) {
1328 Either<RequirementCapabilityRelDef, ActionStatus> convertStatus = convertJsonToObject(data, RequirementCapabilityRelDef.class);
1329 if (convertStatus.isRight()) {
1330 throw new ByActionStatusComponentException(convertStatus.right().value());
1332 RequirementCapabilityRelDef requirementCapabilityRelDef = convertStatus.left().value();
1333 return requirementCapabilityRelDef;
1336 public <T> Either<T, ActionStatus> convertJsonToObject(String data, Class<T> clazz) {
1338 log.trace("convert json to object. json=\n {}", data);
1340 t = gsonDeserializer.fromJson(data, clazz);
1342 BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
1343 log.debug("object is null after converting from json");
1344 return Either.right(ActionStatus.INVALID_CONTENT);
1346 return Either.left(t);
1347 } catch (Exception e) {
1349 BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
1350 log.debug("failed to convert from json", e);
1351 return Either.right(ActionStatus.INVALID_CONTENT);
1357 @Path("/{containerComponentType}/{componentId}/paths-to-delete")
1358 @Produces(MediaType.APPLICATION_JSON)
1359 @Operation(description = "Check if forwarding path to delete on version change", method = "GET", summary = "Returns forwarding paths to delete",
1360 responses = @ApiResponse(
1361 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
1362 public Response changeResourceInstanceVersion( @PathParam("componentId") String componentId,
1363 @QueryParam("componentInstanceId") final String oldComponentInstanceId,
1364 @QueryParam("newComponentInstanceId") final String newComponentInstanceId,
1365 @Parameter(description = "valid values: resources / services",
1366 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
1367 ComponentTypeEnum.SERVICE_PARAM_NAME}))
1368 @PathParam("containerComponentType") final String containerComponentType,
1369 @Context final HttpServletRequest request) {
1370 if (oldComponentInstanceId == null){
1371 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_OLD_COMPONENT_INSTANCE));
1373 if (newComponentInstanceId == null){
1374 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_NEW_COMPONENT_INSTANCE));
1378 String url = request.getMethod() + " " + request.getRequestURI();
1379 log.debug(START_HANDLE_REQUEST_OF, url);
1380 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1381 if (componentInstanceBusinessLogic == null) {
1382 log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
1383 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1385 ComponentInstance newComponentInstance;
1386 if(StringUtils.isNotEmpty(newComponentInstanceId)){
1387 newComponentInstance=new ComponentInstance();
1388 newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,newComponentInstanceId);
1390 log.error("missing component id");
1391 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_DATA));
1393 Either<Set<String>,ResponseFormat> actionResponse= componentInstanceBusinessLogic.forwardingPathOnVersionChange(
1394 containerComponentType,componentId,oldComponentInstanceId,newComponentInstance);
1395 if (actionResponse.isRight()) {
1396 return buildErrorResponse(actionResponse.right().value());
1398 ForwardingPaths forwardingPaths=new ForwardingPaths();
1399 forwardingPaths.setForwardingPathToDelete(actionResponse.left().value());
1400 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), forwardingPaths);
1405 @Path("/services/{componentId}/copyComponentInstance/{componentInstanceId}")
1406 @Consumes(MediaType.APPLICATION_JSON)
1407 @Produces((MediaType.APPLICATION_JSON))
1408 @Operation(description = "Copy Component Instance", method = "POST", summary = "Returns updated service information",responses = @ApiResponse(
1409 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
1410 @ApiResponses(value = {
1411 @ApiResponse(responseCode = "201", description = "Copy and Paste Success"),
1412 @ApiResponse(responseCode = "403", description = "Restricted Operation"),
1413 @ApiResponse(responseCode = "400", description = "Invalid Content / Missing content")})
1414 public Response copyComponentInstance(
1415 @Parameter(description = "service unique id in pasted canvas") @PathParam("componentId") final String containerComponentId,
1416 @Parameter(description = "Data for copying", required = true) String data, @PathParam("componentInstanceId") final String componentInstanceId,
1417 @Context final HttpServletRequest request) {
1418 log.info("Start to copy component instance");
1420 String userId = request.getHeader(Constants.USER_ID_HEADER);
1421 final String CNTAINER_CMPT_TYPE = "services";
1424 ComponentInstance inputComponentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
1425 inputComponentInstance.setInvariantName(null);
1426 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(CNTAINER_CMPT_TYPE);
1427 if (componentInstanceBusinessLogic == null) {
1428 log.debug(UNSUPPORTED_COMPONENT_TYPE, componentTypeEnum);
1429 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, "services"));
1431 Either<Map<String, ComponentInstance>, ResponseFormat> copyComponentInstance = componentInstanceBusinessLogic.copyComponentInstance(
1432 inputComponentInstance, containerComponentId, componentInstanceId, userId);
1434 if (copyComponentInstance.isRight()) {
1435 log.error("Failed to copy ComponentInstance {}", copyComponentInstance.right().value());
1436 return buildErrorResponse(copyComponentInstance.right().value());
1439 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
1440 copyComponentInstance.left().value());
1441 } catch (Exception e) {
1442 log.error("Failed to convert json to Map { }", data, e);
1443 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.USER_DEFINED,
1444 "Failed to get the copied component instance information"));
1449 @Path("/{containerComponentType}/{componentId}/batchDeleteResourceInstances/")
1450 @Consumes(MediaType.APPLICATION_JSON)
1451 @Produces(MediaType.APPLICATION_JSON)
1452 @Operation(description = "Batch Delete ResourceInstances", method = "POST")
1453 @ApiResponses(value = {
1454 @ApiResponse(responseCode = "203", description = "ResourceInstances deleted"),
1455 @ApiResponse(responseCode = "403", description = "Restricted Operation"),
1456 @ApiResponse(responseCode = "400", description = "Invalid Content / Missing Content")
1458 public Response batchDeleteResourceInstances(
1459 @Parameter(description = "valid values: resources / services / products", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
1460 ComponentTypeEnum.SERVICE_PARAM_NAME,
1461 ComponentTypeEnum.PRODUCT_PARAM_NAME}))
1462 @PathParam("containerComponentType") final String containerComponentType,
1463 @PathParam("componentId") final String componentId,
1464 @Context final HttpServletRequest request,
1465 @Parameter(description = "Component Instance Id List", required = true) final String componentInstanceIdLisStr) {
1467 if (componentInstanceIdLisStr == null || componentInstanceIdLisStr.isEmpty()) {
1468 log.error("Empty JSON List was sent",componentInstanceIdLisStr);
1469 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
1473 if (componentInstanceBusinessLogic == null) {
1474 log.error("Unsupported component type {}", containerComponentType);
1475 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1478 Either<List<String>, ResponseFormat> convertResponse = convertToStringList(componentInstanceIdLisStr);
1480 if (convertResponse.isRight()) {
1481 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - batchDeleteResourceInstances");
1482 log.error("Failed to convert received data to BE format.");
1483 return buildErrorResponse(convertResponse.right().value());
1486 String userId = request.getHeader(Constants.USER_ID_HEADER);
1487 List<String> componentInstanceIdList = convertResponse.left().value();
1488 log.debug("batchDeleteResourceInstances componentInstanceIdList is {}", componentInstanceIdList);
1489 Map<String, List<String>> deleteErrorMap = componentInstanceBusinessLogic.batchDeleteComponentInstance(containerComponentType,
1490 componentId, componentInstanceIdList, userId);
1492 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteErrorMap);
1493 } catch (Exception e) {
1494 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Batch Delete ResourceInstances");
1495 log.error("batch delete resource instances with exception" , e);
1496 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
1502 @Path("/{containerComponentType}/{componentId}/resourceInstance/batchDissociate")
1503 @Consumes(MediaType.APPLICATION_JSON)
1504 @Produces(MediaType.APPLICATION_JSON)
1505 @Operation(description = "Batch Dissociate RI from RI", method = "PUT",
1506 summary = "Returns deleted RelationShip Info", responses = @ApiResponse(
1507 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
1508 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship deleted"),
1509 @ApiResponse(responseCode = "403", description = "Missing Information"),
1510 @ApiResponse(responseCode = "400", description = "Invalid Content / Missing Content")})
1511 public Response batchDissociateRIFromRI(
1512 @Parameter(description = "allowed values are resources/services/products",
1513 schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
1514 ComponentTypeEnum.SERVICE_PARAM_NAME,
1515 ComponentTypeEnum.PRODUCT_PARAM_NAME}),
1516 required = true) @PathParam("containerComponentType") final String containerComponentType,
1518 description = "unique id of the container component") @PathParam("componentId") final String componentId,
1519 @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
1520 @Parameter(description = "RelationshipInfo", required = true) String data,
1521 @Context final HttpServletRequest request) {
1525 if (data == null || data.length() == 0) {
1526 log.info("Empty JSON list was sent");
1527 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
1530 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
1532 if (componentInstanceBusinessLogic == null) {
1533 log.debug("Unsupported component type {}", containerComponentType);
1534 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
1537 Either<List<RequirementCapabilityRelDef>, ResponseFormat> regInfoWs = convertToRequirementCapabilityRelDefList(data);
1539 if (regInfoWs.isRight()) {
1540 BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - batch dissociateRIFromRI");
1541 log.debug("Failed to convert received data to BE format");
1542 return buildErrorResponse(regInfoWs.right().value());
1545 List<RequirementCapabilityRelDef> requirementDefList = regInfoWs.left().value();
1546 List<RequirementCapabilityRelDef> delOkResult = componentInstanceBusinessLogic.batchDissociateRIFromRI(
1547 componentId, userId, requirementDefList, componentTypeEnum);
1549 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), delOkResult);
1550 } catch (Exception e) {
1551 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Batch Dissociate Resource Instance");
1552 log.debug("batch dissociate resource instance from service failed with exception", e);
1553 return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
1557 private Either<List<String>, ResponseFormat> convertToStringList(String datalist) {
1558 Either<String[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(datalist, new User(), String[].class, null, null);
1560 if (convertStatus.isRight()) {
1561 return Either.right(convertStatus.right().value());
1564 return Either.left(Arrays.asList(convertStatus.left().value()));
1567 private Either<List<RequirementCapabilityRelDef>, ResponseFormat> convertToRequirementCapabilityRelDefList(String data) {
1568 Either<RequirementCapabilityRelDef[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), RequirementCapabilityRelDef[].class, null, null);
1570 if (convertStatus.isRight()) {
1571 return Either.right(convertStatus.right().value());
1574 return Either.left(Arrays.asList(convertStatus.left().value()));