environment.jersey().register(MultiPartFeature.class);\r
\r
initSwaggerConfig(environment, configuration);\r
- initCometd(environment);\r
+// initCometd(environment);\r
Config.setConfigration(configuration);\r
initService();\r
LOGGER.info("Initialize catalogue finished.");\r
* \r
* @param environment environment information\r
*/\r
- private void initCometd(Environment environment) {\r
- // add filter\r
- environment.getApplicationContext().addFilter(CrossOriginFilter.class,\r
- "/api/nsoccataloguenotification/v1/*",\r
- EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));\r
- // add servlet\r
- environment.getApplicationContext()\r
- .addServlet("org.cometd.server.CometDServlet", "/api/nsoccataloguenotification/v1/*")\r
- .setInitOrder(1);\r
- // add servlet\r
- environment.getApplicationContext()\r
- .addServlet("CometdServlet", "/api/nsoccataloguenotification/v1").setInitOrder(2);\r
- }\r
+// private void initCometd(Environment environment) {\r
+// // add filter\r
+// environment.getApplicationContext().addFilter(CrossOriginFilter.class,\r
+// "/api/nsoccataloguenotification/v1/*",\r
+// EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));\r
+// // add servlet\r
+// environment.getApplicationContext()\r
+// .addServlet("org.cometd.server.CometDServlet", "/api/nsoccataloguenotification/v1/*")\r
+// .setInitOrder(1);\r
+// // add servlet\r
+// environment.getApplicationContext()\r
+// .addServlet("CometdServlet", "/api/nsoccataloguenotification/v1").setInitOrder(2);\r
+// }\r
}\r
+++ /dev/null
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.cometd;\r
-\r
-\r
-public class CometdException extends Exception {\r
- private static final long serialVersionUID = 497640895744777904L;\r
-\r
- public static final int ERROR_CODE_BAYEUX = 0;\r
- public static final int ERROR_CODE_PRARM_ERROR = 1;\r
- public static final int ERROR_CODE_SESSION_ERROR = 2;\r
- public static final int ERROR_CODE_SUBSCRIBE_TIMEOUT = 3;\r
-\r
- private int errorCode = -1;\r
-\r
- public CometdException(String message) {\r
- super(message);\r
- }\r
-\r
- public CometdException(Throwable e1) {\r
- super(e1);\r
- }\r
-\r
- public CometdException(int code, String message) {\r
- super(message);\r
- this.errorCode = code;\r
- }\r
-\r
- public int getErrorCode() {\r
- return this.errorCode;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String str = getClass().getName();\r
- String message = getLocalizedMessage();\r
- message = (message != null) ? (str + ": " + message) : str;\r
- return "errorcode: " + this.errorCode + ";" + message;\r
- }\r
-}\r
+++ /dev/null
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.cometd;\r
-\r
-import org.cometd.bayeux.server.BayeuxServer;\r
-import org.cometd.bayeux.server.ConfigurableServerChannel;\r
-import org.cometd.bayeux.server.LocalSession;\r
-import org.cometd.bayeux.server.ServerChannel;\r
-\r
-import java.io.IOException;\r
-\r
-public class CometdService {\r
- private BayeuxServer bayeux;\r
- private LocalSession session;\r
-\r
- /**\r
- * meta channel.\r
- */\r
- private static final String bayeuxChannel = "/meta/";\r
-\r
- /**\r
- * service channel.\r
- */\r
- private static final String serviceChannel = "/service/";\r
-\r
- private static CometdService cometdService = null;\r
-\r
- /**\r
- * get cometd service instance.\r
- * \r
- * @return cometdService\r
- */\r
- public static CometdService getInstance() {\r
- if (cometdService == null) {\r
- cometdService = new CometdService();\r
- }\r
- return cometdService;\r
- }\r
-\r
- /**\r
- * publish commetd.\r
- * @param channel commetd channel\r
- * @param message message to commet\r
- * @throws CometdException e1\r
- */\r
- public void publish(String channel, Object message) throws CometdException {\r
- if (bayeux == null) {\r
- this.bayeux = CometdUtil.getBayeuxServer();\r
- checkBayeuxServer();\r
- this.session = this.bayeux.newLocalSession("openo_catalogue_local_session");\r
- this.session.handshake();\r
- }\r
- String jsonMsg;\r
- try {\r
- jsonMsg = CometdUtil.convertBean2Json(message);\r
- } catch (IOException e1) {\r
- throw new CometdException(e1);\r
- }\r
-\r
- checkAndInit(channel);\r
- ServerChannel serverChannel = this.bayeux.getChannel(channel);\r
- serverChannel.publish(this.session, jsonMsg);\r
- }\r
-\r
- private void checkBayeuxServer() throws CometdException {\r
- if (this.bayeux == null) {\r
- throw new CometdException(CometdException.ERROR_CODE_BAYEUX, "bayeux is null.");\r
- }\r
- }\r
-\r
- private void checkAndInit(String channel) throws CometdException {\r
- checkBayeuxServer();\r
- checkSession();\r
- checkChannel(channel);\r
- bayeux.createChannelIfAbsent(channel, new ConfigurableServerChannel.Initializer() {\r
- @Override\r
- public void configureChannel(ConfigurableServerChannel channel) {\r
- channel.setPersistent(true);\r
- channel.setLazy(true);\r
- }\r
- });\r
- }\r
-\r
- private void checkSession() throws CometdException {\r
- if (session == null || !session.isConnected()) {\r
- throw new CometdException(CometdException.ERROR_CODE_SESSION_ERROR, "session is invalid.");\r
- }\r
- }\r
-\r
- private void checkChannel(String channel) throws CometdException {\r
- if (channel == null || "".equals(channel)) {\r
- throw new CometdException(CometdException.ERROR_CODE_PRARM_ERROR, "channel is null.");\r
- }\r
- if (channel.startsWith(bayeuxChannel)) {\r
- throw new CometdException(CometdException.ERROR_CODE_PRARM_ERROR, "channel [" + channel\r
- + "] is bayeuxChannel.");\r
- }\r
- if (channel.startsWith(serviceChannel)) {\r
- throw new CometdException(CometdException.ERROR_CODE_PRARM_ERROR, "channel [" + channel\r
- + "] is serviceChannel.");\r
- }\r
- }\r
-}\r
+++ /dev/null
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.cometd;\r
-\r
-import org.cometd.annotation.Listener;\r
-import org.cometd.annotation.ServerAnnotationProcessor;\r
-import org.cometd.annotation.Service;\r
-import org.cometd.bayeux.Message;\r
-import org.cometd.bayeux.server.BayeuxServer;\r
-import org.cometd.bayeux.server.ServerChannel;\r
-import org.cometd.bayeux.server.ServerMessage;\r
-import org.cometd.bayeux.server.ServerSession;\r
-import org.cometd.server.authorizer.GrantAuthorizer;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.io.IOException;\r
-\r
-import javax.servlet.GenericServlet;\r
-import javax.servlet.ServletException;\r
-import javax.servlet.ServletRequest;\r
-import javax.servlet.ServletResponse;\r
-import javax.servlet.UnavailableException;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-\r
-\r
-public class CometdServlet extends GenericServlet {\r
-\r
- private static final long serialVersionUID = 1L;\r
-\r
- private static final Logger logger = LoggerFactory.getLogger(CometdServlet.class);\r
-\r
- @Override\r
- public void init() throws ServletException {\r
- super.init();\r
-\r
- final BayeuxServer bayeux =\r
- (BayeuxServer) getServletContext().getAttribute(BayeuxServer.ATTRIBUTE);\r
- if (bayeux == null) {\r
- throw new UnavailableException("No BayeuxServer!");\r
- }\r
-\r
- // Allow anybody to handshake\r
- bayeux.getChannel(ServerChannel.META_HANDSHAKE).addAuthorizer(GrantAuthorizer.GRANT_PUBLISH);\r
-\r
- // start server processor\r
- ServerAnnotationProcessor processor = new ServerAnnotationProcessor(bayeux);\r
- processor.process(new Monitor());\r
-\r
- CometdUtil.setBayeuxServer(bayeux);\r
- }\r
-\r
- @Override\r
- public void service(ServletRequest paramServletRequest, ServletResponse paramServletResponse)\r
- throws ServletException, IOException {\r
- ((HttpServletResponse) paramServletResponse).sendError(503);\r
- }\r
-\r
- @Service("monitor")\r
- public static class Monitor {\r
- @Listener("/meta/subscribe")\r
- public void monitorSubscribe(ServerSession session, ServerMessage message) {\r
- logger.info("Monitored subscribe from " + session + " for "\r
- + message.get(Message.SUBSCRIPTION_FIELD));\r
- }\r
-\r
- @Listener("/meta/unsubscribe")\r
- public void monitorUnsubscribe(ServerSession session, ServerMessage message) {\r
- logger.info("Monitored unsubscribe from " + session + " for "\r
- + message.get(Message.SUBSCRIPTION_FIELD));\r
- }\r
-\r
- @Listener("/meta/*")\r
- public void monitorMeta(ServerSession session, ServerMessage message) {\r
- logger.debug(message.toString());\r
- }\r
- }\r
-}\r
+++ /dev/null
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.cometd;\r
-\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
-import org.cometd.bayeux.server.BayeuxServer;\r
-\r
-import java.io.IOException;\r
-import java.util.Map;\r
-\r
-\r
-\r
-public class CometdUtil {\r
- private static BayeuxServer bayeuxServer;\r
-\r
- public static BayeuxServer getBayeuxServer() {\r
- return bayeuxServer;\r
- }\r
-\r
- public static void setBayeuxServer(BayeuxServer bayeuxServer) {\r
- CometdUtil.bayeuxServer = bayeuxServer;\r
- }\r
-\r
- public static String convertBean2Json(Object object) throws IOException {\r
- ObjectMapper mapper = new ObjectMapper();\r
- return mapper.writeValueAsString(object);\r
- }\r
-\r
- @SuppressWarnings("rawtypes")\r
- public static Map convertJson2Map(String json) throws IOException {\r
- ObjectMapper mapper = new ObjectMapper();\r
- return mapper.readValue(json, Map.class);\r
- }\r
-}\r
\r
import javax.ws.rs.NotFoundException;\r
\r
-import org.openo.commontosca.catalog.cometd.CometdException;\r
import org.openo.commontosca.catalog.common.CommonConstant;\r
import org.openo.commontosca.catalog.common.FileUtil;\r
import org.openo.commontosca.catalog.common.MsbAddrConfig;\r
return result;\r
}\r
\r
- public static boolean isExistInstanceCSAR(String csarId) throws CometdException {\r
+ public static boolean isExistInstanceCSAR(String csarId) {\r
// 查询各O(GSO、NFVO、SDNO)的资源实例数据库,查询指定csarId对应的服务模版\r
ArrayList<ServiceTemplate> templateList = queryAvailableTemplatesByCsar(csarId);\r
// 调生命周期的接口查询所有实例,查询实例中是否包含指定csarId对应的服务模析ID\r
-#!/bin/sh
-#
+#
# Copyright 2016 [ZTE] and others.
#
# Licensed under the Apache License, Version 2.0 (the "License");