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.v3.oas.annotations.Operation;
25 import io.swagger.v3.oas.annotations.media.ArraySchema;
26 import io.swagger.v3.oas.annotations.media.Content;
27 import io.swagger.v3.oas.annotations.media.Schema;
28 import io.swagger.v3.oas.annotations.responses.ApiResponse;
29 import io.swagger.v3.oas.annotations.servers.Server;
30 import io.swagger.v3.oas.annotations.servers.Servers;
31 import io.swagger.v3.oas.annotations.tags.Tag;
32 import io.swagger.v3.oas.annotations.tags.Tags;
33 import org.openecomp.sdc.be.components.impl.ArchiveBusinessLogic;
34 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
35 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
36 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
37 import org.openecomp.sdc.be.impl.ComponentsUtils;
38 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
39 import org.openecomp.sdc.be.user.UserBusinessLogic;
40 import org.openecomp.sdc.common.api.Constants;
41 import org.openecomp.sdc.common.log.elements.LoggerSupportability;
42 import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
43 import org.openecomp.sdc.common.log.enums.StatusCode;
44 import org.springframework.stereotype.Controller;
45 import org.springframework.web.bind.annotation.RequestBody;
47 import javax.inject.Inject;
48 import javax.ws.rs.Consumes;
49 import javax.ws.rs.GET;
50 import javax.ws.rs.HeaderParam;
51 import javax.ws.rs.POST;
52 import javax.ws.rs.Path;
53 import javax.ws.rs.PathParam;
54 import javax.ws.rs.Produces;
55 import javax.ws.rs.core.MediaType;
56 import javax.ws.rs.core.Response;
57 import java.util.HashMap;
58 import java.util.LinkedList;
59 import java.util.List;
63 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
65 @Tags({@Tag(name = "SDC Internal APIs")})
66 @Servers({@Server(url = "/sdc2/rest")})
68 @Consumes(MediaType.APPLICATION_JSON)
69 @Produces(MediaType.APPLICATION_JSON)
70 public class ArchiveEndpoint extends BeGenericServlet{
72 private static final String COMPONENT_ID = "Component ID= ";
73 private final ArchiveBusinessLogic archiveBusinessLogic;
74 private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ArchiveEndpoint.class.getName());
77 public ArchiveEndpoint(UserBusinessLogic userBusinessLogic,
78 ComponentsUtils componentsUtils, ArchiveBusinessLogic archiveBusinessLogic) {
79 super(userBusinessLogic, componentsUtils);
80 this.archiveBusinessLogic = archiveBusinessLogic;
84 @Path("/resources/{componentId}/archive")
85 @Operation(description = "Archive Resource", method = "POST",
86 summary = "Marks a resource as archived. Can be restored with restore action", responses = {
87 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
88 @ApiResponse(responseCode = "200", description = "Archive successful"),
89 @ApiResponse(responseCode = "400", description = "Bad request"),
90 @ApiResponse(responseCode = "403", description = "Restricted operation"),
91 @ApiResponse(responseCode = "404", description = "Resource not found"),
92 @ApiResponse(responseCode = "500", description = "Internal Error")})
93 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
94 public Response archiveResources(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
95 loggerSupportability.log(LoggerSupportabilityActions.ARCHIVE,StatusCode.STARTED,"Archive Resource " + COMPONENT_ID + " " + componentId + " by "+ userId);
96 archiveBusinessLogic.archiveComponent(ComponentTypeEnum.RESOURCE_PARAM_NAME, userId, componentId);
97 loggerSupportability.log(LoggerSupportabilityActions.ARCHIVE,StatusCode.COMPLETE,"Archive Resource " + COMPONENT_ID + " " + componentId + " by "+ userId);
98 return Response.ok().build();
102 @Path("/resources/{componentId}/restore")
103 @Operation(description = "Restore Resource", method = "POST", summary = "Restores a resource from archive.",
104 responses = {@ApiResponse(
105 content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
106 @ApiResponse(responseCode = "200", description = "Restore successful"),
107 @ApiResponse(responseCode = "400", description = "Bad request"),
108 @ApiResponse(responseCode = "403", description = "Restricted operation"),
109 @ApiResponse(responseCode = "404", description = "Resource not found"),
110 @ApiResponse(responseCode = "500", description = "Internal Error")})
111 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
112 public Response restoreResource(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
113 loggerSupportability.log(LoggerSupportabilityActions.RESTORE_FROM_ARCHIVE,StatusCode.STARTED,"Restore resource from archive " + COMPONENT_ID + " " + componentId + " by "+ userId);
114 archiveBusinessLogic.restoreComponent(ComponentTypeEnum.RESOURCE_PARAM_NAME, userId, componentId);
115 loggerSupportability.log(LoggerSupportabilityActions.RESTORE_FROM_ARCHIVE,StatusCode.COMPLETE,"Restore resource from archive " + COMPONENT_ID + " " + componentId + " by "+ userId);
116 return Response.ok().build();
120 @Path("/services/{componentId}/archive")
121 @Operation(description = "Archive Service", method = "POST",
122 summary = "Marks a service as archived. Can be restored with restore action", responses = {
123 @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
124 @ApiResponse(responseCode = "200", description = "Archive successful"),
125 @ApiResponse(responseCode = "400", description = "Bad request"),
126 @ApiResponse(responseCode = "403", description = "Restricted operation"),
127 @ApiResponse(responseCode = "404", description = "Service not found"),
128 @ApiResponse(responseCode = "500", description = "Internal Error")})
129 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
130 public Response archiveService(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
131 loggerSupportability.log(LoggerSupportabilityActions.ARCHIVE, StatusCode.STARTED, "Archive Service for " + COMPONENT_ID + " " + componentId + " by " + userId);
132 archiveBusinessLogic.archiveComponent(ComponentTypeEnum.SERVICE_PARAM_NAME, userId, componentId);
133 loggerSupportability.log(LoggerSupportabilityActions.ARCHIVE,StatusCode.COMPLETE, "Archive Service for " + COMPONENT_ID + " " + componentId + " by " + userId);
134 return Response.ok().build();
139 @Path("/services/{componentId}/restore")
140 @Operation(description = "Restore Service", method = "POST", summary = "Restores a service from archive.",
141 responses = {@ApiResponse(
142 content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
143 @ApiResponse(responseCode = "200", description = "Restore successful"),
144 @ApiResponse(responseCode = "400", description = "Bad request"),
145 @ApiResponse(responseCode = "403", description = "Restricted operation"),
146 @ApiResponse(responseCode = "404", description = "Service not found"),
147 @ApiResponse(responseCode = "500", description = "Internal Error")})
148 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
149 public Response restoreService(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
150 loggerSupportability.log(LoggerSupportabilityActions.RESTORE_FROM_ARCHIVE,StatusCode.STARTED,"Restore service from archive " + COMPONENT_ID + " " + componentId + " by "+ userId);
151 archiveBusinessLogic.restoreComponent(ComponentTypeEnum.SERVICE_PARAM_NAME, userId, componentId);
152 loggerSupportability.log(LoggerSupportabilityActions.RESTORE_FROM_ARCHIVE,StatusCode.COMPLETE,"Restore service from archive " + COMPONENT_ID + " " + componentId + " by "+ userId);
153 return Response.ok().build();
158 @Operation(description = "Get all Archived Components", method = "GET", summary = "Get all Archived Components",
159 responses = {@ApiResponse(
160 content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
161 @ApiResponse(responseCode = "200", description = "Success"),
162 @ApiResponse(responseCode = "400", description = "Bad request"),
163 @ApiResponse(responseCode = "403", description = "Restricted operation"),
164 @ApiResponse(responseCode = "500", description = "Internal Error")})
165 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
166 public Map<String, List<CatalogComponent>> getArchivedComponents(@HeaderParam(value = Constants.USER_ID_HEADER) String userId){
167 return this.archiveBusinessLogic.getArchiveComponents(userId, new LinkedList<>());
171 @Path("/notif/vsp/archived")
173 description = "Notify about an archived VSP. All VFs with relation to the given CSAR IDs will be martked as vspArchived=true",
174 method = "POST", responses = {@ApiResponse(responseCode = "200", description = "Success"),
175 @ApiResponse(responseCode = "400", description = "Bad request"),
176 @ApiResponse(responseCode = "403", description = "Restricted operation"), @ApiResponse(responseCode = "500",
177 description = "Internal Error. A list of the failed CSAR IDs may be returned.")})
178 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
179 public Response onVspArchived(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @RequestBody List<String> csarIds){
180 List<String> failedCsarIds = this.archiveBusinessLogic.onVspArchive(userId, csarIds);
181 if (!failedCsarIds.isEmpty()){
182 //There are some failed CSAR IDs, return 500 and the list of failed CSAR IDs
183 Map<String, List<String>> entity = new HashMap<>();
184 entity.put("failedIds", failedCsarIds);
185 return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
189 return Response.ok().build();
193 @Path("/notif/vsp/restored")
195 description = "Notify about a restored VSP. All VFs with relation to the given CSAR IDs will be martked as vspArchived=false",
196 method = "POST", responses = {@ApiResponse(responseCode = "200", description = "Success"),
197 @ApiResponse(responseCode = "400", description = "Bad request"),
198 @ApiResponse(responseCode = "403", description = "Restricted operation"), @ApiResponse(responseCode = "500",
199 description = "Internal Error. A list of the failed CSAR IDs may be returned.")})
200 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
201 public Response onVspRestored(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @RequestBody List<String> csarIds){
202 List<String> failedCsarIds = this.archiveBusinessLogic.onVspRestore(userId, csarIds);
203 if (!failedCsarIds.isEmpty()){
204 //There are some failed CSAR IDs, return 500 and the list of failed CSAR IDs
205 Map<String, List<String>> entity = new HashMap<>();
206 entity.put("failedIds", failedCsarIds);
207 return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
211 return Response.ok().build();