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.jcabi.aspects.Loggable;
24 import javax.inject.Inject;
25 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
26 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
27 import org.openecomp.sdc.be.impl.ComponentsUtils;
28 import org.openecomp.sdc.be.impl.DownloadArtifactLogic;
29 import org.openecomp.sdc.be.resources.api.IResourceUploader;
30 import org.openecomp.sdc.be.resources.data.ESArtifactData;
31 import org.openecomp.sdc.be.user.UserBusinessLogic;
32 import org.openecomp.sdc.common.log.wrappers.Logger;
34 import javax.servlet.http.HttpServletRequest;
35 import javax.ws.rs.GET;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.PathParam;
38 import javax.ws.rs.core.Context;
39 import javax.ws.rs.core.Response;
41 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
43 public class CsarBuildServlet extends ToscaDaoServlet {
45 private static final Logger log = Logger.getLogger(CsarBuildServlet.class);
48 public CsarBuildServlet(UserBusinessLogic userBusinessLogic,
49 ComponentsUtils componentsUtils,
50 IResourceUploader resourceUploader,
51 DownloadArtifactLogic logic) {
52 super(userBusinessLogic, componentsUtils, resourceUploader, logic);
56 @Path("/{serviceName}/{serviceVersion}")
57 public Response getDefaultTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) {
59 return null;// buildToscaCsar(request, serviceName, serviceVersion);
64 @Path("/{serviceName}/{serviceVersion}/csar")
65 public Response getToscaCsarTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) {
67 return null; // buildToscaCsar(request, serviceName, serviceVersion);
72 public static final String TOSCA_META_PATH = "TOSCA-Metadata/TOSCA.meta";
74 protected String[] prepareToscaMetaHeader(String serviceName) {
75 return new String[] { "TOSCA-Meta-File-Version: 1.0\n", "CSAR-Version: 1.1\n", "Created-By: INTERWISE\n", "\n", "Entry-Definitions: Definitions/" + serviceName + ".yaml\n", "\n", "Name: Definitions/" + serviceName + ".yaml\n",
76 "Content-Type: application/vnd.oasis.tosca.definitions.yaml\n" };
79 protected String getAppliactionMime(String fileName) {
81 if (fileName.contains(".sh")) {
83 } else if (fileName.contains(".yang")) {
87 else if (fileName.contains(".rar")) {
88 mimeType = "x-rar-compressed";
91 else if (fileName.contains(".zip")) {
95 else if (fileName.contains(".tar")) {
99 else if (fileName.contains(".7z")) {
100 mimeType = "x-7z-compressed";
105 mimeType = "undefined";
110 protected String getArtifactPath(String nodeTamplateName, ESArtifactData artifactData) {
111 return "Scripts/" + nodeTamplateName + "/" + artifactData.getId();
114 protected String getResourcePath(String resourceName) {
115 return "Definitions/" + resourceName + ".yaml";
119 public Logger getLogger() {