aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogApp.java43
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdException.java34
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdService.java104
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdServlet.java95
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdUtil.java60
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonConstant.java2
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateDataHelper.java19
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/CapReqMapping.java33
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplate.java2
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/SubstitutionMapping.java27
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java14
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java34
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java40
-rw-r--r--catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java59
-rw-r--r--catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/ServiceTemplateWrapperTest.java4
15 files changed, 477 insertions, 93 deletions
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogApp.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogApp.java
index 6396b545..88e3b16f 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogApp.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogApp.java
@@ -28,6 +28,11 @@ import io.dropwizard.setup.Environment;
import io.swagger.jaxrs.config.BeanConfig;
import io.swagger.jaxrs.listing.ApiListingResource;
+import java.util.EnumSet;
+
+import javax.servlet.DispatcherType;
+
+import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.openo.commontosca.catalog.common.Config;
import org.openo.commontosca.catalog.common.HttpServerAddrConfig;
@@ -110,7 +115,7 @@ public class CatalogApp extends Application<CatalogAppConfiguration> {
environment.jersey().register(MultiPartFeature.class);
initSwaggerConfig(environment, configuration);
- // initCometd(environment);
+ initCometd(environment);
Config.setConfigration(configuration);
initService();
LOGGER.info("Initialize catalogue finished.");
@@ -149,22 +154,22 @@ public class CatalogApp extends Application<CatalogAppConfiguration> {
registerCatalogService.start();
}
-// /**
-// * initialize cometd server.
-// *
-// * @param environment environment information
-// */
-// private void initCometd(Environment environment) {
-// // add filter
-// environment.getApplicationContext().addFilter(CrossOriginFilter.class,
-// "/api/nsoccataloguenotification/v1/*",
-// EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));
-// // add servlet
-// environment.getApplicationContext()
-// .addServlet("org.cometd.server.CometDServlet", "/api/nsoccataloguenotification/v1/*")
-// .setInitOrder(1);
-// // add servlet
-// environment.getApplicationContext()
-// .addServlet("CometdServlet", "/api/nsoccataloguenotification/v1").setInitOrder(2);
-// }
+ /**
+ * initialize cometd server.
+ *
+ * @param environment environment information
+ */
+ private void initCometd(Environment environment) {
+ // add filter
+ environment.getApplicationContext().addFilter(CrossOriginFilter.class,
+ "/openoapi/catalog/v1/catalognotification/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));
+ // add servlet
+ environment.getApplicationContext()
+ .addServlet("org.cometd.server.CometDServlet", "/openoapi/catalog/v1/catalognotification/*")
+ .setInitOrder(1);
+ // add servlet
+ environment.getApplicationContext()
+ .addServlet("org.openo.commontosca.catalog.cometd.CometdServlet", "/openoapi/catalog/v1/catalognotification")
+ .setInitOrder(2);
+ }
}
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdException.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdException.java
new file mode 100644
index 00000000..7237a37b
--- /dev/null
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdException.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright 2016 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.commontosca.catalog.cometd;
+
+public class CometdException extends Exception {
+ public static int ERROR_CODE_BAYEUX = 0;
+ public static int ERROR_CODE_PARAM_ERROR = 1;
+ public static int ERROR_CODE_SESSION_ERROR = 2;
+ public static int ERROR_CODE_SUBSCRIBE_TIMEOUT = 3;
+ private int errorCode = -1;
+
+ public CometdException(Throwable e1) {
+ super(e1);
+ }
+
+ public CometdException(int code, String message) {
+ super(message);
+ this.errorCode = code;
+ }
+}
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdService.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdService.java
new file mode 100644
index 00000000..a54b9abf
--- /dev/null
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdService.java
@@ -0,0 +1,104 @@
+/**
+ * Copyright 2016 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.commontosca.catalog.cometd;
+
+import org.cometd.bayeux.server.BayeuxServer;
+import org.cometd.bayeux.server.ConfigurableServerChannel;
+import org.cometd.bayeux.server.LocalSession;
+import org.cometd.bayeux.server.ServerChannel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+public class CometdService {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CometdService.class);
+ public static String DATA_UPLOAD_CHANNEL = "/upload/data";
+ public static String SNMPTRAP_CHANNEL = "/upload/snmptrap";
+
+ private BayeuxServer bayeux;
+ private LocalSession session;
+
+ private static String bayeuxChannel = "/meta/";
+
+ private static String serviceChannel = "/service/";
+
+ private static CometdService service = new CometdService();
+
+ public static CometdService getInstance() {
+ return service;
+ }
+
+ public void publish(String channel, Object message) throws CometdException {
+ if (bayeux == null) {
+ this.bayeux = CometdUtil.getBayeuxServer();
+ checkBayeuxServer();
+ this.session = this.bayeux.newLocalSession("openo_catalog_local_session~");
+ this.session.handshake();
+ }
+ String jsonMsg;
+ try {
+ // jsonMsg = CometdUtil.convertBean2Json(message);
+ jsonMsg = CometdUtil.toJson(message);
+ LOGGER.debug("upload json=" + jsonMsg);
+ } catch (IOException e) {
+ throw new CometdException(e);
+ }
+
+ checkAndInit(channel);
+ ServerChannel serverChannel = this.bayeux.getChannel(channel);
+ serverChannel.publish(this.session, jsonMsg);
+ }
+
+ private void checkAndInit(String channel) throws CometdException {
+ checkBayeuxServer();
+ checkSession();
+ checkChannel(channel);
+ bayeux.createChannelIfAbsent(channel, new ConfigurableServerChannel.Initializer() {
+ public void configureChannel(ConfigurableServerChannel channel) {
+ channel.setPersistent(true);
+ channel.setLazy(true);
+ }
+ });
+ }
+
+ private void checkBayeuxServer() throws CometdException {
+ if (bayeux == null) {
+ throw new CometdException(CometdException.ERROR_CODE_BAYEUX, "bayeux is null.");
+ }
+ }
+
+ private void checkSession() throws CometdException {
+ if (session == null || !session.isConnected()) {
+ throw new CometdException(CometdException.ERROR_CODE_SESSION_ERROR, "session is invalid.");
+ }
+ }
+
+ private void checkChannel(String channel) throws CometdException {
+ if (channel == null || "".equals(channel)) {
+ throw new CometdException(CometdException.ERROR_CODE_PARAM_ERROR, "channel is null.");
+ }
+ if (channel.startsWith(bayeuxChannel)) {
+ throw new CometdException(CometdException.ERROR_CODE_PARAM_ERROR,
+ "channel [" + channel + "] is bayeuxChannel.");
+ }
+ if (channel.startsWith(serviceChannel)) {
+ throw new CometdException(CometdException.ERROR_CODE_PARAM_ERROR,
+ "channel [" + channel + "] is serviceChannel.");
+ }
+ }
+}
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdServlet.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdServlet.java
new file mode 100644
index 00000000..ace95455
--- /dev/null
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdServlet.java
@@ -0,0 +1,95 @@
+/**
+ * Copyright 2016 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.commontosca.catalog.cometd;
+
+import org.cometd.annotation.Listener;
+import org.cometd.annotation.ServerAnnotationProcessor;
+import org.cometd.annotation.Service;
+import org.cometd.bayeux.Message;
+import org.cometd.bayeux.server.BayeuxServer;
+import org.cometd.bayeux.server.ServerChannel;
+import org.cometd.bayeux.server.ServerMessage;
+import org.cometd.bayeux.server.ServerSession;
+import org.cometd.server.BayeuxServerImpl;
+import org.cometd.server.authorizer.GrantAuthorizer;
+import org.cometd.server.ext.AcknowledgedMessagesExtension;
+import org.cometd.server.ext.TimesyncExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import javax.servlet.GenericServlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.UnavailableException;
+import javax.servlet.http.HttpServletResponse;
+
+
+public class CometdServlet extends GenericServlet {
+ private static final long serialVersionUID = 8807005039926977330L;
+
+ private static final Logger logger = LoggerFactory.getLogger(CometdServlet.class);
+
+ @Override
+ public void init() throws ServletException {
+ super.init();
+
+ final BayeuxServerImpl bayeux =
+ (BayeuxServerImpl) getServletContext().getAttribute(BayeuxServer.ATTRIBUTE);
+ if (bayeux == null) {
+ throw new UnavailableException("No BayeuxServer!");
+ }
+ // Create extensions
+ bayeux.addExtension(new TimesyncExtension());
+ bayeux.addExtension(new AcknowledgedMessagesExtension());
+
+ // Allow anybody to handshake
+ bayeux.getChannel(ServerChannel.META_HANDSHAKE).addAuthorizer(GrantAuthorizer.GRANT_PUBLISH);
+
+ ServerAnnotationProcessor processor = new ServerAnnotationProcessor(bayeux);
+ processor.process(new CatalogComet());
+
+ CometdUtil.setBayeuxServer(bayeux);
+ }
+
+ @Service("catalog")
+ public static class CatalogComet {
+ @Listener("/meta/subscribe")
+ public void catalogSubscribe(ServerSession session, ServerMessage message) {
+ logger.info("Catalog Subscribe from " + session + " for "
+ + message.get(Message.SUBSCRIPTION_FIELD));
+ }
+
+ @Listener("/meta/unsubscribe")
+ public void catalogUnsubscribe(ServerSession session, ServerMessage message) {
+ logger.info("Catalog Unsubscribe from " + session + " for "
+ + message.get(Message.SUBSCRIPTION_FIELD));
+ }
+
+ @Listener("/meta/*")
+ public void catalogMeta(ServerSession session, ServerMessage message) {
+ logger.debug(message.toString());
+ }
+ }
+
+ @Override
+ public void service(ServletRequest servletRequest, ServletResponse servletResponse)
+ throws ServletException, IOException {
+ ((HttpServletResponse) servletResponse).sendError(503);
+ }
+}
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdUtil.java
new file mode 100644
index 00000000..efb2d35d
--- /dev/null
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdUtil.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2016 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openo.commontosca.catalog.cometd;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.cometd.server.BayeuxServerImpl;
+
+import com.google.gson.Gson;
+
+public class CometdUtil {
+ private static BayeuxServerImpl bayeuxServer = null;
+
+ public static BayeuxServerImpl getBayeuxServer() {
+ return bayeuxServer;
+ }
+
+ public static void setBayeuxServer(BayeuxServerImpl bayeux) {
+ bayeuxServer = bayeux;
+ }
+
+// public static String convertBean2Json(Object object) throws IOException {
+// ObjectMapper mapper = new ObjectMapper();
+// return mapper.writeValueAsString(object);
+// }
+//
+// public static Map convertJson2Map(String jsonStr) throws IOException {
+// ObjectMapper objectMapper = new ObjectMapper();
+// return objectMapper.readValue(jsonStr, Map.class);
+// }
+ public static <T> T fromJson(String jsonString, Class<T> templateClass) throws IOException {
+ Gson gson = new Gson();
+ return gson.fromJson(jsonString, templateClass);
+ }
+
+ /**
+ * gson to json.
+ * @param template class name
+ * @return String
+ */
+ public static <T> String toJson(T template) throws IOException {
+ Gson gson = new Gson();
+ return gson.toJson(template);
+ }
+}
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonConstant.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonConstant.java
index a2d57527..8250c94f 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonConstant.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonConstant.java
@@ -45,4 +45,6 @@ public class CommonConstant {
public static final String HTTP_HEADER_CONTENT_RANGE = "Content-Range";
public static final String CATALOG_CSAR_DIR_NAME = "/csar";
+
+ public static final String COMETD_CHANNEL_PACKAGE_DELETE = "/package/delete";
}
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateDataHelper.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateDataHelper.java
index 6c591f1c..a26a32bc 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateDataHelper.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateDataHelper.java
@@ -21,6 +21,7 @@ import org.openo.commontosca.catalog.db.entity.ServiceTemplateData;
import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData;
import org.openo.commontosca.catalog.db.entity.TemplateData;
import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
+import org.openo.commontosca.catalog.db.resource.TemplateManager;
import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse;
import org.openo.commontosca.catalog.model.entity.NodeTemplate;
import org.openo.commontosca.catalog.model.entity.Parameters;
@@ -68,6 +69,7 @@ public class TemplateDataHelper {
String rawData) {
ServiceTemplateData std = new ServiceTemplateData();
std.setServiceTemplateId(st.getServiceTemplateId());
+ std.setServiceTemplateOriginalId(st.getId());
std.setTemplateName(st.getTemplateName());
std.setVendor(st.getVendor());
std.setVersion(st.getVersion());
@@ -146,9 +148,22 @@ public class TemplateDataHelper {
ToolUtil.fromJson(std.getOperations(), ServiceTemplateOperation[].class);
String downloadUri = buildSTDownloadUri(std.getCsarId(), std.getDownloadUri());
- return new ServiceTemplate(std.getServiceTemplateId(), std.getTemplateName(), std.getTemplateName(), std.getVendor(),
+ return new ServiceTemplate(std.getServiceTemplateId(), std.getServiceTemplateOriginalId(),
+ std.getTemplateName(), std.getVendor(),
std.getVersion(), std.getCsarId(), std.getType(), downloadUri,
- parameters.getInputs(), parameters.getOutputs(), operations);
+ parameters.getInputs(), parameters.getOutputs(), operations,
+ getSubstitutionMappingsByServiceTemplateId(std.getServiceTemplateId()));
+ }
+
+ private static SubstitutionMapping getSubstitutionMappingsByServiceTemplateId(String serviceTemplateId)
+ throws CatalogResourceException {
+ List<ServiceTemplateMappingData> stmDataList =
+ TemplateManager.getInstance().queryServiceTemplateMapping(null, serviceTemplateId);
+ if (stmDataList == null || stmDataList.isEmpty()) {
+ return null;
+ }
+
+ return convert2SubstitutionMapping(stmDataList.get(0));
}
private static String buildSTDownloadUri(String packageId, String stFileName)
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/CapReqMapping.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/CapReqMapping.java
new file mode 100644
index 00000000..6afbd492
--- /dev/null
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/CapReqMapping.java
@@ -0,0 +1,33 @@
+/**
+ * Copyright 2016 [ZTE] and others.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openo.commontosca.catalog.model.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author 10090474
+ *
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CapReqMapping {
+ private String mapped_name;
+ private String node_id;
+ private String name;
+}
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplate.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplate.java
index cbc75667..6f5dfb3a 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplate.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplate.java
@@ -46,4 +46,6 @@ public class ServiceTemplate {
private ServiceTemplateOperation[] operations;
+ private SubstitutionMapping substitution;
+
}
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/SubstitutionMapping.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/SubstitutionMapping.java
index cadbb34a..2f34a4a9 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/SubstitutionMapping.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/SubstitutionMapping.java
@@ -15,9 +15,6 @@
*/
package org.openo.commontosca.catalog.model.entity;
-import java.util.HashMap;
-import java.util.Map;
-
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -32,28 +29,8 @@ public class SubstitutionMapping {
@JsonIgnore
private String serviceTemplateId;
private String nodeType;
- private Map<String, String[]> requirements = new HashMap<String, String[]>();
- private Map<String, String[]> capabilities = new HashMap<String, String[]>();
-
- /**
- * put requirement.
- * @param key key
- * @param value value
- * @return string list
- */
- public String[] putRequirement(String key, String[] value) {
- return this.requirements.put(key, value);
- }
-
- /**
- * put capability.
- * @param key key
- * @param value value
- * @return string list
- */
- public String[] putCapability(String key, String[] value) {
- return this.capabilities.put(key, value);
- }
+ private CapReqMapping[] requirements;
+ private CapReqMapping[] capabilities;
/**
* substitution mapping.
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java
index fb556543..76cc97a0 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java
@@ -213,17 +213,27 @@ public abstract class AbstractModelParser {
return retList.toArray(new InputParameter[0]);
}
-
/**
* @param metadata
* @return
*/
- public String parserServiceTemplateName(Map<String, String> metadata) {
+ public String parserId(Map<String, String> metadata) {
if (metadata.containsKey("id")) {
return metadata.get("id");
}
return metadata.get("template_name");
}
+
+ /**
+ * @param metadata
+ * @return
+ */
+ public String parserServiceTemplateName(Map<String, String> metadata) {
+ if (metadata.containsKey("name")) {
+ return metadata.get("name");
+ }
+ return metadata.get("template_name");
+ }
/**
* @param metadata
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java
index fd2b3507..5145d647 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java
@@ -16,7 +16,6 @@
package org.openo.commontosca.catalog.model.parser.yaml.aria;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -26,6 +25,7 @@ import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
import org.openo.commontosca.catalog.db.resource.TemplateManager;
import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse;
import org.openo.commontosca.catalog.model.common.TemplateDataHelper;
+import org.openo.commontosca.catalog.model.entity.CapReqMapping;
import org.openo.commontosca.catalog.model.entity.InputParameter;
import org.openo.commontosca.catalog.model.entity.NodeTemplate;
import org.openo.commontosca.catalog.model.entity.OutputParameter;
@@ -111,30 +111,30 @@ public class AriaModelParser extends AbstractModelParser {
* @param capabilities
* @return
*/
- private Map<String, String[]> parseSubstitutionCapabilities(Mapping[] capabilities) {
+ private CapReqMapping[] parseSubstitutionCapabilities(Mapping[] capabilities) {
return parseMappings(capabilities);
}
-
-
- private Map<String, String[]> parseMappings(Mapping[] mappings) {
- Map<String, String[]> ret = new HashMap<>();
- if (mappings != null) {
- for (Mapping mapping : mappings) {
- ret.put(mapping.getMapped_name(), new String[]{mapping.getNode_id(), mapping.getName()});
- }
- }
-
- return ret;
- }
-
+
/**
* @param requirement
* @return
*/
- private Map<String, String[]> parseSubstitutionRequirements(Mapping[] requirement) {
+ private CapReqMapping[] parseSubstitutionRequirements(Mapping[] requirement) {
return parseMappings(requirement);
}
+ private CapReqMapping[] parseMappings(Mapping[] mappings) {
+ List<CapReqMapping> ret = new ArrayList<>();
+ if (mappings != null) {
+ for (Mapping mapping : mappings) {
+ ret.add(new CapReqMapping(
+ mapping.getMapped_name(), mapping.getNode_id(), mapping.getName()));
+ }
+ }
+
+ return ret.toArray(new CapReqMapping[0]);
+ }
+
/**
* @param result
* @return
@@ -243,7 +243,7 @@ public class AriaModelParser extends AbstractModelParser {
ServiceTemplate st = new ServiceTemplate();
st.setServiceTemplateId(ToolUtil.generateId());
- st.setId(parserServiceTemplateName(result.getInstance().getMetadata())); // TODO
+ st.setId(parserId(result.getInstance().getMetadata()));
st.setTemplateName(parserServiceTemplateName(result.getInstance().getMetadata()));
st.setVendor(parserServiceTemplateVendor(result.getInstance().getMetadata()));
st.setVersion(parserServiceTemplateVersion(result.getInstance().getMetadata()));
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java
index 4a50b02d..b02a6b23 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java
@@ -18,11 +18,14 @@ package org.openo.commontosca.catalog.model.parser.yaml.zte;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import org.openo.commontosca.catalog.common.ToolUtil;
import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
import org.openo.commontosca.catalog.db.resource.TemplateManager;
import org.openo.commontosca.catalog.model.common.TemplateDataHelper;
+import org.openo.commontosca.catalog.model.entity.CapReqMapping;
import org.openo.commontosca.catalog.model.entity.InputParameter;
import org.openo.commontosca.catalog.model.entity.NodeTemplate;
import org.openo.commontosca.catalog.model.entity.OutputParameter;
@@ -99,8 +102,39 @@ public class ToscaYamlModelParser extends AbstractModelParser {
org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlResult
.TopologyTemplate.SubstitutionMapping stm =
result.getTopologyTemplate().getSubstitutionMappings();
- return new SubstitutionMapping(serviceTemplateId, type, stm.getRequirementList(),
- stm.getCapabilityList());
+ return new SubstitutionMapping(
+ serviceTemplateId, type,
+ parseSubstitutionRequirements(stm.getRequirementList()),
+ parseSubstitutionCapabilities(stm.getCapabilityList()));
+ }
+
+ /**
+ * @param requirementList
+ * @return
+ */
+ private CapReqMapping[] parseSubstitutionRequirements(Map<String, String[]> requirementList) {
+ return parseMappings(requirementList);
+ }
+
+ /**
+ * @param capabilityList
+ * @return
+ */
+ private CapReqMapping[] parseSubstitutionCapabilities(Map<String, String[]> capabilityList) {
+ return parseMappings(capabilityList);
+ }
+
+ private CapReqMapping[] parseMappings(Map<String, String[]> mappings) {
+ List<CapReqMapping> ret = new ArrayList<>();
+ if (mappings != null) {
+ for (Entry<String, String[]> mapping : mappings.entrySet()) {
+ if (mapping.getValue().length >= 2) {
+ ret.add(new CapReqMapping(
+ mapping.getKey(), mapping.getValue()[0], mapping.getValue()[1]));
+ }
+ }
+ }
+ return ret.toArray(new CapReqMapping[0]);
}
private ServiceTemplate parseServiceTemplate(ParseYamlResult result, String packageId,
@@ -108,7 +142,7 @@ public class ToscaYamlModelParser extends AbstractModelParser {
ServiceTemplate st = new ServiceTemplate();
st.setServiceTemplateId(ToolUtil.generateId());
- st.setId(parserServiceTemplateName(result.getMetadata())); // TODO
+ st.setId(parserId(result.getMetadata()));
st.setTemplateName(parserServiceTemplateName(result.getMetadata()));
st.setVendor(parserServiceTemplateVendor(result.getMetadata()));
st.setVersion(parserServiceTemplateVersion(result.getMetadata()));
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java
index 8a882533..247446ff 100644
--- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java
+++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java
@@ -16,6 +16,9 @@
package org.openo.commontosca.catalog.wrapper;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.openo.commontosca.catalog.cometd.CometdException;
+import org.openo.commontosca.catalog.cometd.CometdService;
+import org.openo.commontosca.catalog.cometd.CometdUtil;
import org.openo.commontosca.catalog.common.CommonConstant;
import org.openo.commontosca.catalog.common.HttpServerPathConfig;
import org.openo.commontosca.catalog.common.RestUtil;
@@ -42,6 +45,8 @@ import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
@@ -197,6 +202,18 @@ public class PackageWrapper {
}
}
+ private void publishDeletionPendingStatusCometdMessage(String csarid) {
+ try {
+ Map<String, Object> cometdMessage = new HashMap<String, Object>();
+ cometdMessage.put("csarid", csarid);
+ cometdMessage.put("status", "deletionPending");
+ CometdService.getInstance().publish(CommonConstant.COMETD_CHANNEL_PACKAGE_DELETE,
+ cometdMessage);
+ } catch (CometdException e1) {
+ LOG.error("publish delfinish cometdmsg fail.", e1);
+ }
+ }
+
class DelCsarThread implements Runnable {
private String csarid;
private boolean isInstanceTemplate = false;
@@ -216,12 +233,12 @@ public class PackageWrapper {
LOG.error("del instance csar fail."+ e1.getMessage());
updatePackageStatus(csarid, null, null, null, CommonConstant.PACKAGE_STATUS_DELETE_FAIL,
null);
- // publishDelFinishCometdMessage(csarid, "false");
+ publishDelFinishCometdMessage(csarid, "false");
}
}
private void delCsarData(String csarId) {
- updatePackageStatus(csarid, null, null, null, CommonConstant.PACKAGE_STATUS_DELETING, null);
+ updatePackageStatus(csarId, null, null, null, CommonConstant.PACKAGE_STATUS_DELETING, null);
String packagePath = PackageWrapperUtil.getPackagePath(csarId);
if (packagePath == null) {
LOG.error("package path is null! ");
@@ -236,36 +253,30 @@ public class PackageWrapper {
} catch (CatalogResourceException e) {
LOG.error("delete template data from db error! csarId = " + csarId, e);
}
-// PackageData packageData = new PackageData();
-// packageData.setCsarId(csarId);
-// try {
-// TemplateManager.getInstance().deleteServiceTemplateByCsarPackageInfo(packageData);
-// } catch (CatalogResourceException e2) {
-// LOG.error("delete template data from db error! csarId = " + csarId);
-// }
//delete package data from database
try {
PackageManager.getInstance().deletePackage(csarId);
} catch (CatalogResourceException e1) {
LOG.error("delete package by csarId from db error ! " + e1.getMessage(), e1);
}
+ publishDelFinishCometdMessage(csarId, "true");
}
- // private void publishDelFinishCometdMessage(String csarid, String csarDelStatus) {
- // if (isInstanceTemplate) {
- // LOG.info("delete instance Template finish. csarid:{}", csarid);
- // return;
- // }
- // try {
- // Map<String, Object> cometdMessage = new HashMap<String, Object>();
- // cometdMessage.put("csarid", csarid);
- // cometdMessage.put("status", csarDelStatus);
- // CometdService.getInstance().publish(CommonConstant.COMETD_CHANNEL_PACKAGE_DELETE,
- // cometdMessage);
- // } catch (CometdException e) {
- // LOG.error("publish delfinish cometdmsg fail.", e);
- // }
- // }
+ private void publishDelFinishCometdMessage(String csarId, String csarDelStatus) {
+ if (isInstanceTemplate) {
+ LOG.info("delete instance Template finish. csarid:{}", csarId);
+ return;
+ }
+ try {
+ Map<String, Object> cometdMessage = new HashMap<String, Object>();
+ cometdMessage.put("csarid", csarId);
+ cometdMessage.put("status", csarDelStatus);
+ CometdService.getInstance().publish(CommonConstant.COMETD_CHANNEL_PACKAGE_DELETE,
+ cometdMessage);
+ } catch (CometdException e1) {
+ LOG.error("publish delfinish cometdmsg fail." + e1.getMessage(), e1);
+ }
+ }
}
/**
diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/ServiceTemplateWrapperTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/ServiceTemplateWrapperTest.java
index 8a9bf745..76af3744 100644
--- a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/ServiceTemplateWrapperTest.java
+++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/ServiceTemplateWrapperTest.java
@@ -55,6 +55,7 @@ import org.openo.commontosca.catalog.model.entity.RelationShip;
import org.openo.commontosca.catalog.model.entity.ServiceTemplate;
import org.openo.commontosca.catalog.model.entity.ServiceTemplateOperation;
import org.openo.commontosca.catalog.model.entity.ServiceTemplateRawData;
+import org.openo.commontosca.catalog.model.entity.SubstitutionMapping;
import org.openo.commontosca.catalog.model.wrapper.ServiceTemplateWrapper;
import java.util.ArrayList;
@@ -370,11 +371,12 @@ public class ServiceTemplateWrapperTest {
OutputParameter[] outputs = getOutputs();
serviceTemplate.setOutputs(outputs);
serviceTemplate.setServiceTemplateId("serviceTemplateId");
- serviceTemplate.setId("templateName");
serviceTemplate.setTemplateName("templateName");
serviceTemplate.setType("NS");
serviceTemplate.setVendor("ZTE");
serviceTemplate.setVersion("0.0.1");
+ serviceTemplate.setSubstitution(
+ new SubstitutionMapping("serviceTemplateId", "tosca.nodes.nfv.VL"));
return serviceTemplate;
}