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 org.openecomp.sdc.be.components.impl.ArchiveBusinessLogic;
29 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
30 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
31 import org.openecomp.sdc.common.api.Constants;
32 import org.springframework.stereotype.Controller;
33 import org.springframework.web.bind.annotation.RequestBody;
36 import javax.ws.rs.core.MediaType;
37 import javax.ws.rs.core.Response;
38 import java.util.HashMap;
39 import java.util.LinkedList;
40 import java.util.List;
44 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
46 @Api(value = "Archive Endpoint")
48 @Consumes(MediaType.APPLICATION_JSON)
49 @Produces(MediaType.APPLICATION_JSON)
50 public class ArchiveEndpoint {
52 private final ArchiveBusinessLogic archiveBusinessLogic;
54 public ArchiveEndpoint(ArchiveBusinessLogic archiveBusinessLogic) {
55 this.archiveBusinessLogic = archiveBusinessLogic;
59 @Path("/resources/{componentId}/archive")
60 @ApiOperation(value = "Archive Resource", httpMethod = "POST", notes = "Marks a resource as archived. Can be restored with restore action", response = String.class, responseContainer = "")
61 @ApiResponses(value = {
62 @ApiResponse(code = 200, message = "Archive successful"),
63 @ApiResponse(code = 400, message = "Bad request"),
64 @ApiResponse(code = 403, message = "Restricted operation"),
65 @ApiResponse(code = 404, message = "Resource not found"),
66 @ApiResponse(code = 500, message = "Internal Error")
68 public Response archiveResources(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
69 archiveBusinessLogic.archiveComponent(ComponentTypeEnum.RESOURCE_PARAM_NAME, userId, componentId);
70 return Response.ok().build();
74 @Path("/resources/{componentId}/restore")
75 @ApiOperation(value = "Restore Resource", httpMethod = "POST", notes = "Restores a resource from archive.", response = String.class, responseContainer = "")
76 @ApiResponses(value = {
77 @ApiResponse(code = 200, message = "Restore successful"),
78 @ApiResponse(code = 400, message = "Bad request"),
79 @ApiResponse(code = 403, message = "Restricted operation"),
80 @ApiResponse(code = 404, message = "Resource not found"),
81 @ApiResponse(code = 500, message = "Internal Error")
83 public Response restoreResource(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
84 archiveBusinessLogic.restoreComponent(ComponentTypeEnum.RESOURCE_PARAM_NAME, userId, componentId);
85 return Response.ok().build();
89 @Path("/services/{componentId}/archive")
90 @ApiOperation(value = "Archive Service", httpMethod = "POST", notes = "Marks a service as archived. Can be restored with restore action", response = String.class, responseContainer = "")
91 @ApiResponses(value = {
92 @ApiResponse(code = 200, message = "Archive successful"),
93 @ApiResponse(code = 400, message = "Bad request"),
94 @ApiResponse(code = 403, message = "Restricted operation"),
95 @ApiResponse(code = 404, message = "Service not found"),
96 @ApiResponse(code = 500, message = "Internal Error")
98 public Response archiveService(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
99 archiveBusinessLogic.archiveComponent(ComponentTypeEnum.SERVICE_PARAM_NAME, userId, componentId);
100 return Response.ok().build();
105 @Path("/services/{componentId}/restore")
106 @ApiOperation(value = "Restore Service", httpMethod = "POST", notes = "Restores a service from archive.", response = String.class, responseContainer = "")
107 @ApiResponses(value = {
108 @ApiResponse(code = 200, message = "Restore successful"),
109 @ApiResponse(code = 400, message = "Bad request"),
110 @ApiResponse(code = 403, message = "Restricted operation"),
111 @ApiResponse(code = 404, message = "Service not found"),
112 @ApiResponse(code = 500, message = "Internal Error")
114 public Response restoreService(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
115 archiveBusinessLogic.restoreComponent(ComponentTypeEnum.SERVICE_PARAM_NAME, userId, componentId);
116 return Response.ok().build();
121 @ApiOperation(value = "Get all Archived Components", httpMethod = "GET", notes = "Get all Archived Components", response = String.class, responseContainer = "")
122 @ApiResponses(value = {
123 @ApiResponse(code = 200, message = "Success"),
124 @ApiResponse(code = 400, message = "Bad request"),
125 @ApiResponse(code = 403, message = "Restricted operation"),
126 @ApiResponse(code = 500, message = "Internal Error")
128 public Map<String, List<CatalogComponent>> getArchivedComponents(@HeaderParam(value = Constants.USER_ID_HEADER) String userId){
129 return this.archiveBusinessLogic.getArchiveComponents(userId, new LinkedList<>());
133 @Path("/notif/vsp/archived")
134 @ApiOperation(value = "Notify about an archived VSP. All VFs with relation to the given CSAR IDs will be martked as vspArchived=true", httpMethod = "POST")
135 @ApiResponses(value = {
136 @ApiResponse(code = 200, message = "Success"),
137 @ApiResponse(code = 400, message = "Bad request"),
138 @ApiResponse(code = 403, message = "Restricted operation"),
139 @ApiResponse(code = 500, message = "Internal Error. A list of the failed CSAR IDs may be returned.")
141 public Response onVspArchived(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @RequestBody List<String> csarIds){
142 List<String> failedCsarIds = this.archiveBusinessLogic.onVspArchive(userId, csarIds);
143 if (!failedCsarIds.isEmpty()){
144 //There are some failed CSAR IDs, return 500 and the list of failed CSAR IDs
145 Map<String, List<String>> entity = new HashMap<>();
146 entity.put("failedIds", failedCsarIds);
147 return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
151 return Response.ok().build();
155 @Path("/notif/vsp/restored")
156 @ApiOperation(value = "Notify about a restored VSP. All VFs with relation to the given CSAR IDs will be martked as vspArchived=false", httpMethod = "POST")
157 @ApiResponses(value = {
158 @ApiResponse(code = 200, message = "Success"),
159 @ApiResponse(code = 400, message = "Bad request"),
160 @ApiResponse(code = 403, message = "Restricted operation"),
161 @ApiResponse(code = 500, message = "Internal Error. A list of the failed CSAR IDs may be returned.")
163 public Response onVspRestored(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @RequestBody List<String> csarIds){
164 List<String> failedCsarIds = this.archiveBusinessLogic.onVspRestore(userId, csarIds);
165 if (!failedCsarIds.isEmpty()){
166 //There are some failed CSAR IDs, return 500 and the list of failed CSAR IDs
167 Map<String, List<String>> entity = new HashMap<>();
168 entity.put("failedIds", failedCsarIds);
169 return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
173 return Response.ok().build();