2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.jcabi.aspects.Loggable;
24 import io.swagger.annotations.Api;
25 import io.swagger.annotations.ApiOperation;
26 import io.swagger.annotations.ApiResponse;
27 import io.swagger.annotations.ApiResponses;
28 import javax.inject.Inject;
29 import org.openecomp.sdc.be.components.impl.ArchiveBusinessLogic;
30 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
31 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
32 import org.openecomp.sdc.common.api.Constants;
33 import org.springframework.stereotype.Controller;
34 import org.springframework.web.bind.annotation.RequestBody;
37 import javax.ws.rs.core.MediaType;
38 import javax.ws.rs.core.Response;
39 import java.util.HashMap;
40 import java.util.LinkedList;
41 import java.util.List;
45 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
47 @Api(value = "Archive Endpoint")
49 @Consumes(MediaType.APPLICATION_JSON)
50 @Produces(MediaType.APPLICATION_JSON)
51 public class ArchiveEndpoint {
53 private final ArchiveBusinessLogic archiveBusinessLogic;
56 public ArchiveEndpoint(ArchiveBusinessLogic archiveBusinessLogic) {
57 this.archiveBusinessLogic = archiveBusinessLogic;
61 @Path("/resources/{componentId}/archive")
62 @ApiOperation(value = "Archive Resource", httpMethod = "POST", notes = "Marks a resource as archived. Can be restored with restore action", response = String.class, responseContainer = "")
63 @ApiResponses(value = {
64 @ApiResponse(code = 200, message = "Archive successful"),
65 @ApiResponse(code = 400, message = "Bad request"),
66 @ApiResponse(code = 403, message = "Restricted operation"),
67 @ApiResponse(code = 404, message = "Resource not found"),
68 @ApiResponse(code = 500, message = "Internal Error")
70 public Response archiveResources(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
71 archiveBusinessLogic.archiveComponent(ComponentTypeEnum.RESOURCE_PARAM_NAME, userId, componentId);
72 return Response.ok().build();
76 @Path("/resources/{componentId}/restore")
77 @ApiOperation(value = "Restore Resource", httpMethod = "POST", notes = "Restores a resource from archive.", response = String.class, responseContainer = "")
78 @ApiResponses(value = {
79 @ApiResponse(code = 200, message = "Restore successful"),
80 @ApiResponse(code = 400, message = "Bad request"),
81 @ApiResponse(code = 403, message = "Restricted operation"),
82 @ApiResponse(code = 404, message = "Resource not found"),
83 @ApiResponse(code = 500, message = "Internal Error")
85 public Response restoreResource(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
86 archiveBusinessLogic.restoreComponent(ComponentTypeEnum.RESOURCE_PARAM_NAME, userId, componentId);
87 return Response.ok().build();
91 @Path("/services/{componentId}/archive")
92 @ApiOperation(value = "Archive Service", httpMethod = "POST", notes = "Marks a service as archived. Can be restored with restore action", response = String.class, responseContainer = "")
93 @ApiResponses(value = {
94 @ApiResponse(code = 200, message = "Archive successful"),
95 @ApiResponse(code = 400, message = "Bad request"),
96 @ApiResponse(code = 403, message = "Restricted operation"),
97 @ApiResponse(code = 404, message = "Service not found"),
98 @ApiResponse(code = 500, message = "Internal Error")
100 public Response archiveService(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
101 archiveBusinessLogic.archiveComponent(ComponentTypeEnum.SERVICE_PARAM_NAME, userId, componentId);
102 return Response.ok().build();
107 @Path("/services/{componentId}/restore")
108 @ApiOperation(value = "Restore Service", httpMethod = "POST", notes = "Restores a service from archive.", response = String.class, responseContainer = "")
109 @ApiResponses(value = {
110 @ApiResponse(code = 200, message = "Restore successful"),
111 @ApiResponse(code = 400, message = "Bad request"),
112 @ApiResponse(code = 403, message = "Restricted operation"),
113 @ApiResponse(code = 404, message = "Service not found"),
114 @ApiResponse(code = 500, message = "Internal Error")
116 public Response restoreService(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
117 archiveBusinessLogic.restoreComponent(ComponentTypeEnum.SERVICE_PARAM_NAME, userId, componentId);
118 return Response.ok().build();
123 @ApiOperation(value = "Get all Archived Components", httpMethod = "GET", notes = "Get all Archived Components", response = String.class, responseContainer = "")
124 @ApiResponses(value = {
125 @ApiResponse(code = 200, message = "Success"),
126 @ApiResponse(code = 400, message = "Bad request"),
127 @ApiResponse(code = 403, message = "Restricted operation"),
128 @ApiResponse(code = 500, message = "Internal Error")
130 public Map<String, List<CatalogComponent>> getArchivedComponents(@HeaderParam(value = Constants.USER_ID_HEADER) String userId){
131 return this.archiveBusinessLogic.getArchiveComponents(userId, new LinkedList<>());
135 @Path("/notif/vsp/archived")
136 @ApiOperation(value = "Notify about an archived VSP. All VFs with relation to the given CSAR IDs will be martked as vspArchived=true", httpMethod = "POST")
137 @ApiResponses(value = {
138 @ApiResponse(code = 200, message = "Success"),
139 @ApiResponse(code = 400, message = "Bad request"),
140 @ApiResponse(code = 403, message = "Restricted operation"),
141 @ApiResponse(code = 500, message = "Internal Error. A list of the failed CSAR IDs may be returned.")
143 public Response onVspArchived(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @RequestBody List<String> csarIds){
144 List<String> failedCsarIds = this.archiveBusinessLogic.onVspArchive(userId, csarIds);
145 if (!failedCsarIds.isEmpty()){
146 //There are some failed CSAR IDs, return 500 and the list of failed CSAR IDs
147 Map<String, List<String>> entity = new HashMap<>();
148 entity.put("failedIds", failedCsarIds);
149 return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
153 return Response.ok().build();
157 @Path("/notif/vsp/restored")
158 @ApiOperation(value = "Notify about a restored VSP. All VFs with relation to the given CSAR IDs will be martked as vspArchived=false", httpMethod = "POST")
159 @ApiResponses(value = {
160 @ApiResponse(code = 200, message = "Success"),
161 @ApiResponse(code = 400, message = "Bad request"),
162 @ApiResponse(code = 403, message = "Restricted operation"),
163 @ApiResponse(code = 500, message = "Internal Error. A list of the failed CSAR IDs may be returned.")
165 public Response onVspRestored(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @RequestBody List<String> csarIds){
166 List<String> failedCsarIds = this.archiveBusinessLogic.onVspRestore(userId, csarIds);
167 if (!failedCsarIds.isEmpty()){
168 //There are some failed CSAR IDs, return 500 and the list of failed CSAR IDs
169 Map<String, List<String>> entity = new HashMap<>();
170 entity.put("failedIds", failedCsarIds);
171 return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
175 return Response.ok().build();