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.google.gson.reflect.TypeToken;
26 import com.jcabi.aspects.Loggable;
27 import fj.data.Either;
28 import io.swagger.annotations.Api;
29 import io.swagger.v3.oas.annotations.Operation;
30 import io.swagger.v3.oas.annotations.Parameter;
31 import io.swagger.v3.oas.annotations.media.ArraySchema;
32 import io.swagger.v3.oas.annotations.media.Content;
33 import io.swagger.v3.oas.annotations.media.Schema;
34 import io.swagger.v3.oas.annotations.responses.ApiResponse;
35 import io.swagger.v3.oas.annotations.responses.ApiResponses;
36 import org.apache.http.HttpStatus;
37 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
38 import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
39 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
40 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
41 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
42 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
43 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
44 import org.openecomp.sdc.be.config.BeEcompErrorManager;
45 import org.openecomp.sdc.be.dao.api.ActionStatus;
46 import org.openecomp.sdc.be.datamodel.ServiceRelations;
47 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
48 import org.openecomp.sdc.be.impl.ComponentsUtils;
49 import org.openecomp.sdc.be.impl.ServletUtils;
50 import org.openecomp.sdc.be.model.DistributionStatusEnum;
51 import org.openecomp.sdc.be.model.GroupInstanceProperty;
52 import org.openecomp.sdc.be.model.Resource;
53 import org.openecomp.sdc.be.model.Service;
54 import org.openecomp.sdc.be.model.User;
55 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
56 import org.openecomp.sdc.be.user.UserBusinessLogic;
57 import org.openecomp.sdc.common.api.Constants;
58 import org.openecomp.sdc.common.datastructure.Wrapper;
59 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
60 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
61 import org.openecomp.sdc.common.log.enums.StatusCode;
62 import org.openecomp.sdc.common.log.wrappers.Logger;
63 import org.openecomp.sdc.exception.ResponseFormat;
64 import org.springframework.stereotype.Controller;
66 import javax.inject.Inject;
67 import javax.servlet.ServletContext;
68 import javax.servlet.http.HttpServletRequest;
69 import javax.ws.rs.Consumes;
70 import javax.ws.rs.DELETE;
71 import javax.ws.rs.GET;
72 import javax.ws.rs.HeaderParam;
73 import javax.ws.rs.POST;
74 import javax.ws.rs.PUT;
75 import javax.ws.rs.Path;
76 import javax.ws.rs.PathParam;
77 import javax.ws.rs.Produces;
78 import javax.ws.rs.core.Context;
79 import javax.ws.rs.core.MediaType;
80 import javax.ws.rs.core.Response;
81 import java.io.IOException;
82 import java.lang.reflect.Type;
83 import java.util.ArrayList;
84 import java.util.List;
87 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
89 @Api(value = "Service Catalog", description = "Service Servlet")
91 public class ServiceServlet extends AbstractValidationsServlet {
93 private static final Logger log = Logger.getLogger(ServiceServlet.class);
94 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ServiceServlet.class.getName());
96 private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
97 private static final String MODIFIER_ID_IS = "modifier id is {}";
99 private final ServiceBusinessLogic serviceBusinessLogic;
102 public ServiceServlet(UserBusinessLogic userBusinessLogic,
103 ComponentInstanceBusinessLogic componentInstanceBL,
104 ComponentsUtils componentsUtils, ServletUtils servletUtils,
105 ResourceImportManager resourceImportManager,
106 ServiceBusinessLogic serviceBusinessLogic,
107 ResourceBusinessLogic resourceBusinessLogic) {
108 super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
109 this.serviceBusinessLogic = serviceBusinessLogic;
114 @Consumes(MediaType.APPLICATION_JSON)
115 @Produces(MediaType.APPLICATION_JSON)
116 @Operation(description = "Create Service", method = "POST", summary = "Returns created service",
117 responses = @ApiResponse(
118 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
119 @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service created"),
120 @ApiResponse(responseCode = "403", description = "Restricted operation"),
121 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
122 @ApiResponse(responseCode = "409", description = "Service already exist")})
123 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
124 public Response createService(@Parameter(description = "Service object to be created", required = true) String data,
125 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
127 String url = request.getMethod() + " " + request.getRequestURI();
128 log.debug(START_HANDLE_REQUEST_OF, url);
129 User modifier = new User();
130 modifier.setUserId(userId);
131 log.debug(MODIFIER_ID_IS, userId);
132 loggerSupportability.log(LoggerSupportabilityActions.CREATE_SERVICE,StatusCode.STARTED,"Starting to create a service by user {} ",userId);
134 validateNotEmptyBody(data);
135 Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier);
136 if (convertResponse.isRight()) {
137 throw new ByResponseFormatComponentException(convertResponse.right().value());
140 Service service = convertResponse.left().value();
141 Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.createService(service, modifier);
143 if (actionResponse.isRight()) {
144 log.debug("Failed to create service");
145 throw new ByResponseFormatComponentException(actionResponse.right().value());
148 loggerSupportability.log(LoggerSupportabilityActions.CREATE_SERVICE,service.getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"Service {} has been created by user {} ",service.getName(), userId );
150 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
153 public Either<Service, ResponseFormat> parseToService(String serviceJson, User user) {
154 return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, Service.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
158 @Path("/services/validate-name/{serviceName}")
159 @Consumes(MediaType.APPLICATION_JSON)
160 @Produces(MediaType.APPLICATION_JSON)
161 @Operation(description = "validate service name", method = "GET",
162 summary = "checks if the chosen service name is available ", responses = @ApiResponse(
163 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
164 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
165 @ApiResponse(responseCode = "403", description = "Restricted operation")})
166 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
167 public Response validateServiceName(@PathParam("serviceName") final String serviceName,
168 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
169 String url = request.getMethod() + " " + request.getRequestURI();
170 log.debug(START_HANDLE_REQUEST_OF, url);
173 User modifier = new User();
174 modifier.setUserId(userId);
175 log.debug(MODIFIER_ID_IS, userId);
176 Response response = null;
178 Either<Map<String, Boolean>, ResponseFormat> actionResponse =
179 serviceBusinessLogic.validateServiceNameExists(serviceName, userId);
181 if (actionResponse.isRight()) {
182 log.debug("failed to get validate service name");
183 response = buildErrorResponse(actionResponse.right().value());
186 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
187 } catch (Exception e) {
188 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Service Name");
189 log.debug("validate service name failed with exception", e);
195 @Path("/audit-records/{componentType}/{componentUniqueId}")
196 @Consumes(MediaType.APPLICATION_JSON)
197 @Produces(MediaType.APPLICATION_JSON)
198 @Operation(description = "get component audit records", method = "GET",
199 summary = "get audit records for a service or a resource", responses = @ApiResponse(
200 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
201 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
202 @ApiResponse(responseCode = "403", description = "Restricted operation")})
203 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
204 public Response getComponentAuditRecords(@PathParam("componentType") final String componentType,
205 @PathParam("componentUniqueId") final String componentUniqueId, @Context final HttpServletRequest request,
206 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
208 ServletContext context = request.getSession().getServletContext();
209 String url = request.getMethod() + " " + request.getRequestURI();
210 log.debug(START_HANDLE_REQUEST_OF, url);
212 User modifier = new User();
213 modifier.setUserId(userId);
214 log.debug(MODIFIER_ID_IS, userId);
215 Wrapper<Response> responseWrapper = new Wrapper<>();
216 Wrapper<String> uuidWrapper = new Wrapper<>();
217 Wrapper<String> versionWrapper = new Wrapper<>();
218 Wrapper<User> userWrapper = new Wrapper<>();
220 validateUserExist(responseWrapper, userWrapper, userId);
222 if (responseWrapper.isEmpty()) {
223 fillUUIDAndVersion(responseWrapper, uuidWrapper, versionWrapper, userWrapper.getInnerElement(), validateComponentType(componentType), componentUniqueId, context);
226 if (responseWrapper.isEmpty()) {
227 Either<List<Map<String, Object>>, ResponseFormat> eitherServiceAudit = serviceBusinessLogic.getComponentAuditRecords(versionWrapper.getInnerElement(), uuidWrapper.getInnerElement(), userId);
229 if (eitherServiceAudit.isRight()) {
230 Response errorResponse = buildErrorResponse(eitherServiceAudit.right().value());
231 responseWrapper.setInnerElement(errorResponse);
233 List<Map<String, Object>> auditRecords = eitherServiceAudit.left().value();
234 Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), auditRecords);
235 responseWrapper.setInnerElement(okResponse);
240 } catch (Exception e) {
241 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Service Name");
242 log.debug("get Service Audit Records failed with exception", e);
245 return responseWrapper.getInnerElement();
248 private void fillUUIDAndVersion(Wrapper<Response> responseWrapper, Wrapper<String> uuidWrapper, Wrapper<String> versionWrapper, User user, final ComponentTypeEnum componentTypeEnum, final String componentUniqueId, ServletContext context) {
250 if (componentTypeEnum == ComponentTypeEnum.RESOURCE) {
251 Either<Resource, ResponseFormat> eitherResource = getResourceBL(context).getResource(componentUniqueId, user);
252 if (eitherResource.isLeft()) {
253 uuidWrapper.setInnerElement(eitherResource.left().value().getUUID());
254 versionWrapper.setInnerElement(eitherResource.left().value().getVersion());
256 responseWrapper.setInnerElement(buildErrorResponse(eitherResource.right().value()));
260 Either<Service, ResponseFormat> eitherService = getServiceBL(context).getService(componentUniqueId, user);
261 if (eitherService.isLeft()) {
262 uuidWrapper.setInnerElement(eitherService.left().value().getUUID());
263 versionWrapper.setInnerElement(eitherService.left().value().getVersion());
265 responseWrapper.setInnerElement(buildErrorResponse(eitherService.right().value()));
272 @Path("/services/{serviceId}")
273 @Operation(description = "Delete Service", method = "DELETE", summary = "Return no content", responses = @ApiResponse(
274 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
275 @ApiResponses(value = { @ApiResponse(responseCode = "204", description = "Service deleted"),
276 @ApiResponse(responseCode = "403", description = "Restricted operation"),
277 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
278 @ApiResponse(responseCode = "404", description = "Service not found") })
279 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
280 public Response deleteService(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request) {
281 ServletContext context = request.getSession().getServletContext();
282 String url = request.getMethod() + " " + request.getRequestURI();
283 log.debug(START_HANDLE_REQUEST_OF, url);
286 String userId = request.getHeader(Constants.USER_ID_HEADER);
287 User modifier = new User();
288 modifier.setUserId(userId);
289 log.debug(MODIFIER_ID_IS, userId);
290 Response response = null;
292 String serviceIdLower = serviceId.toLowerCase();
293 loggerSupportability.log(LoggerSupportabilityActions.DELETE_SERVICE, StatusCode.STARTED,"Starting to delete service {} by user {} ",serviceIdLower, userId);
294 ServiceBusinessLogic businessLogic = getServiceBL(context);
295 ResponseFormat actionResponse = businessLogic.deleteService(serviceIdLower, modifier);
296 if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
297 log.debug("failed to delete service");
298 response = buildErrorResponse(actionResponse);
301 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
302 loggerSupportability.log(LoggerSupportabilityActions.DELETE_SERVICE,StatusCode.COMPLETE,"Ended deleting service {} by user {}",serviceIdLower, userId);
305 } catch (Exception e) {
306 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service");
307 log.debug("delete service failed with exception", e);
313 @Path("/services/{serviceName}/{version}")
314 @Operation(description = "Delete Service By Name And Version", method = "DELETE", summary = "Returns no content", responses = @ApiResponse(
315 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
316 @ApiResponses(value = { @ApiResponse(responseCode = "204", description = "Service deleted"),
317 @ApiResponse(responseCode = "403", description = "Restricted operation"),
318 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
319 @ApiResponse(responseCode = "404", description = "Service not found") })
320 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
321 public Response deleteServiceByNameAndVersion(@PathParam("serviceName") final String serviceName,
322 @PathParam("version") final String version,
323 @Context final HttpServletRequest request) {
324 String url = request.getMethod() + " " + request.getRequestURI();
325 log.debug(START_HANDLE_REQUEST_OF, url);
328 String userId = request.getHeader(Constants.USER_ID_HEADER);
329 User modifier = new User();
330 modifier.setUserId(userId);
331 log.debug(MODIFIER_ID_IS, userId);
333 Response response = null;
336 ResponseFormat actionResponse = serviceBusinessLogic.deleteServiceByNameAndVersion(serviceName, version, modifier);
338 if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
339 log.debug("failed to delete service");
340 response = buildErrorResponse(actionResponse);
343 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
346 } catch (Exception e) {
347 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service");
348 log.debug("delete service failed with exception", e);
354 @Path("/services/{serviceId}/metadata")
355 @Consumes(MediaType.APPLICATION_JSON)
356 @Produces(MediaType.APPLICATION_JSON)
357 @Operation(description = "Update Service Metadata", method = "PUT", summary = "Returns updated service",
358 responses = @ApiResponse(
359 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
360 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service Updated"),
361 @ApiResponse(responseCode = "403", description = "Restricted operation"),
362 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
363 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
364 public Response updateServiceMetadata(@PathParam("serviceId") final String serviceId,
365 @Parameter(description = "Service object to be Updated", required = true) String data,
366 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
368 String url = request.getMethod() + " " + request.getRequestURI();
369 log.debug(START_HANDLE_REQUEST_OF, url);
371 User modifier = new User();
372 modifier.setUserId(userId);
373 log.debug(MODIFIER_ID_IS, userId);
375 Response response = null;
378 String serviceIdLower = serviceId.toLowerCase();
380 Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier);
381 if (convertResponse.isRight()) {
382 log.debug("failed to parse service");
383 response = buildErrorResponse(convertResponse.right().value());
386 Service updatedService = convertResponse.left().value();
387 Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.updateServiceMetadata(serviceIdLower, updatedService, modifier);
389 if (actionResponse.isRight()) {
390 log.debug("failed to update service");
391 response = buildErrorResponse(actionResponse.right().value());
395 Service service = actionResponse.left().value();
396 Object result = RepresentationUtils.toRepresentation(service);
397 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
399 } catch (Exception e) {
400 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Service Metadata");
401 log.debug("update service metadata failed with exception", e);
406 * updates group instance property values
407 * Note, than in case of group instance updated successfully, related resourceInstance and containing component modification time will be updated
409 * @param componentInstanceId
410 * @param groupInstanceId
417 @Path("/{containerComponentType}/{serviceId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}")
418 @Consumes(MediaType.APPLICATION_JSON)
419 @Produces(MediaType.APPLICATION_JSON)
420 @Operation(description = "Update Group Instance Property Values", method = "PUT",
421 summary = "Returns updated group instance", responses = @ApiResponse(
422 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
423 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group Instance Property Values Updated"),
424 @ApiResponse(responseCode = "403", description = "Restricted operation"),
425 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
426 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
427 public Response updateGroupInstancePropertyValues(@PathParam("serviceId") final String serviceId,
428 @PathParam("componentInstanceId") final String componentInstanceId,
429 @PathParam("groupInstanceId") final String groupInstanceId,
430 @Parameter(description = "Group instance object to be Updated", required = true) String data,
431 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws JsonProcessingException {
433 Response response = null;
434 String url = request.getMethod() + " " + request.getRequestURI();
435 log.debug(START_HANDLE_REQUEST_OF, url);
437 User modifier = new User();
438 modifier.setUserId(userId);
439 log.debug(MODIFIER_ID_IS,userId);
441 Either<List<GroupInstanceProperty>, ResponseFormat> actionResponse = null;
443 List<GroupInstanceProperty> updatedProperties;
444 Type listType = new TypeToken<ArrayList<GroupInstanceProperty>>(){}.getType();
445 ArrayList<GroupInstanceProperty> newProperties = gson.fromJson(data, listType);
446 if (newProperties == null) {
447 actionResponse = Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
449 if(actionResponse == null){
450 log.debug("Start handle update group instance property values request. Received group instance is {}", groupInstanceId);
451 actionResponse = serviceBusinessLogic.updateGroupInstancePropertyValues(modifier, serviceId, componentInstanceId, groupInstanceId, newProperties);
452 if(actionResponse.isRight()){
453 actionResponse = Either.right(actionResponse.right().value());
456 if(actionResponse.isLeft()){
457 updatedProperties = actionResponse.left().value();
458 ObjectMapper mapper = new ObjectMapper();
459 String result = mapper.writeValueAsString(updatedProperties);
460 response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
463 response = buildErrorResponse(actionResponse.right().value());
465 } catch (Exception e) {
466 log.error("Exception occured during update Group Instance property values: {}", e.getMessage(), e);
473 @Path("/services/{serviceId}")
474 @Consumes(MediaType.APPLICATION_JSON)
475 @Produces(MediaType.APPLICATION_JSON)
476 @Operation(description = "Retrieve Service", method = "GET", summary = "Returns service according to serviceId",
477 responses = @ApiResponse(
478 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
479 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
480 @ApiResponse(responseCode = "403", description = "Restricted operation"),
481 @ApiResponse(responseCode = "404", description = "Service not found")})
482 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
483 public Response getServiceById(@PathParam("serviceId") final String serviceId,
484 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
486 String url = request.getMethod() + " " + request.getRequestURI();
487 log.debug(START_HANDLE_REQUEST_OF, url);
490 User modifier = new User();
491 modifier.setUserId(userId);
492 log.debug(MODIFIER_ID_IS, userId);
494 Response response = null;
496 String serviceIdLower = serviceId.toLowerCase();
497 log.debug("get service with id {}", serviceId);
498 Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.getService(serviceIdLower, modifier);
500 if (actionResponse.isRight()) {
501 log.debug("failed to get service");
502 response = buildErrorResponse(actionResponse.right().value());
506 Service service = actionResponse.left().value();
507 Object result = RepresentationUtils.toRepresentation(service);
509 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
511 } catch (Exception e) {
512 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service");
513 log.debug("get service failed with exception", e);
519 @Path("/services/serviceName/{serviceName}/serviceVersion/{serviceVersion}")
520 @Consumes(MediaType.APPLICATION_JSON)
521 @Produces(MediaType.APPLICATION_JSON)
522 @Operation(description = "Retrieve Service", method = "GET",
523 summary = "Returns service according to name and version", responses = @ApiResponse(
524 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
525 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
526 @ApiResponse(responseCode = "403", description = "Restricted operation"),
527 @ApiResponse(responseCode = "404", description = "Service not found")})
528 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
529 public Response getServiceByNameAndVersion(@PathParam("serviceName") final String serviceName,
530 @PathParam("serviceVersion") final String serviceVersion, @Context final HttpServletRequest request,
531 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
534 User modifier = new User();
535 modifier.setUserId(userId);
536 log.debug(MODIFIER_ID_IS, userId);
538 Response response = null;
540 Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.getServiceByNameAndVersion(serviceName, serviceVersion, userId);
542 if (actionResponse.isRight()) {
543 response = buildErrorResponse(actionResponse.right().value());
547 Service service = actionResponse.left().value();
548 Object result = RepresentationUtils.toRepresentation(service);
550 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
552 } catch (Exception e) {
553 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service by name and version");
554 log.debug("get service failed with exception", e);
560 @Path("/services/{serviceId}/distribution/{env}/activate")
561 @Consumes(MediaType.APPLICATION_JSON)
562 @Produces(MediaType.APPLICATION_JSON)
563 @Operation(description = "Activate distribution", method = "POST", summary = "activate distribution")
564 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
565 @ApiResponse(responseCode = "409",
566 description = "Service cannot be distributed due to missing deployment artifacts"),
567 @ApiResponse(responseCode = "404", description = "Requested service was not found"),
568 @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")})
569 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
570 public Response activateDistribution(@PathParam("serviceId") final String serviceId,
571 @PathParam("env") final String env, @Context final HttpServletRequest request,
572 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
574 String url = request.getMethod() + " " + request.getRequestURI();
575 log.debug(START_HANDLE_REQUEST_OF, url);
577 User modifier = new User();
578 modifier.setUserId(userId);
579 log.debug(MODIFIER_ID_IS, userId);
581 Response response = null;
582 Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.activateDistribution(serviceId, env, modifier, request);
584 if (distResponse.isRight()) {
585 log.debug("failed to activate service distribution");
586 response = buildErrorResponse(distResponse.right().value());
589 Service service = distResponse.left().value();
590 Object result = null;
592 result = RepresentationUtils.toRepresentation(service);
593 } catch (IOException e) {
594 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Activate Distribution");
595 log.debug("activate distribution failed with exception", e);
598 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
602 @Path("/services/{serviceId}/distribution/{did}/markDeployed")
603 @Consumes(MediaType.APPLICATION_JSON)
604 @Produces(MediaType.APPLICATION_JSON)
605 @Operation(description = "Mark distribution as deployed", method = "POST",
606 summary = "relevant audit record will be created")
607 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service was marked as deployed"),
608 @ApiResponse(responseCode = "409", description = "Restricted operation"),
609 @ApiResponse(responseCode = "403", description = "Service is not available"),
610 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
611 @ApiResponse(responseCode = "404", description = "Requested service was not found"),
612 @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")})
613 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
614 public Response markDistributionAsDeployed(@PathParam("serviceId") final String serviceId,
615 @PathParam("did") final String did, @Context final HttpServletRequest request,
616 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
618 String url = request.getMethod() + " " + request.getRequestURI();
619 log.debug(START_HANDLE_REQUEST_OF, url);
621 User modifier = new User();
622 modifier.setUserId(userId);
623 log.debug(MODIFIER_ID_IS, userId);
625 Response response = null;
627 Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.markDistributionAsDeployed(serviceId, did, modifier);
629 if (distResponse.isRight()) {
630 log.debug("failed to mark distribution as deployed");
631 response = buildErrorResponse(distResponse.right().value());
634 Service service = distResponse.left().value();
635 Object result = RepresentationUtils.toRepresentation(service);
636 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
637 } catch (Exception e) {
638 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Mark Distribution As Deployed");
639 log.debug("mark distribution as deployed failed with exception", e);
645 @Path("/services/{serviceId}/tempUrlToBeDeleted")
646 @Consumes(MediaType.APPLICATION_JSON)
647 @Produces(MediaType.APPLICATION_JSON)
648 @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.") })
649 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
650 public Response tempUrlToBeDeleted(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
652 ServletContext context = request.getSession().getServletContext();
653 String url = request.getMethod() + " " + request.getRequestURI();
654 log.debug(START_HANDLE_REQUEST_OF, url);
656 User modifier = new User();
657 modifier.setUserId(userId);
658 log.debug(MODIFIER_ID_IS, userId);
662 Service service = (serviceBusinessLogic.getService(serviceId, modifier)).left().value();
663 Either<Service, ResponseFormat> res = serviceBusinessLogic.updateDistributionStatusForActivation(service, modifier, DistributionStatusEnum.DISTRIBUTED);
666 response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
668 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
669 } catch (Exception e) {
670 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("tempUrlToBeDeleted");
671 log.debug("failed with exception", e);
678 @Path("/services/{serviceId}/linksMap")
679 @Consumes(MediaType.APPLICATION_JSON)
680 @Produces(MediaType.APPLICATION_JSON)
681 @Operation(description = "Retrieve Service component relations map", method = "GET",
682 summary = "Returns service components relations",responses = @ApiResponse(
683 content = @Content(array = @ArraySchema(schema = @Schema(implementation = ServiceRelations.class)))))
684 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
685 @ApiResponse(responseCode = "403", description = "Restricted operation"),
686 @ApiResponse(responseCode = "404", description = "Service not found")})
687 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
688 public Response getServiceComponentRelationMap(@PathParam("serviceId") final String serviceId,
689 @Context final HttpServletRequest request,
690 @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
692 String url = request.getMethod() + " " + request.getRequestURI();
693 log.debug(START_HANDLE_REQUEST_OF, url);
696 User modifier = new User();
697 modifier.setUserId(userId);
698 log.debug(MODIFIER_ID_IS, userId);
700 Response response = null;
702 String serviceIdLower = serviceId.toLowerCase();
703 log.debug("get service components relations with id {}", serviceId);
704 Either<ServiceRelations, ResponseFormat> actionResponse = serviceBusinessLogic.getServiceComponentsRelations(serviceIdLower, modifier);
706 if (actionResponse.isRight()) {
707 log.debug("failed to get service relations data");
708 response = buildErrorResponse(actionResponse.right().value());
712 ServiceRelations serviceRelations = actionResponse.left().value();
713 Object result = RepresentationUtils.toRepresentation(serviceRelations);
715 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
717 } catch (Exception e) {
718 BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service");
719 log.debug("get service relations data failed with exception", e);