diff options
Diffstat (limited to 'catalog-core/catalog-mgr/src/main/java/org/openo')
159 files changed, 0 insertions, 15443 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 deleted file mode 100644 index 1528edc7..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogApp.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * 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; - -import com.fasterxml.jackson.annotation.JsonInclude; - -import io.dropwizard.Application; -import io.dropwizard.assets.AssetsBundle; -import io.dropwizard.db.DataSourceFactory; -import io.dropwizard.hibernate.HibernateBundle; -import io.dropwizard.migrations.MigrationsBundle; -import io.dropwizard.server.SimpleServerFactory; -import io.dropwizard.setup.Bootstrap; -import io.dropwizard.setup.Environment; -import io.swagger.jaxrs.config.BeanConfig; -import io.swagger.jaxrs.listing.ApiListingResource; - -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; -import org.openo.commontosca.catalog.common.HttpServerPathConfig; -import org.openo.commontosca.catalog.common.MsbAddrConfig; -import org.openo.commontosca.catalog.common.ServiceRegistrer; -import org.openo.commontosca.catalog.db.dao.DaoManager; -import org.openo.commontosca.catalog.db.entity.NodeTemplateData; -import org.openo.commontosca.catalog.db.entity.PackageData; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData; -import org.openo.commontosca.catalog.db.hibernate.HibernateBundleAgent; -import org.openo.commontosca.catalog.health.ConsoleHealthCheck; -import org.openo.commontosca.catalog.resources.PackageResource; -import org.openo.commontosca.catalog.resources.TemplateResource; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.EnumSet; -import javax.servlet.DispatcherType; - - - - -public class CatalogApp extends Application<CatalogAppConfiguration> { - - private static final Logger LOGGER = LoggerFactory.getLogger(CatalogApp.class); - - public static void main(String[] args) throws Exception { - new CatalogApp().run(args); - } - - @Override - public String getName() { - return "OPENO-Catalog"; - } - private final HibernateBundleAgent bundle = new HibernateBundleAgent(); - @Override - public void initialize(Bootstrap<CatalogAppConfiguration> bootstrap) { - bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc")); - initDb(bootstrap); - } - - // private void initDao() { - // DaoManager.getInstance().setSessionFactory(bundle.getSessionFactory()); - // } - - private void initDb(Bootstrap<CatalogAppConfiguration> bootstrap) { - bootstrap.addBundle(bundle); - bootstrap.addBundle(new MigrationsBundle<CatalogAppConfiguration>() { - @Override - public DataSourceFactory getDataSourceFactory(CatalogAppConfiguration configuration) { - return configuration.getDataSourceFactory(); - } - }); - } - - @Override - public void run(CatalogAppConfiguration configuration, Environment environment) { - LOGGER.info("Start to initialize catalogue."); - MsbAddrConfig.setMsbAddress(configuration.getMsbServerAddr()); - HttpServerAddrConfig.setHttpServerAddress(configuration.getHttpServerAddr()); - HttpServerPathConfig.setHttpServerPath(configuration.getHttpServerPath()); - //initDao(); - final ConsoleHealthCheck healthCheck = new ConsoleHealthCheck(configuration.getTemplate()); - environment.healthChecks().register("template", healthCheck); - - environment.jersey().register(new PackageResource()); - environment.jersey().register(new TemplateResource()); - // environment.jersey().register(new VNFHostImageResource()); - // environment.jersey().register(new VNFSoftwareVersionResource()); - - // register rest interface - environment.jersey().packages("org.openo.commontosca.catalog.resources"); - // upload file by inputstream need to register MultiPartFeature - environment.jersey().register(MultiPartFeature.class); - - initSwaggerConfig(environment, configuration); - initCometd(environment); - Config.setConfigration(configuration); - initService(); - LOGGER.info("Initialize catalogue finished."); - } - - /** - * initialize swagger configuration. - * - * @param environment environment information - * @param configuration catalogue configuration - */ - private void initSwaggerConfig(Environment environment, CatalogAppConfiguration configuration) { - environment.jersey().register(new ApiListingResource()); - environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); - - BeanConfig config = new BeanConfig(); - config.setTitle("Open-o Catalog Service rest API"); - config.setVersion("1.0.0"); - config.setResourcePackage("org.openo.commontosca.catalog.resources"); - // set rest api basepath in swagger - SimpleServerFactory simpleServerFactory = - (SimpleServerFactory) configuration.getServerFactory(); - String basePath = simpleServerFactory.getApplicationContextPath(); - String rootPath = simpleServerFactory.getJerseyRootPath(); - rootPath = rootPath.substring(0, rootPath.indexOf("/*")); - basePath = - basePath.equals("/") ? rootPath : (new StringBuilder()).append(basePath).append(rootPath) - .toString(); - config.setBasePath(basePath); - config.setScan(true); - } - - private void initService() { - Thread registerCatalogService = new Thread(new ServiceRegistrer()); - registerCatalogService.setName("register catalog service to Microservice Bus"); - registerCatalogService.start(); - } - - /** - * 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/CatalogAppConfiguration.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogAppConfiguration.java deleted file mode 100644 index b3204873..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/CatalogAppConfiguration.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * 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; - -import com.fasterxml.jackson.annotation.JsonProperty; -import io.dropwizard.Configuration; -import io.dropwizard.db.DataSourceFactory; -import org.hibernate.validator.constraints.NotEmpty; - -import javax.validation.Valid; -import javax.validation.constraints.NotNull; - - - - -public class CatalogAppConfiguration extends Configuration { - @NotEmpty - private String template; - - @NotEmpty - private String defaultName = "OPENO-Catalog"; - - @NotEmpty - private String msbServerAddr; - - @NotEmpty - private String httpServerAddr; - - @NotEmpty - private String parserType; - - @NotEmpty - private String cataloguePath; - @NotEmpty - private String httpServerPath; - - @Valid - private String serviceIp; - - @Valid - @NotNull - private DataSourceFactory database = new DataSourceFactory(); - - @JsonProperty("database") - public DataSourceFactory getDataSourceFactory() { - return database; - } - - @JsonProperty("database") - public void setDataSourceFactory(DataSourceFactory dataSourceFactory) { - this.database = dataSourceFactory; - } - - @JsonProperty - public String getTemplate() { - return template; - } - - @JsonProperty - public void setTemplate(String template) { - this.template = template; - } - - @JsonProperty - public String getDefaultName() { - return defaultName; - } - - @JsonProperty - public void setDefaultName(String name) { - this.defaultName = name; - } - - @JsonProperty - public String getMsbServerAddr() { - return msbServerAddr; - } - - @JsonProperty - public void setMsbServerAddr(String msbServerAddr) { - this.msbServerAddr = msbServerAddr; - } - - @JsonProperty - public String getHttpServerAddr() { - return httpServerAddr; - } - - @JsonProperty - public void setHttpServerAddr(String httpServerAddr) { - this.httpServerAddr = httpServerAddr; - } - - public String getParserType() { - return parserType; - } - - public void setParserType(String parserType) { - this.parserType = parserType; - } - - @JsonProperty - public String getCataloguePath() { - return cataloguePath; - } - - @JsonProperty - public void setCataloguePath(String cataloguePath) { - this.cataloguePath = cataloguePath; - } - - @JsonProperty - public String getHttpServerPath() { - return httpServerPath; - } - - @JsonProperty - public void setHttpServerPath(String httpServerPath) { - this.httpServerPath = httpServerPath; - } - - @JsonProperty - public String getServiceIp() { - return serviceIp; - } - - @JsonProperty - public void setServiceIp(String serviceIp) { - this.serviceIp = serviceIp; - } - -} 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 deleted file mode 100644 index 7237a37b..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdException.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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 deleted file mode 100644 index a54b9abf..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdService.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * 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 deleted file mode 100644 index ace95455..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdServlet.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * 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 deleted file mode 100644 index efb2d35d..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/cometd/CometdUtil.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * 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 deleted file mode 100644 index 8250c94f..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonConstant.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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.common; - -public class CommonConstant { - // Package Status - public static final String PACKAGE_STATUS_DELETING = "deleting"; - - public static final String PACKAGE_STATUS_DELETE_FAIL = "deleteFailed"; - - public static final String PACKAGE_XML_FORMAT = "xml"; - - - public static final String PACKAGE_YAML_FORMAT = "yaml"; - - // host image progress - - public static final String TOSCA_METADATA = "TOSCA-Metadata"; - - public static final String CSAR_VERSION_META = "version"; - - public static final String CSAR_TYPE_META = "type"; - - public static final String CSAR_PROVIDER_META = "provider"; - - public static final String DEFINITIONS = "Definitions"; - - public static final String CSAR_META = "csar.meta"; - - public static final String CSAR_SUFFIX = ".csar"; - - 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/common/CommonErrorResponse.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonErrorResponse.java deleted file mode 100644 index 31709064..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/CommonErrorResponse.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 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.common; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class CommonErrorResponse { - - private String code; - - private String message; - - - public static Object failure(String message) { - return message; - } - - public CommonErrorResponse(String message) { - super(); - this.message = message; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/Config.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/Config.java deleted file mode 100644 index 0b9c4074..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/Config.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * 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.common; - -import org.openo.commontosca.catalog.CatalogAppConfiguration; - - -public class Config { - private static CatalogAppConfiguration configration; - - public static CatalogAppConfiguration getConfigration() { - return configration; - } - - public static void setConfigration(CatalogAppConfiguration config) { - configration = config; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/DateTimeUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/DateTimeUtil.java deleted file mode 100644 index d41993fc..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/DateTimeUtil.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.common; - -import java.text.SimpleDateFormat; -import java.util.Date; - -public class DateTimeUtil { - public static String getCurrentTime() { - return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()); - } - - public static String getFormatTime(Date date) { - return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date); - } - - public static String getFormatTime(Date date, String format) { - return new SimpleDateFormat(format).format(date); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/EnumUploadStatus.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/EnumUploadStatus.java deleted file mode 100644 index 1aa6d478..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/EnumUploadStatus.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * 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.common; - -public enum EnumUploadStatus { - Create_Directory_Success, Create_Directory_Fail, File_Exist, - Upload_From_Break_Success, Upload_From_Break_Failed, Upload_New_File_Success, - Upload_New_File_Failed -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/FileUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/FileUtil.java deleted file mode 100644 index ae17de61..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/FileUtil.java +++ /dev/null @@ -1,185 +0,0 @@ -/** - * 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.common; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - - -public final class FileUtil { - - public static final Logger LOG = LoggerFactory.getLogger(FileUtil.class); - - private static final int BUFFER_SIZE = 2 * 1024 * 1024; - - private static final int TRY_COUNT = 3; - - private FileUtil() { - - } - - - /** - * create dir. - * @param dir dir to create - * @return boolean - */ - public static boolean createDirectory(String dir) { - File folder = new File(dir); - int tryCount = 0; - while (tryCount < TRY_COUNT) { - tryCount++; - if (!folder.exists() && !folder.mkdirs()) { - continue; - } else { - return true; - } - } - - return folder.exists(); - } - - /** - * delete file. - * @param file the file to delete - * @return boolean - */ - public static boolean deleteFile(File file) { - String hintInfo = file.isDirectory() ? "dir " : "file "; - boolean isFileDeleted = file.delete(); - boolean isFileExist = file.exists(); - if (!isFileExist) { - if (isFileDeleted) { - LOG.info("delete " + hintInfo + file.getAbsolutePath()); - } else { - isFileDeleted = true; - LOG.info("file not exist. no need delete " + hintInfo + file.getAbsolutePath()); - } - } else { - LOG.info("fail to delete " + hintInfo + file.getAbsolutePath()); - } - return isFileDeleted; - } - - - /** - * unzip zip file. - * @param zipFileName file name to zip - * @param extPlace extPlace - * @return unzip file name - * @throws IOException e1 - */ - public static ArrayList<String> unzip(String zipFileName, String extPlace) throws IOException { - ZipFile zipFile = null; - ArrayList<String> unzipFileNams = new ArrayList<String>(); - - try { - zipFile = new ZipFile(zipFileName); - Enumeration<?> fileEn = zipFile.entries(); - byte[] buffer = new byte[BUFFER_SIZE]; - - while (fileEn.hasMoreElements()) { - InputStream input = null; - BufferedOutputStream bos = null; - try { - ZipEntry entry = (ZipEntry) fileEn.nextElement(); - if (entry.isDirectory()) { - continue; - } - - input = zipFile.getInputStream(entry); - File file = new File(extPlace, entry.getName()); - if (!file.getParentFile().exists()) { - createDirectory(file.getParentFile().getAbsolutePath()); - } - - bos = new BufferedOutputStream(new FileOutputStream(file)); - while (true) { - int length = input.read(buffer); - if (length == -1) { - break; - } - bos.write(buffer, 0, length); - } - unzipFileNams.add(file.getAbsolutePath()); - } finally { - closeOutputStream(bos); - closeInputStream(input); - } - } - } finally { - closeZipFile(zipFile); - } - return unzipFileNams; - } - - /** - * close InputStream. - * - * @param inputStream the inputstream to close - */ - private static void closeInputStream(InputStream inputStream) { - try { - if (inputStream != null) { - inputStream.close(); - } - } catch (Exception e1) { - LOG.info("close InputStream error!"); - } - } - - /** - * close OutputStream. - * - * @param outputStream the output stream to close - */ - private static void closeOutputStream(OutputStream outputStream) { - try { - if (outputStream != null) { - outputStream.close(); - } - } catch (Exception e1) { - LOG.info("close OutputStream error!"); - } - } - - /** - * close zipFile. - * - * @param zipFile the zipFile to close - */ - private static void closeZipFile(ZipFile zipFile) { - try { - if (zipFile != null) { - zipFile.close(); - zipFile = null; - } - } catch (IOException e1) { - LOG.info("close ZipFile error!"); - } - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/FtpClient.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/FtpClient.java deleted file mode 100644 index 62a68df8..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/FtpClient.java +++ /dev/null @@ -1,211 +0,0 @@ -/** - * 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.common; - -import org.apache.commons.net.ftp.FTP; -import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPFile; -import org.apache.commons.net.ftp.FTPReply; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - - - -/** - * FTP client user for upload or delete files in ftp client. - */ -public class FtpClient { - private FTPClient ftpClient; - - public static final String ZIP = ".zip"; - - public FtpClient(String host, String username, String password, int port) throws Exception { - ftpClient = new FTPClient(); - connect(host, username, password, port); - } - - private void connect(String host, String user, String pwd, int port) throws Exception { - ftpClient.connect(host, port); - if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { - ftpClient.disconnect(); - throw new Exception("Exception in connecting to FTP Server"); - } - ftpClient.login(user, pwd); - ftpClient.setFileType(FTP.BINARY_FILE_TYPE); - ftpClient.enterLocalPassiveMode(); - } - - /** - * disconnect to ftp. - * @throws Exception e - */ - public void disconnect() throws Exception { - if (this.ftpClient.isConnected()) { - this.ftpClient.logout(); - this.ftpClient.disconnect(); - } - } - - /** - * get remote file. - * @param remoteFilePath remote file path - * @param localFilePath local file path - * @throws IOException e - */ - public void get(String remoteFilePath, String localFilePath) throws IOException { - FileOutputStream fos = new FileOutputStream(localFilePath); - this.ftpClient.retrieveFile(remoteFilePath, fos); - fos.close(); - } - - public void delete(String filePath) throws IOException { - ftpClient.dele(filePath); - } - - - /** - * upload a file to FTP client. support resuming. - * @param startPosition start position to upload - * @param endPosition end position of upload - * @param inputstream upload inputstream - * @param remote remote path - * @return enum - * @throws IOException e - */ - public EnumUploadStatus upload(int startPosition, int endPosition, InputStream inputstream, - String remote) throws IOException { - // set transfer mode: PassiveMode - ftpClient.enterLocalPassiveMode(); - // set transfer file type: binary - ftpClient.setFileType(FTP.BINARY_FILE_TYPE); - ftpClient.setControlEncoding("GBK"); - String remoteFileName = remote; - if (remote.contains("/")) { - remoteFileName = remote.substring(remote.lastIndexOf("/") + 1); - if (createDirecroty(remote, ftpClient) == EnumUploadStatus.Create_Directory_Fail) { - return EnumUploadStatus.Create_Directory_Fail; - } - } - - long lstartPos = 0; - FTPFile[] files = ftpClient.listFiles(new String(remoteFileName.getBytes("GBK"), "iso-8859-1")); - if (files.length == 1) { - lstartPos = files[0].getSize(); - } - if (lstartPos > endPosition) { - return EnumUploadStatus.File_Exist; - } - if (lstartPos < startPosition) { - lstartPos = startPosition; - } else if (lstartPos > startPosition && lstartPos < endPosition) { - lstartPos = startPosition; - } - - return uploadFile(remoteFileName, inputstream, ftpClient, lstartPos); - } - - /** - * Create a remote server directory recursively. - * - * @param remote remote directory - * @param ftpClient ftpclient - * @return enum - * @throws IOException e - */ - public EnumUploadStatus createDirecroty(String remote, FTPClient ftpClient) throws IOException { - String directory = remote.substring(0, remote.lastIndexOf("/") + 1); - if (!directory.equalsIgnoreCase("/") - && !ftpClient.changeWorkingDirectory(new String(directory.getBytes("GBK"), "iso-8859-1"))) { - int start = 0; - int end = 0; - if (directory.startsWith("/")) { - start = 1; - } else { - start = 0; - } - end = directory.indexOf("/", start); - while (true) { - String subDirectory = - new String(remote.substring(start, end).getBytes("GBK"), "iso-8859-1"); - if (!ftpClient.changeWorkingDirectory(subDirectory)) { - if (ftpClient.makeDirectory(subDirectory)) { - ftpClient.changeWorkingDirectory(subDirectory); - } else { - return EnumUploadStatus.Create_Directory_Fail; - } - } - - start = end + 1; - end = directory.indexOf("/", start); - - // check whether all directories are created or not - if (end <= start) { - break; - } - } - } - return EnumUploadStatus.Create_Directory_Success; - } - - /** - * upload file to client. - * - * @param remoteFile remote file name - * @param localFile local file name including absolute path - * @param ftpClient FTPClient class - * @param lStartPos starting position - * @return enum - * @throws IOException e - */ - /** - * upload file to client. - * @param remoteFile remote file name - * @param inputstream inputstream to upload file - * @param ftpClient ftp client - * @param lstartPos start position - * @return enum - * @throws IOException e - */ - public EnumUploadStatus uploadFile(String remoteFile, InputStream inputstream, - FTPClient ftpClient, long lstartPos) throws IOException { - OutputStream out = - ftpClient.appendFileStream(new String(remoteFile.getBytes("GBK"), "iso-8859-1")); - if (out == null) { - out = ftpClient.storeFileStream(new String(remoteFile.getBytes("GBK"), "iso-8859-1")); - } - if (lstartPos > 0) { - ftpClient.setRestartOffset(lstartPos); - } - byte[] bytes = new byte[512]; - int count; - while ((count = inputstream.read(bytes, 0, 512)) > 0) { - out.write(bytes, 0, count); - } - out.flush(); - out.close(); - boolean result = ftpClient.completePendingCommand(); - if (lstartPos > 0) { - return result ? EnumUploadStatus.Upload_From_Break_Success - : EnumUploadStatus.Upload_From_Break_Failed; - } else { - return result ? EnumUploadStatus.Upload_New_File_Success - : EnumUploadStatus.Upload_New_File_Failed; - } - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/HttpServerAddrConfig.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/HttpServerAddrConfig.java deleted file mode 100644 index 07d26458..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/HttpServerAddrConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * 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.common; - - -public class HttpServerAddrConfig { - - protected static String httpServerAddress; - - public static String getHttpServerAddress() { - return httpServerAddress; - } - - public static void setHttpServerAddress(String httpServerAddress) { - HttpServerAddrConfig.httpServerAddress = httpServerAddress; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/HttpServerPathConfig.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/HttpServerPathConfig.java deleted file mode 100644 index cef93583..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/HttpServerPathConfig.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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.common; - - -public class HttpServerPathConfig { - protected static String httpServerPath; - - public static String getHttpServerPath() { - return httpServerPath; - } - - public static void setHttpServerPath(String httpServerPath) { - HttpServerPathConfig.httpServerPath = httpServerPath; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/MsbAddrConfig.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/MsbAddrConfig.java deleted file mode 100644 index 4f27a0f3..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/MsbAddrConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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.common; - -public class MsbAddrConfig { - - protected static String msbAddress; - - public static String getMsbAddress() { - return msbAddress; - } - - public static void setMsbAddress(String msbAddress) { - MsbAddrConfig.msbAddress = msbAddress; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/MsbUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/MsbUtil.java deleted file mode 100644 index a241c112..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/MsbUtil.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * 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.common; - -/** - * micro-service bus utility class. - * - */ -public class MsbUtil { - - public static String getRocBaseUrl() { - return Config.getConfigration().getMsbServerAddr() + getRocApiRootDomain(); - } - - private static String getRocApiRootDomain() { - return "/api/roc/v1"; - } - - public static String getNsocLifecycleBaseUrl() { - return Config.getConfigration().getMsbServerAddr() + getNsocLifeCycleRootDomain(); - } - - private static String getNsocLifeCycleRootDomain() { - return "/api/nsoc/v1"; - } - - public static String getVimBaseUrl() { - return Config.getConfigration().getMsbServerAddr() + getVimRootDomain(); - } - - private static String getVimRootDomain() { - return "/api/vim/v1"; - } - - public static String getPackageUrl() { - return Config.getConfigration().getMsbServerAddr() + "/api/nsoc/v1/csar/"; - } - - public static String getYamlParseBaseUrl() { - return Config.getConfigration().getMsbServerAddr() + "/openoapi/yamlparser/v1"; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/RestUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/RestUtil.java deleted file mode 100644 index 049aac26..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/RestUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.common; - -import javax.ws.rs.core.Response; - - -public class RestUtil { - - /** - * get rest exception. - * @param errorMsg error message - * @return Response - */ - public static Response getRestException(String errorMsg) { - String code = "001"; - return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity(new CommonErrorResponse(code, errorMsg)).build(); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/ServiceRegistrer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/ServiceRegistrer.java deleted file mode 100644 index 1e2be58a..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/ServiceRegistrer.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * 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.common; - -import org.openo.commontosca.catalog.common.Config; -import org.openo.commontosca.catalog.externalservice.msb.MicroserviceBusConsumer; -import org.openo.commontosca.catalog.externalservice.msb.ServiceRegisterEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Iterator; - -public class ServiceRegistrer implements Runnable { - private final ArrayList<ServiceRegisterEntity> serviceEntityList = - new ArrayList<ServiceRegisterEntity>(); - private static final Logger LOG = LoggerFactory.getLogger(ServiceRegistrer.class); - - public ServiceRegistrer() { - initServiceEntity(); - } - - @Override - public void run() { - LOG.info("start microservice register"); - boolean flag = false; - ServiceRegisterEntity entity = new ServiceRegisterEntity(); - int retry = 0; - while (retry < 1000 && serviceEntityList.size() > 0) { - Iterator<ServiceRegisterEntity> it = serviceEntityList.iterator(); - while (it.hasNext()) { - entity = it.next(); - LOG.info("start" + entity.getServiceName() + " catalog microservice register.retry:" - + retry); - flag = MicroserviceBusConsumer.registerService(entity); - if (flag == false) { - LOG.warn(entity.getServiceName() - + " microservice register failed, sleep 30S and try again."); - threadSleep(30000); - } else { - LOG.info(entity.getServiceName() + " microservice register success!"); - it.remove(); - } - } - retry++; - - } - LOG.info("catalog microservice register end."); - - } - - /** - * sleep thread. - * @param second sleep second - */ - private void threadSleep(int seconds) { - LOG.info("start sleep ...."); - try { - Thread.sleep(seconds); - } catch (InterruptedException e1) { - LOG.error("thread sleep error.errorMsg:" + e1.getMessage()); - } - LOG.info("sleep end ."); - } - - private void initServiceEntity() { - ServiceRegisterEntity catalogEntity = new ServiceRegisterEntity(); - catalogEntity.setServiceName("catalog"); - catalogEntity.setProtocol("REST"); - catalogEntity.setVersion("v1"); - catalogEntity.setUrl("/openoapi/catalog/v1"); - catalogEntity.setSingleNode(Config.getConfigration().getServiceIp(), "8200", 0); - catalogEntity.setVisualRange("1"); - serviceEntityList.add(catalogEntity); - ServiceRegisterEntity httpServiceEntity = new ServiceRegisterEntity(); - httpServiceEntity.setServiceName("/files/catalog-http"); - httpServiceEntity.setProtocol("REST"); - httpServiceEntity.setVersion("v1"); - httpServiceEntity.setUrl("/"); - httpServiceEntity.setSingleNode(Config.getConfigration().getServiceIp(), "8201", 0); - httpServiceEntity.setVisualRange("1"); - serviceEntityList.add(httpServiceEntity); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/ToolUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/ToolUtil.java deleted file mode 100644 index 576cade3..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/ToolUtil.java +++ /dev/null @@ -1,403 +0,0 @@ -/** - * 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.common; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; - -import org.openo.commontosca.catalog.model.common.EnumToscaNodeTypeDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.UUID; - - - -/** - * common utility class. - * - */ -public class ToolUtil { - private static final Logger LOG = LoggerFactory.getLogger(ToolUtil.class); - - public static final String CATALOGUE_CSAR_DIR_NAME = "csar"; - - public static final String CATALOGUE_IMAGE_DIR_NAME = "image"; - - public static final int FILE_PERCENT = 1024 * 1024; // 1M - - public static boolean isEmptyString(String val) { - return val == null || "".equals(val); - } - - public static boolean isTrimedEmptyString(String val) { - return val == null || "".equals(val.trim()); - } - - public static boolean isTrimedEmptyArray(String[] val) { - return val == null || val.length == 0; - } - - /** - * trimed string. - * - * @param val string array to trim - * @return String[] - */ - public static String[] trimedStringArray(String[] val) { - if (isTrimedEmptyArray(val)) { - return val; - } - - String[] rets = new String[val.length]; - for (int i = 0; i < val.length; i++) { - rets[i] = val[i].trim(); - } - return rets; - } - - public static boolean isEmptyCollection(Collection<?> coll) { - return null == coll || coll.isEmpty(); - } - - /** - * store chunk file to local temp directory. - * - * @param dirName directory name - * @param fileName file name - * @param uploadedInputStream upload input stream - * @return String - * @throws IOException e - */ - public static String storeChunkFileInLocal(String dirName, String fileName, - InputStream uploadedInputStream) throws IOException { - File tmpDir = new File(dirName); - LOG.info("tmpdir = " + File.separator + dirName); - if (!tmpDir.exists()) { - tmpDir.mkdirs(); - } - File file = new File(tmpDir + File.separator + fileName); - OutputStream os = null; - try { - int read = 0; - byte[] bytes = new byte[1024]; - os = new FileOutputStream(file, true); - while ((read = uploadedInputStream.read(bytes)) != -1) { - os.write(bytes, 0, read); - } - os.flush(); - return file.getAbsolutePath(); - } finally { - if (os != null) { - os.close(); - } - } - } - - /** - * get temp dirctory when upload package. - * - * @param dirName temp directory name - * @param fileName package name - * @return String - */ - public static String getTempDir(String dirName, String fileName) { - // File tmpDir = new File(File.separator + dirName); - return Class.class.getClass().getResource("/").getPath() + dirName + File.separator - + fileName.replace(".csar", ""); - } - - public static String getUnzipDir(String dirName) { - File tmpDir = new File(File.separator + dirName); - return tmpDir.getAbsolutePath().replace(".csar", ""); - } - - /** - * delete file. - * - * @param dirName the directory of file - * @param fileName file name - * @return boolean - */ - public static boolean deleteFile(String dirName, String fileName) { - File tmpDir = new File(getCataloguePath() + File.separator + dirName); - if (!tmpDir.exists()) { - return true; - } - File file = new File(tmpDir.getAbsolutePath() + File.separator + fileName); - if (file.exists()) { - return file.delete(); - } - return true; - } - - public static String getCataloguePath() { - return Config.getConfigration().getCataloguePath(); - } - - public static String getCatalogueCsarPath() { - return getCataloguePath() + File.separator + CATALOGUE_CSAR_DIR_NAME; - } - - public static String getCatalogueImagePath() { - return getCataloguePath() + File.separator + CATALOGUE_IMAGE_DIR_NAME; - } - - /** - * get file size. - * - * @param file file which to get the size - * @param fileUnit file unit - * @return String file size - */ - public static String getFileSize(File file, int fileUnit) { - String fileSize = ""; - DecimalFormat format = new DecimalFormat("#0.00"); - if (file.exists()) { - fileSize = format.format((double) file.length() / fileUnit) + "M"; - } - return fileSize; - } - - public static String formatFileSize(double fileLength, int fileUnit) { - DecimalFormat format = new DecimalFormat("#0.00"); - return format.format(fileLength / fileUnit) + "M"; - } - - /** - * get file size by content. - * - * @param contentRange content range - * @return String - */ - public static String getFileSizeByContent(String contentRange) { - String size = - contentRange.substring(contentRange.indexOf("/") + 1, contentRange.length()).trim(); - return formatFileSize(Double.parseDouble(size), FILE_PERCENT); - } - - /** - * fix package format. - * - * @param csarId package ID - * @return String - */ - public static String formatCsar(String csarId) { - String result = csarId; - if (csarId.indexOf(".csar") < 0) { - result += ".csar"; - } - return result; - } - - /** - * judge the package format is xml or not. - * - * @param fileLocation package location - * @param unzipDir the directory where the package unzip to - * @return boolean - * @throws IOException e - */ - public static boolean isXmlCsar(String fileLocation, String unzipDir) throws IOException { - String tempfolder = unzipDir; - ArrayList<String> unzipFiles = FileUtil.unzip(fileLocation, tempfolder); - if (unzipFiles.isEmpty()) { - return true; - } - for (String unzipFile : unzipFiles) { - if (isYamlFile(new File(unzipFile))) { - return false; - } - } - return true; - } - - - /** - * delete the file and file directory. - * - * @param dir file - * @return boolean - */ - public static boolean deleteDir(File dir) { - if (dir.isDirectory()) { - String[] children = dir.list(); - for (int i = 0; i < children.length; i++) { - boolean success = deleteDir(new File(dir, children[i])); - if (!success) { - return false; - } - } - } - return dir.delete(); - } - - // public static boolean unZipCsar(String fileLocation) throws IOException { - // String tempfolder=System.getProperty("java.io.tmpdir"); - // ArrayList<String> unzipFiles = FileUtil.unzip(fileLocation, tempfolder); - // if(unzipFiles.isEmpty()){ - // return true; - // } - // } - - /** - * judge the file's format is yaml or not. - * - * @param file file to judge - * @return boolean - */ - public static boolean isYamlFile(File file) { - if (!file.isDirectory() && file.getName().indexOf(".yaml") != -1) { - return true; - } - return false; - } - - /** - * remove the csar suffix. - * - * @param csarName package name - * @return String - */ - public static String removeCsarSuffix(String csarName) { - return csarName.replaceAll(".csar", ""); - } - - /** - * add the csar fuffix. - * - * @param csarName package name - * @return String - */ - public static String addCsarSuffix(String csarName) { - if (csarName.indexOf(".csar") == -1) { - return csarName + ".csar"; - } - return csarName; - } - - /** - * judge whether the type is vnf node type. - * - * @param type type - * @return boolean - */ - public static boolean isVnfNodetype(String type) { - if (type.toLowerCase().contains(EnumToscaNodeTypeDefinition.VNFC.getName().toLowerCase())) { - return false; - } - return type.toLowerCase().contains(EnumToscaNodeTypeDefinition.VNF.getName().toLowerCase()); - } - - /** - * process file name. - * - * @param fileName file's name - * @return String - */ - public static String processFileName(String fileName) { - int index = fileName.indexOf(".zip"); - if (index == -1) { - return fileName; - } - - return addCsarSuffix(fileName.replaceAll(".zip", "")); - } - - /** - * exchange object to string. - * - * @param obj object - * @return String - */ - public static String objectToString(Object obj) { - if (obj == null) { - return ""; - } - Gson gson = new Gson(); - String str = gson.toJson(obj); - return str; - } - - public static String generateId() { - return UUID.randomUUID().toString(); - } - - /** - * get the size format according file size. - * - * @param fileSize file size - * @return size format - */ - public static String getFormatFileSize(long fileSize) { - long kb = 1024; - long mb = kb * 1024; - long gb = mb * 1024; - - if (fileSize >= gb) { - return String.format("%.1f GB", (float) fileSize / gb); - } else if (fileSize >= mb) { - float fi = (float) fileSize / mb; - return String.format(fi > 100 ? "%.0f MB" : "%.1f MB", fi); - } else if (fileSize >= kb) { - float fi = (float) fileSize / kb; - return String.format(fi > 100 ? "%.0f KB" : "%.1f KB", fi); - } else { - return String.format("%d B", fileSize); - } - } - - /** - * get gson from json. - * @param jsonString json string - * @param templateClass template class - * @return Template - */ - public static <T> T fromJson(String jsonString, Class<T> templateClass) { - 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) { - Gson gson = new Gson(); - return gson.toJson(template); - } - - /** - * @param value - * @return - */ - public static String getAsString(JsonElement value) { - if (value.isJsonPrimitive()) { - return value.getAsString(); - } - - return value.toString(); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/ZipCompressor.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/ZipCompressor.java deleted file mode 100644 index 08925f9c..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/common/ZipCompressor.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * 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.common; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.util.zip.CRC32; -import java.util.zip.CheckedOutputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - - -public class ZipCompressor { - - public static final Logger LOG = LoggerFactory.getLogger(ZipCompressor.class); - static final int BUFFER = 8192; - - private File zipFile; - - public ZipCompressor(String pathName) { - zipFile = new File(pathName); - } - - /** - * compress file according several path. - * @param pathName file path name - */ - public void compress(String... pathName) { - ZipOutputStream out = null; - try { - FileOutputStream fileOutputStream = new FileOutputStream(zipFile); - CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream, new CRC32()); - out = new ZipOutputStream(cos); - String basedir = ""; - for (int i = 0; i < pathName.length; i++) { - compress(new File(pathName[i]), out, basedir); - } - out.close(); - } catch (Exception e1) { - throw new RuntimeException(e1); - } - } - - /** - * compress file according file path. - * @param srcPathName file path name - */ - public void compress(String srcPathName) { - File file = new File(srcPathName); - if (!file.exists()) { - throw new RuntimeException(srcPathName + "not exist!"); - } - try { - FileOutputStream fileOutputStream = new FileOutputStream(zipFile); - CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream, new CRC32()); - ZipOutputStream out = new ZipOutputStream(cos); - String basedir = ""; - compress(file, out, basedir); - out.close(); - } catch (Exception e1) { - throw new RuntimeException(e1); - } - } - - private void compress(File file, ZipOutputStream out, String basedir) { - if (file.isDirectory()) { - System.out.println("compress: " + basedir + file.getName()); - this.compressDirectory(file, out, basedir); - } else { - System.out.println("compress: " + basedir + file.getName()); - this.compressFile(file, out, basedir); - } - } - - private void compressDirectory(File dir, ZipOutputStream out, String basedir) { - if (!dir.exists()) { - return; - } - - File[] files = dir.listFiles(); - for (int i = 0; i < files.length; i++) { - compress(files[i], out, basedir + dir.getName() + "/"); - } - } - - private void compressFile(File file, ZipOutputStream out, String basedir) { - if (!file.exists()) { - return; - } - try { - byte data[] = new byte[BUFFER]; - BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); - ZipEntry entry = new ZipEntry(basedir + file.getName()); - out.putNextEntry(entry); - int count; - while ((count = bis.read(data, 0, BUFFER)) != -1) { - out.write(data, 0, count); - } - bis.close(); - } catch (Exception e1) { - throw new RuntimeException(e1); - } - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/common/CatalogResuorceType.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/common/CatalogResuorceType.java deleted file mode 100644 index e610d562..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/common/CatalogResuorceType.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * 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.db.common; - - -public enum CatalogResuorceType { - SERVICETEMPLATE, PACKAGE, NODETEMPLATE, TEMPLATE, SERVICETEMPLATEMAPPING; - - public static CatalogResuorceType getType(String type) { - return valueOf(type); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/common/Parameters.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/common/Parameters.java deleted file mode 100644 index 2211a748..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/common/Parameters.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * 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.db.common; - -public enum Parameters { - oid, name, provider, version, deletionPending, - type, status, csarId, vendor, serviceTemplateId, - nodeTemplateId, mappingId, nodeType; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/BaseDao.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/BaseDao.java deleted file mode 100644 index fab22d6a..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/BaseDao.java +++ /dev/null @@ -1,218 +0,0 @@ -/** - * 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.db.dao; - -import io.dropwizard.hibernate.AbstractDAO; -import io.dropwizard.util.Generics; - -import org.hibernate.Criteria; -import org.hibernate.HibernateException; -import org.hibernate.Query; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.criterion.Restrictions; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.util.HqlFactory; - -import java.util.List; -import java.util.Map; - - -/** - * a base class for Hibernate DAO classes. provide the common methods to create,delete,update and - * query data. - * - */ -public class BaseDao<T> extends AbstractDAO<T> { - - /** - * base dao constructor. - * - * @param sessionFactory session factory - */ - public BaseDao(SessionFactory sessionFactory) { - super(sessionFactory); - this.sessionFactory = sessionFactory; - this.entityClass = Generics.getTypeParameter(getClass()); - } - - public String[] excludeProperties; - private SessionFactory sessionFactory; - protected Session session; - private final Class<?> entityClass; - - @Override - protected Session currentSession() { - return this.session; - } - - /** - * update data. - * - * @param data the object to update - * @throws CatalogResourceException e1 - */ - public void update(T data, String filter) throws CatalogResourceException { - try { - String hql = HqlFactory.getUpdateHql(data, excludeProperties, filter); - beginTransaction(); - Query query = this.session.createQuery(hql); - query.executeUpdate(); - closeTransaction(); - } catch (Exception e1) { - transactionRollBack(); - throw new CatalogResourceException("error while updating data.errorMsg:" + e1.getMessage(), - e1); - } finally { - closeSession(); - } - } - - /** - * delete data. - * - * @param data the object to delete - * @throws CatalogResourceException e1 - */ - public void delete(T data) throws CatalogResourceException { - try { - beginTransaction(); - this.session.delete(data); - closeTransaction(); - } catch (Exception e1) { - transactionRollBack(); - throw new CatalogResourceException("error while deleting data.errorMsg:" + e1.getMessage(), - e1); - } finally { - closeSession(); - } - } - - /** - * create data. - * - * @param data the object to create - * @return data - * @throws CatalogResourceException e1 - */ - public T create(T data) throws CatalogResourceException { - try { - beginTransaction(); - session.save(data); - closeTransaction(); - } catch (HibernateException e1) { - transactionRollBack(); - throw new CatalogResourceException("error while creating data.errorMsg:" + e1.getMessage(), - e1); - } finally { - closeSession(); - } - return data; - } - - /** - * union query. - * - * @param unionHql union hql - * @return list - * @throws CatalogResourceException e1 - */ - public List<T> unionQuery(String unionHql) throws CatalogResourceException { - List<T> data; - try { - beginTransaction(); - Query query = this.session.createQuery(unionHql); - data = query.list(); - closeTransaction(); - } catch (Exception e1) { - transactionRollBack(); - throw new CatalogResourceException("error while union query data.errorMsg:" + e1.getMessage(), - e1); - } finally { - closeSession(); - } - return data; - } - - /** - * union delete. - * - * @param unionHql union hql - * @return int - * @throws CatalogResourceException e1 - */ - public int unionDelete(String unionHql) throws CatalogResourceException { - int num = 0; - try { - beginTransaction(); - Query query = this.session.createQuery(unionHql); - num = query.executeUpdate(); - closeTransaction(); - } catch (Exception e1) { - transactionRollBack(); - throw new CatalogResourceException("error while union query data.errorMsg:" + e1.getMessage(), - e1); - } finally { - closeSession(); - } - return num; - } - - /** - * query data. - * - * @param queryParams the condition map used to query objects - * @return data list - * @throws CatalogResourceException e1 - */ - @SuppressWarnings("unchecked") - public List<T> query(Map<String, String> queryParams) throws CatalogResourceException { - List<T> result = null; - try { - beginTransaction(); - Criteria criteria = this.session.createCriteria(entityClass); - for (String key : queryParams.keySet()) { - criteria.add(Restrictions.eq(key, queryParams.get(key))); - } - result = (List<T>) criteria.list(); - closeTransaction(); - } catch (HibernateException e1) { - throw new CatalogResourceException("error while querying data.errorMsg:" + e1.getMessage(), - e1); - } finally { - closeSession(); - } - return result; - } - - protected void beginTransaction() { - this.session = this.sessionFactory.openSession(); - this.session.beginTransaction(); - } - - protected void closeTransaction() { - this.session.getTransaction().commit(); - } - - protected void closeSession() { - this.session.close(); - } - - protected void transactionRollBack() { - this.session.getTransaction().rollback(); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/DaoManager.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/DaoManager.java deleted file mode 100644 index cdd1f666..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/DaoManager.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * 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.db.dao; - -import org.hibernate.SessionFactory; - -import org.openo.commontosca.catalog.db.common.CatalogResuorceType; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; - -/** - * DAO manager class. - * a class to store DAO instances and provide methods to get these instances. - * - */ -public class DaoManager { - private static DaoManager instance = new DaoManager(); - - private ServiceTemplateDao serviceTemplateDao; - private PackageDao packageDao; - private NodeTemplateDao nodeTemplateDao; - private TemplateDao templateDao; - private ServiceTemplateMappingDao templateMappingDao; - private SessionFactory sessionFactory; - - private DaoManager() {} - - public static synchronized DaoManager getInstance() { - return instance; - } - - /** - * get dao. - * @param type data type - * @return BaseDao<?> - */ - public BaseDao<?> getDao(String type) throws CatalogResourceException{ - if (sessionFactory == null) { - throw new CatalogResourceException("errorMsg:database connect init faild!"); - } - switch (CatalogResuorceType.getType(type)) { - case SERVICETEMPLATE: - return getServiceTemplateDao(); - case PACKAGE: - return getPackageDao(); - case NODETEMPLATE: - return getNodeTemplateDao(); - case TEMPLATE: - return getTemplateDao(); - case SERVICETEMPLATEMAPPING: - return getTemplateMappingDao(); - default: - return null; - } - } - - public void setSessionFactory(SessionFactory sessionFactory) { - this.sessionFactory = sessionFactory; - } - - public SessionFactory getSessionFactory() { - return sessionFactory; - } - - /** - * get service template dao. - * @return ServiceTemplateDao - */ - public ServiceTemplateDao getServiceTemplateDao() { - //if (serviceTemplateDao == null) { - serviceTemplateDao = new ServiceTemplateDao(sessionFactory); - // } - return serviceTemplateDao; - } - - public void setServiceTemplateDao(ServiceTemplateDao serviceTemplateDao) { - this.serviceTemplateDao = serviceTemplateDao; - } - - /** - * get package dao. - * @return PackageDao - */ - public PackageDao getPackageDao() { - // if (packageDao == null) { - packageDao = new PackageDao(sessionFactory); - // } - return packageDao; - } - - public void setPackageDao(PackageDao packageDao) { - this.packageDao = packageDao; - } - - /** - * get node templage dao. - * @return NodeTemplateDao - */ - public NodeTemplateDao getNodeTemplateDao() { - // if (nodeTemplateDao == null) { - nodeTemplateDao = new NodeTemplateDao(sessionFactory); - // } - return nodeTemplateDao; - } - - public void setTemplateDao(TemplateDao templateDao) { - this.templateDao = templateDao; - } - - /** - * get template dao. - * @return TemplateDao - */ - public TemplateDao getTemplateDao() { - // if (templateDao == null) { - templateDao = new TemplateDao(sessionFactory); - // } - return templateDao; - } - - public void setNodeTemplateDao(NodeTemplateDao nodeTemplateDao) { - this.nodeTemplateDao = nodeTemplateDao; - } - - /** - * get template mapping dao. - * @return ServiceTemplateMappingDao - */ - public ServiceTemplateMappingDao getTemplateMappingDao() { - //if (templateMappingDao == null) { - templateMappingDao = new ServiceTemplateMappingDao(sessionFactory); - // } - return templateMappingDao; - } - - public void setTemplateMappingDao(ServiceTemplateMappingDao templateMappingDao) { - this.templateMappingDao = templateMappingDao; - } - - /** - * set dao null. - */ - public void setDaoNull() { - this.nodeTemplateDao = null; - this.templateDao = null; - this.serviceTemplateDao = null; - this.packageDao = null; - this.templateMappingDao = null; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/NodeTemplateDao.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/NodeTemplateDao.java deleted file mode 100644 index 4669e37c..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/NodeTemplateDao.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.db.dao; - -import org.hibernate.SessionFactory; -import org.openo.commontosca.catalog.db.entity.NodeTemplateData; - - -/** - * host DAO class. - * - */ -public class NodeTemplateDao extends BaseDao<NodeTemplateData> { - - public NodeTemplateDao(SessionFactory sessionFactory) { - super(sessionFactory); - } - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/PackageDao.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/PackageDao.java deleted file mode 100644 index 81869de5..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/PackageDao.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.db.dao; - -import org.hibernate.SessionFactory; -import org.openo.commontosca.catalog.db.entity.PackageData; - - -/** - * host DAO class. - * - */ -public class PackageDao extends BaseDao<PackageData> { - - public PackageDao(SessionFactory sessionFactory) { - super(sessionFactory); - } - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/ServiceTemplateDao.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/ServiceTemplateDao.java deleted file mode 100644 index bd38a915..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/ServiceTemplateDao.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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.db.dao; - -import org.hibernate.SessionFactory; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; - -/** - * DAO class. - * - */ -public class ServiceTemplateDao extends BaseDao<ServiceTemplateData> { - - public ServiceTemplateDao(SessionFactory sessionFactory) { - super(sessionFactory); - } - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/ServiceTemplateMappingDao.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/ServiceTemplateMappingDao.java deleted file mode 100644 index d5e41306..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/ServiceTemplateMappingDao.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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.db.dao; - -import org.hibernate.SessionFactory; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData; - -/** - * DAO class. - * - */ -public class ServiceTemplateMappingDao extends BaseDao<ServiceTemplateMappingData> { - - public ServiceTemplateMappingDao(SessionFactory sessionFactory) { - super(sessionFactory); - } - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/TemplateDao.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/TemplateDao.java deleted file mode 100644 index 5a772ba4..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/dao/TemplateDao.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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.db.dao; - -import org.hibernate.HibernateException; -import org.hibernate.SessionFactory; -import org.openo.commontosca.catalog.db.entity.NodeTemplateData; -import org.openo.commontosca.catalog.db.entity.TemplateData; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.util.CatalogDbUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * DAO class. - * - */ -public class TemplateDao extends BaseDao<TemplateData> { - private static final Logger logger = LoggerFactory.getLogger(TemplateDao.class); - - public TemplateDao(SessionFactory sessionFactory) { - super(sessionFactory); - } - - /** - * create template data. - */ - public TemplateData create(TemplateData data) throws CatalogResourceException { - logger.info("TemplateDao:start add template.info:" + CatalogDbUtil.objectToString(data)); - beginTransaction(); - try { - this.session.persist(data.getServiceTemplate()); - for (NodeTemplateData nodeData : data.getNodeTemplates()) { - this.session.persist(nodeData); - } - closeTransaction(); - } catch (HibernateException e1) { - logger.error("TemplateDao:error while add template data.errorMsg:" + e1.getMessage()); - throw new CatalogResourceException("error while add template data" + e1.getMessage(), e1); - } finally { - closeSession(); - } - logger.info("TemplateDao: add template end ."); - return data; - } - - /** - * delete template data. - */ - public void delete(TemplateData data) throws CatalogResourceException { - logger.info("TemplateDao:start delete template.info:" + CatalogDbUtil.objectToString(data)); - beginTransaction(); - try { - for (NodeTemplateData nodeData : data.getNodeTemplates()) { - this.session.delete(nodeData); - } - this.session.delete(data.getServiceTemplate()); - closeTransaction(); - } catch (HibernateException e1) { - logger.error("TemplateDao:error while delete template data.errorMsg:" + e1.getMessage()); - throw new CatalogResourceException("error while delete template data" + e1.getMessage(), e1); - } finally { - closeSession(); - } - logger.info("TemplateDao: delete template end ."); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/BaseData.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/BaseData.java deleted file mode 100644 index ce688cbb..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/BaseData.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * 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.db.entity; - -public class BaseData { - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/NodeTemplateData.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/NodeTemplateData.java deleted file mode 100644 index 0457e068..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/NodeTemplateData.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * 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.db.entity; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name = "catalog_node_template_table") -@JsonIgnoreProperties(ignoreUnknown = true) -public class NodeTemplateData extends BaseData implements Serializable{ - - private static final long serialVersionUID = -2512216362645538471L; - @Id - @Column(name = "NODETEMPLATEID") - private String nodeTemplateId; - @Column(name = "NAME") - private String name; - @Id - @Column(name = "SERVICETEMPLATEID") - private String serviceTemplateId; - - @Column(name = "TYPE") - private String type; - - @Column(name = "PROPERTIES") - private String properties; - - @Column(name = "RELATIONSHIPS") - private String relationShips; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getServiceTemplateId() { - return serviceTemplateId; - } - - public void setServiceTemplateId(String serviceTemplateId) { - this.serviceTemplateId = serviceTemplateId; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getProperties() { - return properties; - } - - public void setProperties(String properties) { - this.properties = properties; - } - - public String getRelationShips() { - return relationShips; - } - - public void setRelationShips(String relationShips) { - this.relationShips = relationShips; - } - - public void setNodeTemplateId(String nodeTemplateId) { - this.nodeTemplateId = nodeTemplateId; - } - - public String getNodeTemplateId() { - return nodeTemplateId; - } - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/PackageData.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/PackageData.java deleted file mode 100644 index 631c6d9b..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/PackageData.java +++ /dev/null @@ -1,187 +0,0 @@ -/** - * 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.db.entity; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name = "catalog_package_table") -@JsonIgnoreProperties(ignoreUnknown = true) -public class PackageData extends BaseData { - - @Id - @Column(name = "CSARID") - private String csarId; - @Column(name = "DOWNLOADURi") - private String downloadUri; - - @Column(name = "NAME") - private String name; - - @Column(name = "SIZE") - private String size; - @Column(name = "VERSION") - private String version; - - @Column(name = "PROVIDER") - private String provider; - @Column(name = "TYPE") - private String type; - @Column(name = "FORMAT") - private String format; - - @Column(name = "DELETIONPENDING") - private String deletionPending; - - @Column(name = "MODIFYTIME") - private String modifyTime; - @Column(name = "OPERATIONALSTATE") - private String operationalState; - @Column(name = "USAGESTATE") - private String usageState; - @Column(name = "CREATETIME") - private String createTime; - @Column(name = "ONBOARDSTATE") - private String onBoardState; - @Column(name = "PROCESSSTATE") - private String processState; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getOnBoardState() { - return onBoardState; - } - - public void setOnBoardState(String onBoardState) { - this.onBoardState = onBoardState; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getProvider() { - return provider; - } - - public void setProvider(String provider) { - this.provider = provider; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDownloadUri() { - return downloadUri; - } - - public void setDownloadUri(String downloadUri) { - this.downloadUri = downloadUri; - } - - public String getSize() { - return size; - } - - public void setSize(String size) { - this.size = size; - } - - public String getFormat() { - return format; - } - - public void setFormat(String format) { - this.format = format; - } - - public String getDeletionPending() { - return deletionPending; - } - - public void setDeletionPending(String deletionPending) { - this.deletionPending = deletionPending; - } - - public String getModifyTime() { - return modifyTime; - } - - public void setModifyTime(String modifyTime) { - this.modifyTime = modifyTime; - } - - public String getOperationalState() { - return operationalState; - } - - public void setOperationalState(String operationalState) { - this.operationalState = operationalState; - } - - public String getUsageState() { - return usageState; - } - - public void setUsageState(String usageState) { - this.usageState = usageState; - } - - public String getCreateTime() { - return createTime; - } - - public void setCreateTime(String createTime) { - this.createTime = createTime; - } - - public void setCsarId(String csarId) { - this.csarId = csarId; - } - - public String getCsarId() { - return csarId; - } - - public String getProcessState() { - return processState; - } - - public void setProcessState(String processState) { - this.processState = processState; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/ServiceTemplateData.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/ServiceTemplateData.java deleted file mode 100644 index 7348b868..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/ServiceTemplateData.java +++ /dev/null @@ -1,160 +0,0 @@ -/** - * 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.db.entity; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - - -@Entity -@Table(name = "catalog_service_template_table") -@JsonIgnoreProperties(ignoreUnknown = true) -public class ServiceTemplateData extends BaseData { - @Id - @Column(name = "SERVICETEMPLATEID") - private String serviceTemplateId; - @Column(name = "TEMPLATENAME") - private String templateName; - - @Column(name = "TYPE") - private String type; - - @Column(name = "VENDOR") - private String vendor; - - @Column(name = "VERSION") - private String version; - - @Column(name = "CSARID") - private String csarId; - - @Column(name = "INPUTS") - private String inputs; - - @Column(name = "DOWNLOADURI") - private String downloadUri; - - @Column(name = "ROWDATA") - private String rowData; - @Column(name = "OPERATIONS") - private String operations; - - @Column(name = "METADATA") - private String metadata; - - @Column(name = "SERVICETEMPLATEORIGINALID") - private String serviceTemplateOriginalId; - - public String getRowData() { - return rowData; - } - - public void setRowData(String rowData) { - this.rowData = rowData; - } - - public String getOperations() { - return operations; - } - - public void setOperations(String operations) { - this.operations = operations; - } - - public String getTemplateName() { - return templateName; - } - - public void setTemplateName(String templateName) { - this.templateName = templateName; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getVendor() { - return vendor; - } - - public void setVendor(String vendor) { - this.vendor = vendor; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getCsarId() { - return csarId; - } - - public void setCsarId(String csarId) { - this.csarId = csarId; - } - - public String getInputs() { - return inputs; - } - - public void setInputs(String inputs) { - this.inputs = inputs; - } - - public String getDownloadUri() { - return downloadUri; - } - - public void setDownloadUri(String downloadUri) { - this.downloadUri = downloadUri; - } - - public void setServiceTemplateId(String serviceTemplateId) { - this.serviceTemplateId = serviceTemplateId; - } - - public String getServiceTemplateId() { - return serviceTemplateId; - } - - public String getMetadata() { - return metadata; - } - - public void setMetadata(String metadata) { - this.metadata = metadata; - } - - public String getServiceTemplateOriginalId() { - return serviceTemplateOriginalId; - } - - public void setServiceTemplateOriginalId(String serviceTemplateOriginalId) { - this.serviceTemplateOriginalId = serviceTemplateOriginalId; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/ServiceTemplateMappingData.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/ServiceTemplateMappingData.java deleted file mode 100644 index fab23d6c..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/ServiceTemplateMappingData.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * 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.db.entity; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name = "catalog_model_substitution_mapping_table") -@JsonIgnoreProperties(ignoreUnknown = true) -public class ServiceTemplateMappingData extends BaseData { - - @Id - @Column(name = "MAPPINGID") - private String mappingId; - - @Column(name = "NODETYPE") - private String nodeType; - - @Column(name = "SERVICETEMPLATEID") - private String serviceTemplateId; - - @Column(name = "REQUIREMENTS") - private String requirements; - - @Column(name = "CAPABILITIES") - private String capabilities; - - public String getMappingId() { - return mappingId; - } - - public void setMappingId(String mappingId) { - this.mappingId = mappingId; - } - - public String getNodeType() { - return nodeType; - } - - public void setNodeType(String nodeType) { - this.nodeType = nodeType; - } - - public String getServiceTemplateId() { - return serviceTemplateId; - } - - public void setServiceTemplateId(String serviceTemplateId) { - this.serviceTemplateId = serviceTemplateId; - } - - public String getRequirements() { - return requirements; - } - - public void setRequirements(String requirements) { - this.requirements = requirements; - } - - public String getCapabilities() { - return capabilities; - } - - public void setCapabilities(String capabilities) { - this.capabilities = capabilities; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/TemplateData.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/TemplateData.java deleted file mode 100644 index 415465c4..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/entity/TemplateData.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 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.db.entity; - -import java.util.ArrayList; - -public class TemplateData extends BaseData { - private ServiceTemplateData serviceTemplate; - private ArrayList<NodeTemplateData> nodeTemplates = new ArrayList<NodeTemplateData>(); - - public ServiceTemplateData getServiceTemplate() { - return serviceTemplate; - } - - public void setServiceTemplate(ServiceTemplateData serviceTemplate) { - this.serviceTemplate = serviceTemplate; - } - - public ArrayList<NodeTemplateData> getNodeTemplates() { - return nodeTemplates; - } - - public void setNodeTemplates(ArrayList<NodeTemplateData> nodeTemplates) { - this.nodeTemplates = nodeTemplates; - } - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/exception/CatalogResourceException.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/exception/CatalogResourceException.java deleted file mode 100644 index c18ad432..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/exception/CatalogResourceException.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * 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.db.exception; - -public class CatalogResourceException extends ErrorCodeException { - private static final long serialVersionUID = 5699508780537383310L; - - - public CatalogResourceException(int errcode) { - super(errcode, ""); - } - - - public CatalogResourceException(int errcode, Throwable cause) { - super(cause, errcode); - } - - - public CatalogResourceException(int errcode, String message, Throwable cause) { - super(cause, errcode, message); - } - - - public CatalogResourceException() { - super(9999999, null); - } - - - public CatalogResourceException(String message) { - super(9999999, message); - } - - - public CatalogResourceException(Throwable cause) { - super(cause, 9999999); - } - - - public CatalogResourceException(String message, Throwable cause) { - super(cause, 9999999, message); - } - - - /** - * catalog resource exception. - * @param source throwable source - * @param errId error Id - * @param debugMessage debug message - * @param arguments arguments - */ - public CatalogResourceException(Throwable source, int errId, String debugMessage, - String[] arguments) { - super(source, errId, debugMessage, arguments); - } - - public CatalogResourceException(Throwable source, int category, int code, String debugMessage, - String[] arguments) { - super(source, category, code, debugMessage, arguments); - } - - public int getErrcode() { - return super.getErrorCode(); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/exception/ErrorCodeException.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/exception/ErrorCodeException.java deleted file mode 100644 index 1a57f5e6..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/exception/ErrorCodeException.java +++ /dev/null @@ -1,144 +0,0 @@ -/** - * 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.db.exception; - - -public class ErrorCodeException extends Exception { - - private static final long serialVersionUID = 3220072444842529499L; - private int categoryCode = 0; - private int errorCode = 1; - private String[] arguments = null; - - private static String defaultText = null; - - - public static void setDefaultText(String text) { - defaultText = text; - } - - - public static String getDefaultText() { - return defaultText; - } - - - public ErrorCodeException(int code, String debugMessage) { - this(code, debugMessage, null); - } - - /** - * error code exception. - * @param code error code - * @param debugMessage debug message - * @param arguments arguments - */ - public ErrorCodeException(int code, String debugMessage, String[] arguments) { - super(debugMessage); - this.errorCode = code; - this.arguments = arguments; - } - - - public ErrorCodeException(Throwable source, int code) { - this(source, code, (String[]) null); - } - - /** - * error code exception. - * @param source Throwable - * @param code error code - * @param arguments arguments - */ - public ErrorCodeException(Throwable source, int code, String[] arguments) { - super(source); - this.errorCode = code; - this.arguments = arguments; - } - - - public ErrorCodeException(Throwable source, int code, String debugMessage) { - this(source, code, debugMessage, null); - } - - /** - * error code exception. - * @param source Throwable - * @param code error code - * @param debugMessage debug message - * @param arguments arguments - */ - public ErrorCodeException(Throwable source, int code, String debugMessage, String[] arguments) { - super(debugMessage, source); - this.errorCode = code; - this.arguments = arguments; - } - - - public ErrorCodeException(int category, int code, String debugMessage) { - this(category, code, debugMessage, null); - } - - - public ErrorCodeException(int category, int code, String debugMessage, String[] arguments) { - super(debugMessage); - this.categoryCode = category; - this.errorCode = code; - this.arguments = arguments; - } - - - public ErrorCodeException(Throwable source, int category, int code) { - this(source, category, code, (String[]) null); - } - - - public ErrorCodeException(Throwable source, int category, int code, String[] arguments) { - super(source); - this.categoryCode = category; - this.errorCode = code; - this.arguments = arguments; - } - - - public ErrorCodeException(Throwable source, int category, int code, String debugMessage) { - this(source, category, code, debugMessage, null); - } - - - public ErrorCodeException(Throwable source, int category, int code, String debugMessage, - String[] arguments) { - super(debugMessage, source); - this.categoryCode = category; - this.errorCode = code; - this.arguments = arguments; - } - - - public int getCategory() { - return categoryCode; - } - - public int getErrorCode() { - return errorCode; - } - - - public String[] getArguments() { - return arguments; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/hibernate/HibernateBundleAgent.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/hibernate/HibernateBundleAgent.java deleted file mode 100644 index 43b9333e..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/hibernate/HibernateBundleAgent.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * 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.db.hibernate; - -import io.dropwizard.ConfiguredBundle; -import io.dropwizard.setup.Bootstrap; -import io.dropwizard.setup.Environment; - -import org.openo.commontosca.catalog.CatalogAppConfiguration; -import org.openo.commontosca.catalog.db.dao.DaoManager; -import org.openo.commontosca.catalog.db.entity.NodeTemplateData; -import org.openo.commontosca.catalog.db.entity.PackageData; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HibernateBundleAgent implements ConfiguredBundle<CatalogAppConfiguration> { - - private final HibernateBundleExt bundle = new HibernateBundleExt(ServiceTemplateData.class, - PackageData.class, NodeTemplateData.class, ServiceTemplateMappingData.class); - private static final Logger LOGGER = LoggerFactory.getLogger(HibernateBundleAgent.class); - - @Override - public void run(final CatalogAppConfiguration configuration, final Environment environment) - throws Exception { - Thread thread = new Thread(new Runnable() { - int retry = 0; - boolean flag = true; - - public void run() { - while (retry < 1000) { - LOGGER.info("init hibernateBundle.retry:" + retry); - retry++; - try { - bundle.runExt(configuration, environment); - } catch (Exception e1) { - flag = false; - LOGGER.warn( - "init hibernateBundle failed, sleep 15S and try again.errorMsg:" + e1.getMessage()); - threadSleep(15000); - } - if (flag) { - LOGGER.info("init hibernateBundle success!"); - initDao(); - break; - } - } - } - }); - thread.setName("init hibernateBundle"); - thread.start(); - } - - private void initDao() { - DaoManager.getInstance().setSessionFactory(bundle.getSessionFactory()); - } - - private void threadSleep(int second) { - LOGGER.info("start sleep ...."); - try { - Thread.sleep(second); - } catch (InterruptedException error) { - LOGGER.error("thread sleep error.errorMsg:" + error.getMessage()); - } - LOGGER.info("sleep end ."); - } - - @Override - public void initialize(Bootstrap<?> bootstrap) { - bundle.initializeExt(bootstrap); - } - // - // public SessionFactory getSessionFactory() { - // return bundle.getSessionFactory(); - // } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/hibernate/HibernateBundleExt.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/hibernate/HibernateBundleExt.java deleted file mode 100644 index 20759491..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/hibernate/HibernateBundleExt.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * 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.db.hibernate; - -import com.google.common.collect.ImmutableList; - -import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module; - -import io.dropwizard.db.DataSourceFactory; -import io.dropwizard.hibernate.HibernateBundle; -import io.dropwizard.hibernate.SessionFactoryFactory; -import io.dropwizard.setup.Bootstrap; -import io.dropwizard.setup.Environment; - -import org.hibernate.SessionFactory; -import org.openo.commontosca.catalog.CatalogAppConfiguration; - - -public class HibernateBundleExt extends HibernateBundle<CatalogAppConfiguration> { - - private static final String DEFAULT_NAME = "hibernate"; - - private SessionFactory sessionFactory; - - private final ImmutableList<Class<?>> entities; - private final SessionFactoryFactory sessionFactoryFactory; - - protected HibernateBundleExt(Class<?> entity, Class<?>... entities) { - this(ImmutableList.<Class<?>>builder().add(entity).add(entities).build(), - new SessionFactoryFactory()); - } - - protected HibernateBundleExt(ImmutableList<Class<?>> entities, - SessionFactoryFactory sessionFactoryFactory) { - super(entities, sessionFactoryFactory); - this.entities = entities; - this.sessionFactoryFactory = sessionFactoryFactory; - } - - public final void initializeExt(Bootstrap<?> bootstrap) { - bootstrap.getObjectMapper().registerModule(createHibernate4Module()); - } - - /** - * Override to configure the {@link Hibernate4Module}. - */ - protected Hibernate4Module createHibernate4Module() { - return new Hibernate4Module(); - } - - protected String name() { - return DEFAULT_NAME; - } - - public final void runExt(CatalogAppConfiguration configuration, Environment environment) - throws Exception { - final DataSourceFactory dbConfig = getDataSourceFactory(configuration); - this.sessionFactory = - sessionFactoryFactory.build(this, environment, dbConfig, entities, name()); - - } - - public SessionFactory getSessionFactory() { - return sessionFactory; - } - - - @Override - public DataSourceFactory getDataSourceFactory(CatalogAppConfiguration configuration) { - return configuration.getDataSourceFactory(); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/resource/PackageManager.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/resource/PackageManager.java deleted file mode 100644 index a22fc66b..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/resource/PackageManager.java +++ /dev/null @@ -1,181 +0,0 @@ -/** - * 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.db.resource; - -import org.openo.commontosca.catalog.db.common.Parameters; -import org.openo.commontosca.catalog.db.entity.PackageData; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; - -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.util.CatalogDbUtil; -import org.openo.commontosca.catalog.db.util.HqlFactory; -import org.openo.commontosca.catalog.db.wrapper.PackageHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -public class PackageManager { - private static final Logger LOGGER = LoggerFactory.getLogger(PackageManager.class); - private static PackageManager manager; - PackageHandler handler = new PackageHandler(); - - /** - * get PackageManager instance. - * @return PackageManager instance - */ - public static synchronized PackageManager getInstance() { - if (manager == null) { - manager = new PackageManager(); - } - return manager; - } - - private PackageManager() {} - - /** - * add package. - * @param packageData package data - * @return PackageData - * @throws CatalogResourceException e - */ - public PackageData addPackage(PackageData packageData) throws CatalogResourceException { - LOGGER.info("start add package info to db.info:" + CatalogDbUtil.objectToString(packageData)); - PackageData data = handler.create(packageData); - LOGGER.info(" package info to db end.info:" + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * query package by package id. - * @param csarId package id - * @return package data list - * @throws CatalogResourceException e - */ - public ArrayList<PackageData> queryPackageByCsarId(String csarId) - throws CatalogResourceException { - Map<String, String> queryParam = new HashMap<String, String>(); - queryParam.put(Parameters.csarId.name(), csarId); - LOGGER.info("start query package info by csarid." + csarId); - ArrayList<PackageData> data = handler.query(queryParam); - LOGGER.info("query package info end.size:" + data.size() + "detail:" - + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * query package by condition. - * @param name package name - * @param provider package provider - * @param version package version - * @param deletionPending deletionPending - * @param type package type - * @return package data list - * @throws CatalogResourceException e - */ - public ArrayList<PackageData> queryPackage(String name, String provider, String version, - String deletionPending, String type) throws CatalogResourceException { - LOGGER.info("start query package info.name:" + name + " provider:" + provider + " version:" - + version + " type:" + type); - Map<String, String> queryParam = new HashMap<String, String>(); - if (CatalogDbUtil.isNotEmpty(name)) { - queryParam.put(Parameters.name.name(), name); - } - if (CatalogDbUtil.isNotEmpty(version)) { - queryParam.put(Parameters.version.name(), version); - } - if (CatalogDbUtil.isNotEmpty(deletionPending)) { - queryParam.put(Parameters.deletionPending.name(), deletionPending); - } - if (CatalogDbUtil.isNotEmpty(type)) { - queryParam.put(Parameters.type.name(), type); - } - if (CatalogDbUtil.isNotEmpty(provider)) { - queryParam.put(Parameters.provider.name(), provider); - } - ArrayList<PackageData> data = handler.query(queryParam); - LOGGER.info("query package info end.size:" + data.size() + "detail:" - + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * delete package according package id. - * @param packageId package id - * @throws CatalogResourceException e - */ - public void deletePackage(String packageId) throws CatalogResourceException { - LOGGER.info("start delete package info by id." + packageId); - handler.delete(packageId); - LOGGER.info(" delete package info end id." + packageId); - } - - /** - * delete package by service template id. - * @param serviceTemplateId service template id - * @throws CatalogResourceException e - */ - public void deletePackageByServiceTemplateId(String serviceTemplateId) - throws CatalogResourceException { - LOGGER.info("start delete package info by serviceTemplateid." + serviceTemplateId); - ServiceTemplateData serviceTemplate = new ServiceTemplateData(); - serviceTemplate.setServiceTemplateId(serviceTemplateId); - String filter = - HqlFactory.getDeleteHqlByFilter(PackageData.class, serviceTemplate, - Parameters.csarId.name()); - int data = handler.unionDelete(filter); - - LOGGER.info("delete serviceTemplate info end.num:" + data); - } - - /** - * query package by service template id. - * @param serviceTemplateId service template id - * @return package data list - * @throws CatalogResourceException e - */ - public ArrayList<PackageData> queryPackageByServiceTemplateId(String serviceTemplateId) - throws CatalogResourceException { - LOGGER.info("start query package info by serviceTemplateid." + serviceTemplateId); - ServiceTemplateData serviceTemplate = new ServiceTemplateData(); - serviceTemplate.setServiceTemplateId(serviceTemplateId); - String filter = - HqlFactory - .getQueryHqlByFilter(PackageData.class, serviceTemplate, Parameters.csarId.name()); - ArrayList<PackageData> data = handler.unionQuery(filter); - LOGGER.info("query package info end.size:" + data.size() + "detail:" - + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * update package data. - * - * @param packageData package data - * @param csarId package id - * @throws CatalogResourceException e - */ - public void updatePackage(PackageData packageData, String csarId) - throws CatalogResourceException { - LOGGER.info("start update package info by id." + csarId + " info:" - + CatalogDbUtil.objectToString(packageData)); - handler.update(packageData, csarId); - LOGGER.info(" update package end id." + csarId); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/resource/TemplateManager.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/resource/TemplateManager.java deleted file mode 100644 index e389bfe6..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/resource/TemplateManager.java +++ /dev/null @@ -1,301 +0,0 @@ -/** - * 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.db.resource; - -import org.openo.commontosca.catalog.db.common.Parameters; -import org.openo.commontosca.catalog.db.entity.NodeTemplateData; -import org.openo.commontosca.catalog.db.entity.PackageData; -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.util.CatalogDbUtil; -import org.openo.commontosca.catalog.db.util.HqlFactory; -import org.openo.commontosca.catalog.db.wrapper.NodeTemplateHandler; -import org.openo.commontosca.catalog.db.wrapper.ServiceTemplateHandler; -import org.openo.commontosca.catalog.db.wrapper.ServiceTemplateMappingHandler; -import org.openo.commontosca.catalog.db.wrapper.TemplateHandler; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -public class TemplateManager { - private static final Logger LOGGER = LoggerFactory.getLogger(TemplateManager.class); - private static TemplateManager manager; - ServiceTemplateHandler handler = new ServiceTemplateHandler(); - NodeTemplateHandler nodeTemplateHandler = new NodeTemplateHandler(); - TemplateHandler templateHandler = new TemplateHandler(); - ServiceTemplateMappingHandler mappingHandler = new ServiceTemplateMappingHandler(); - - /** - * get TemplateManager instance. - * @return TemplateManager instance - */ - public static synchronized TemplateManager getInstance() { - if (manager == null) { - manager = new TemplateManager(); - } - return manager; - } - - private TemplateManager() {} - - /** - * add service template. - * - * @param templateData TemplateData - * @return TemplateData - * @throws CatalogResourceException e - */ - public TemplateData addServiceTemplate(TemplateData templateData) - throws CatalogResourceException { - LOGGER - .info("start add template info to db.info:" + CatalogDbUtil.objectToString(templateData)); - TemplateData data = templateHandler.create(templateData); - LOGGER.info(" template info to db end.info:" + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * add service template mapping. - * @param templateMappingData mapping data - * @return ServiceTemplateMappingData - * @throws CatalogResourceException e - */ - public ServiceTemplateMappingData addServiceTemplateMapping( - ServiceTemplateMappingData templateMappingData) throws CatalogResourceException { - LOGGER.info("start add servicetemplate Mapping info to db.info:" - + CatalogDbUtil.objectToString(templateMappingData)); - ServiceTemplateMappingData data = mappingHandler.create(templateMappingData); - LOGGER.info(" template mapping info to db end.info:" + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * query service template mapping by id. - * @param id id - * @return ServiceTemplateMappingData list - * @throws CatalogResourceException e - */ - public ArrayList<ServiceTemplateMappingData> queryServiceTemplateMappingById(String id) - throws CatalogResourceException { - Map<String, String> queryParam = new HashMap<String, String>(); - queryParam.put(Parameters.mappingId.name(), id); - LOGGER.info("start query serviceTemplateMapping info by id." + id); - ArrayList<ServiceTemplateMappingData> data = mappingHandler.query(queryParam); - LOGGER.info("query serviceTemplateMapping info end.size:" + data.size() + "detail:" - + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * delete service template mapping by id. - * @param id id - * @throws CatalogResourceException e - */ - public void deleteServiceTemplateMappingById(String id) throws CatalogResourceException { - - LOGGER.info("start delete serviceTemplateMapping info by id." + id); - mappingHandler.delete(id); - LOGGER.info("delete serviceTemplateMapping info end"); - } - - /** - * delete service template mapping. - * @param nodeType node type - * @param serviceTemplateId service template id - * @throws CatalogResourceException e - */ - public void deleteServiceTemplateMapping(String nodeType, String serviceTemplateId) - throws CatalogResourceException { - Map<String, String> delParam = new HashMap<String, String>(); - if (CatalogDbUtil.isNotEmpty(nodeType)) { - delParam.put(Parameters.nodeType.name(), nodeType); - } - if (CatalogDbUtil.isNotEmpty(serviceTemplateId)) { - delParam.put(Parameters.serviceTemplateId.name(), serviceTemplateId); - } - LOGGER.info("start delete serviceTemplateMapping info.nodeType:" + nodeType - + " serviceTemplateId:" + serviceTemplateId); - mappingHandler.delete(delParam); - LOGGER.info("delete serviceTemplateMapping info "); - } - - /** - * query service template mapping. - * @param nodeType nodeType - * @param serviceTemplateId serviceTemplateId - * @return ServiceTemplateMappingData list - * @throws CatalogResourceException e - */ - public ArrayList<ServiceTemplateMappingData> queryServiceTemplateMapping(String nodeType, - String serviceTemplateId) throws CatalogResourceException { - Map<String, String> queryParam = new HashMap<String, String>(); - if (CatalogDbUtil.isNotEmpty(nodeType)) { - queryParam.put(Parameters.nodeType.name(), nodeType); - } - if (CatalogDbUtil.isNotEmpty(serviceTemplateId)) { - queryParam.put(Parameters.serviceTemplateId.name(), serviceTemplateId); - } - LOGGER.info("start query serviceTemplateMapping info.nodeType:" + nodeType - + " serviceTemplateId:" + serviceTemplateId); - ArrayList<ServiceTemplateMappingData> data = mappingHandler.query(queryParam); - LOGGER.info("query serviceTemplateMapping info end.size:" + data.size() + "detail:" - + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * query service template by id. - * @param id service template id - * @return ServiceTemplateData list - * @throws CatalogResourceException e - */ - public ArrayList<ServiceTemplateData> queryServiceTemplateById(String id) - throws CatalogResourceException { - Map<String, String> queryParam = new HashMap<String, String>(); - queryParam.put(Parameters.serviceTemplateId.name(), id); - LOGGER.info("start query serviceTemplate info by id." + id); - ArrayList<ServiceTemplateData> data = handler.query(queryParam); - LOGGER.info("query serviceTemplate info end.size:" + data.size() + "detail:" - + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * query service template according to condition. - * @param type template type - * @param version template version - * @param vendor template vendor - * @return ServiceTemplateData list - * @throws CatalogResourceException e - */ - public ArrayList<ServiceTemplateData> queryServiceTemplate(String type, String version, - String vendor) throws CatalogResourceException { - LOGGER.info("start query serviceTemplate info.type:" + type + " vendor:" + vendor + " version:" - + version); - Map<String, String> queryParam = new HashMap<String, String>(); - if (CatalogDbUtil.isNotEmpty(type)) { - queryParam.put(Parameters.type.name(), type); - } - if (CatalogDbUtil.isNotEmpty(vendor)) { - queryParam.put(Parameters.vendor.name(), vendor); - } - if (CatalogDbUtil.isNotEmpty(version)) { - queryParam.put(Parameters.version.name(), version); - } - ArrayList<ServiceTemplateData> data = handler.query(queryParam); - LOGGER.info("query serviceTemplate info end.size:" + data.size() + "detail:" - + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * query node template service template id. - * @param serviceTemplateId service template id - * @return NodeTemplateData list - * @throws CatalogResourceException e - */ - public ArrayList<NodeTemplateData> queryNodeTemplateBySeriviceTemplateId(String serviceTemplateId) - throws CatalogResourceException { - LOGGER.info("start query NodeTemplate info.serviceTemplateId:" + serviceTemplateId); - Map<String, String> queryParam = new HashMap<String, String>(); - queryParam.put(Parameters.serviceTemplateId.name(), serviceTemplateId); - ArrayList<NodeTemplateData> data = nodeTemplateHandler.query(queryParam); - LOGGER.info("query NodeTemplate info end.size:" + data.size() + "detail:" - + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * query node template by id. - * @param serviceTemplateId service template id - * @param nodeTemplateId nodetemplate id - * @return NodeTemplateData list - * @throws CatalogResourceException e - */ - public ArrayList<NodeTemplateData> queryNodeTemplateById(String serviceTemplateId, - String nodeTemplateId) throws CatalogResourceException { - LOGGER.info("start query NodeTemplate info.serviceTemplateId:" + serviceTemplateId - + "nodeTemplateId:" + nodeTemplateId); - Map<String, String> queryParam = new HashMap<String, String>(); - if (CatalogDbUtil.isNotEmpty(serviceTemplateId)) { - queryParam.put(Parameters.serviceTemplateId.name(), serviceTemplateId); - } - if (CatalogDbUtil.isNotEmpty(nodeTemplateId)) { - queryParam.put(Parameters.nodeTemplateId.name(), nodeTemplateId); - } - ArrayList<NodeTemplateData> data = nodeTemplateHandler.query(queryParam); - LOGGER.info("query NodeTemplate info end.size:" + data.size() + "detail:" - + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * query service template by package infomation. - * @param packageInfo package information - * @return ServiceTemplateData list - * @throws CatalogResourceException e - */ - public ArrayList<ServiceTemplateData> queryServiceTemplateByCsarPackageInfo( - PackageData packageInfo) throws CatalogResourceException { - LOGGER.info("start query serviceTemplate info by package.package:" - + CatalogDbUtil.objectToString(packageInfo)); - String filter = - HqlFactory.getQueryHqlByFilter(ServiceTemplateData.class, packageInfo, - Parameters.csarId.name()); - ArrayList<ServiceTemplateData> data = handler.unionQuery(filter); - LOGGER.info("query serviceTemplate info end.size:" + data.size() + "detail:" - + CatalogDbUtil.objectToString(data)); - return data; - } - - /** - * delete service template by id. - * @param serviceTemplateId service template id - * @throws CatalogResourceException e - */ - public void deleteServiceTemplateById(String serviceTemplateId) throws CatalogResourceException { - LOGGER.info("start delete serviceTemplate info.id:" + serviceTemplateId); - ArrayList<NodeTemplateData> nodeTemplateList = - queryNodeTemplateBySeriviceTemplateId(serviceTemplateId); - templateHandler.delete(serviceTemplateId, nodeTemplateList); - LOGGER.info(" delete serviceTemplate info end id." + serviceTemplateId); - } - - /** - * delete service template by package info. - * @param packageInfo package information - * @throws CatalogResourceException e - */ - public void deleteServiceTemplateByCsarPackageInfo(PackageData packageInfo) - throws CatalogResourceException { - LOGGER.info("start delete serviceTemplate info by package.package:" - + CatalogDbUtil.objectToString(packageInfo)); - - ArrayList<ServiceTemplateData> serviceTemplate = - queryServiceTemplateByCsarPackageInfo(packageInfo); - for (int i = 0; i < serviceTemplate.size(); i++) { - deleteServiceTemplateById(serviceTemplate.get(i).getServiceTemplateId()); - } - LOGGER.info("delete serviceTemplate info end."); - - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/util/CatalogDbUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/util/CatalogDbUtil.java deleted file mode 100644 index ff6518e0..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/util/CatalogDbUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.db.util; - - -import com.google.gson.Gson; - -import java.util.UUID; - - -public class CatalogDbUtil { - - public static String generateId() { - return UUID.randomUUID().toString(); - } - - public static boolean isNotEmpty(String str) { - return str != null && !"".equals(str) && str.length() > 0; - } - - /** - * exchange object to string. - * @param obj Object - * @return string - */ - public static String objectToString(Object obj) { - Gson gson = new Gson(); - if (obj != null) { - return gson.toJson(obj); - } else { - return null; - } - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/util/HqlFactory.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/util/HqlFactory.java deleted file mode 100644 index 08e2e35c..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/util/HqlFactory.java +++ /dev/null @@ -1,208 +0,0 @@ -/** - * 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.db.util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Arrays; - -/** - * a tool class for creating Hibernate's HQL. - * - */ -public class HqlFactory { - - private static final Logger logger = LoggerFactory.getLogger(HqlFactory.class); - - /** - * get update hql. - * @param obj the object that used to be generate the hql - * @param excludeProperties the properties that need not to be used - * @param filter the condition after "where" - * @return hibernate hql - */ - public static String getUpdateHql(Object obj, String[] excludeProperties, String filter) { - StringBuffer hql = new StringBuffer(); - String objName = obj.getClass().getSimpleName(); - hql.append("update "); - hql.append(objName); - hql.append(" set "); - Field[] fields = obj.getClass().getDeclaredFields(); - if (obj.getClass().getGenericSuperclass() != null) { - Field[] parentFields = obj.getClass().getSuperclass().getDeclaredFields(); - fields = concat(fields, parentFields); - } - for (Field field : fields) { - String name = field.getName(); - Method method = null; - Object value = null; - if (!contain(excludeProperties, name)) { - String upperName = name.substring(0, 1).toUpperCase() + name.substring(1); - try { - method = obj.getClass().getMethod("get" + upperName); - value = method.invoke(obj); - if (value != null) { - if (value instanceof String) { - hql.append(name); - hql.append("="); - hql.append("'"); - hql.append(value); - hql.append("'"); - hql.append(","); - } else { - hql.append(name); - hql.append("="); - hql.append(value); - hql.append(","); - } - } - } catch (Exception e1) { - logger.error("error while creating update hql", e1); - } - } - } - - String sql = hql.toString(); - sql = sql.substring(0, sql.lastIndexOf(",")); - if (filter != null) { - sql = sql + " where " + filter; - } - logger.info("update hql is : " + sql); - return sql; - } - - /** - * judge wether target contains src. - * @param src String[] - * @param target String - * @return boolean - */ - public static boolean contain(String[] src, String target) { - if (src == null || src.length == 0 || target == null) { - return false; - } else { - for (String str : src) { - if(str.equals(target)){ - return true; - } - } - } - return false; - } - - /** - * concat two array. - * @param first first array - * @param second second array - * @return T - */ - public static <T> T[] concat(T[] first, T[] second) { - T[] result = Arrays.copyOf(first, first.length + second.length); - System.arraycopy(second, 0, result, first.length, second.length); - return result; - } - - public static String getOidFilter(String key, String value) { - return key + "= '" + value + "'"; - } - - /** - * get query hql. - * @param data Object - * @param column String - * @return String - */ - public static String getQueryHql(Object data, String column) { - StringBuffer hql = new StringBuffer(); - String objName = data.getClass().getSimpleName(); - hql.append("select q."); - hql.append(column); - hql.append(" from "); - hql.append(objName); - hql.append(" as q where "); - Field[] fields = data.getClass().getDeclaredFields(); - if (data.getClass().getGenericSuperclass() != null) { - Field[] parentFields = data.getClass().getSuperclass().getDeclaredFields(); - fields = concat(fields, parentFields); - } - for (Field field : fields) { - String name = field.getName(); - Method method = null; - Object value = null; - String upperName = name.substring(0, 1).toUpperCase() + name.substring(1); - try { - method = data.getClass().getMethod("get" + upperName); - value = method.invoke(data); - if (value != null) { - if (value instanceof String) { - hql.append("q." + name); - hql.append("="); - hql.append("'"); - hql.append(value); - hql.append("'"); - hql.append(" and "); - } else { - hql.append("q." + name); - hql.append("="); - hql.append(value); - hql.append("and "); - } - } - } catch (Exception e1) { - logger.error("error while creating update hql", e1); - } - } - String sql = hql.toString(); - sql = sql.substring(0, sql.lastIndexOf("and")); - - logger.info("query hql is : " + sql); - return sql.trim(); - } - - public static String getQueryHqlByFilter(Class mainObject, Object filterData, String foreignKey) { - StringBuffer hql = new StringBuffer(); - String objName = mainObject.getSimpleName(); - // hql.append("select queryTable."); - hql.append(" from "); - hql.append(objName); - hql.append(" as a where "); - String filterHql = getQueryHql(filterData, foreignKey); - hql.append("a." + foreignKey); - hql.append(" in("); - hql.append(filterHql); - hql.append(")"); - logger.info("QueryHqlByFilter is : " + hql); - return hql.toString(); - } - - public static String getDeleteHqlByFilter(Class mainObject, Object filterData, String foreignKey) { - StringBuffer hql = new StringBuffer(); - String objName = mainObject.getSimpleName(); - hql.append("delete from "); - hql.append(objName); - hql.append(" as b where "); - String filterHql = getQueryHql(filterData, foreignKey); - hql.append("b." + foreignKey); - hql.append(" in("); - hql.append(filterHql); - hql.append(")"); - logger.info("DeleteHqlByFilter is : " + hql); - return hql.toString(); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/BaseHandler.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/BaseHandler.java deleted file mode 100644 index 276b1c6a..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/BaseHandler.java +++ /dev/null @@ -1,212 +0,0 @@ -/** - * 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.db.wrapper; - -import com.google.gson.Gson; - -import org.openo.commontosca.catalog.db.dao.BaseDao; -import org.openo.commontosca.catalog.db.dao.DaoManager; -import org.openo.commontosca.catalog.db.entity.BaseData; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.util.CatalogDbUtil; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.Map; - - - -/** - * an abstract class for NFV wrapper class. - * provide the common methods to process the CRUD rest request. - * - */ -public abstract class BaseHandler<T extends BaseData> { - private static final Logger logger = LoggerFactory.getLogger(BaseHandler.class); - - public Gson gson = new Gson(); - - /** - * create date. - * @param data data to create - * @param resouceType resouce type - * @return T - * @throws CatalogResourceException e1 - */ - @SuppressWarnings({"unchecked", "rawtypes"}) - public T create(T data, String resouceType) throws CatalogResourceException { - T rtnData = null; - logger.info("BaseHandler:start create data.info:" + CatalogDbUtil.objectToString(data)); - try { - check(data); - BaseDao dao = DaoManager.getInstance().getDao(resouceType); - rtnData = (T) dao.create(data); - } catch (CatalogResourceException e1) { - logger.error("BaseHandler:error while creating " + resouceType, e1); - throw e1; - } - logger.info("BaseHandler:create data end.info:" + CatalogDbUtil.objectToString(data)); - return rtnData; - } - - /** - * delete data. - * @param data data to delete - * @param resouceType resource type - * @throws CatalogResourceException e1 - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public void delete(T data, String resouceType) throws CatalogResourceException { - logger.info("BaseHandler:start delete data.info:" + CatalogDbUtil.objectToString(data)); - try { - BaseDao dao = DaoManager.getInstance().getDao(resouceType); - dao.delete(data); - } catch (CatalogResourceException e1) { - logger.error("BaseHandler:error while deleting " + resouceType, e1); - throw e1; - } - logger.info("BaseHandler:delete data end"); - } - - /** - * delete data. - * @param queryParam query param - * @param resouceType String - * @throws CatalogResourceException e1 - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public void delete(Map<String, String> queryParam, String resouceType) - throws CatalogResourceException { - logger.info("BaseHandler:start delete data by condition.info:" - + CatalogDbUtil.objectToString(queryParam)); - List<T> datas; - try { - BaseDao dao = DaoManager.getInstance().getDao(resouceType); - datas = dao.query(queryParam); - for (T data : datas) { - delete(data, resouceType); - } - } catch (CatalogResourceException e1) { - logger.error("BaseHandler:error while deleting " + resouceType, e1); - throw e1; - } - - } - - /** - * update data. - * @param data data to update - * @param filter filter - * @param resouceType resource type - * @throws CatalogResourceException e1 - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public void update(T data, String filter, String resouceType) throws CatalogResourceException { - logger.info("BaseHandler:start update data .info:" + CatalogDbUtil.objectToString(data) - + " filter:" + filter); - try { - check(data); - BaseDao dao = DaoManager.getInstance().getDao(resouceType); - dao.update(data, filter); - - } catch (CatalogResourceException e1) { - logger.error("BaseHandler:error while updating " + resouceType, e1); - throw e1; - } - logger.info("BaseHandler:update data end "); - } - - /** - * query data. - * @param queryParam query parameter - * @param resouceType resource type - * @return T list - * @throws CatalogResourceException e1 - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public List<T> query(Map<String, String> queryParam, String resouceType) - throws CatalogResourceException { - logger.info("BaseHandler:start query data .info:" + CatalogDbUtil.objectToString(queryParam)); - List<T> datas = null; - try { - BaseDao dao = DaoManager.getInstance().getDao(resouceType); - datas = dao.query(queryParam); - - } catch (CatalogResourceException e1) { - logger.error("BaseHandler:error while querying " + resouceType, e1); - throw e1; - } - logger.info("BaseHandler: query data end .info:" + CatalogDbUtil.objectToString(datas)); - return datas; - } - - /** - * union query. - * @param filter filter - * @param resouceType resource type - * @return T list - * @throws CatalogResourceException e1 - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public List<T> unionQuery(String filter, String resouceType) throws CatalogResourceException { - logger.info("BaseHandler:start union query data.fliter:" + filter); - List<T> datas = null; - try { - BaseDao dao = DaoManager.getInstance().getDao(resouceType); - datas = dao.unionQuery(filter); - - } catch (CatalogResourceException e1) { - logger.error("BaseHandler:error while union querying " + resouceType, e1); - throw e1; - } - logger.info("BaseHandler:union query data end .info:" + CatalogDbUtil.objectToString(datas)); - return datas; - } - - /** - * union delete. - * @param filter filter - * @param resouceType resource type - * @return int - * @throws CatalogResourceException e1 - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - public int unionDelete(String filter, String resouceType) throws CatalogResourceException { - logger.info("BaseHandler:start delete query data.fliter:" + filter); - int num; - try { - BaseDao dao = DaoManager.getInstance().getDao(resouceType); - num = dao.unionDelete(filter); - - } catch (CatalogResourceException e1) { - logger.error("BaseHandler:error while union delete " + resouceType, e1); - throw e1; - } - logger.info("BaseHandler:union delete data end .num:" + num); - return num; - } - - /** - * check if the related object id exists in the system. - * - * @param data data to check - * @throws CatalogResourceException e - */ - public abstract void check(T data) throws CatalogResourceException; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/NodeTemplateHandler.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/NodeTemplateHandler.java deleted file mode 100644 index 4ee455bf..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/NodeTemplateHandler.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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.db.wrapper; - -import org.openo.commontosca.catalog.db.common.CatalogResuorceType; -import org.openo.commontosca.catalog.db.entity.NodeTemplateData; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Map; - -public class NodeTemplateHandler extends BaseHandler<NodeTemplateData> { - private static final Logger logger = LoggerFactory.getLogger(NodeTemplateHandler.class); - - /** - * query node template. - * @param queryParam query parameter - * @return NodeTemplateData list - * @throws CatalogResourceException e - */ - public ArrayList<NodeTemplateData> query(Map<String, String> queryParam) - throws CatalogResourceException { - logger.info("NodeTemplateHandler query nodeTemplate info."); - ArrayList<NodeTemplateData> data = new ArrayList<NodeTemplateData>(); - Object result = query(queryParam, CatalogResuorceType.NODETEMPLATE.name()); - if (result != null) { - data = (ArrayList<NodeTemplateData>) result; - } else { - logger.warn("NodeTemplateHandler: query nodeTemplate info is null."); - } - logger.info("NodeTemplateHandler: query nodeTemplate info end."); - return data; - - } - - @Override - public void check(NodeTemplateData nodeTemplateData) throws CatalogResourceException { - - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/PackageHandler.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/PackageHandler.java deleted file mode 100644 index 2ec747d0..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/PackageHandler.java +++ /dev/null @@ -1,159 +0,0 @@ -/** - * 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.db.wrapper; - -import org.openo.commontosca.catalog.db.common.CatalogResuorceType; -import org.openo.commontosca.catalog.db.common.Parameters; -import org.openo.commontosca.catalog.db.entity.PackageData; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.util.CatalogDbUtil; -import org.openo.commontosca.catalog.db.util.HqlFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Map; - -public class PackageHandler extends BaseHandler<PackageData> { - private static final Logger logger = LoggerFactory.getLogger(PackageHandler.class); - - /** - * create package data. - * @param packageData package data to create - * @return PackageData - * @throws CatalogResourceException e1 - */ - public PackageData create(PackageData packageData) throws CatalogResourceException { - logger.info("packageHandler:start create package info."); - PackageData data = null; - if (!CatalogDbUtil.isNotEmpty(packageData.getCsarId())) { - - logger.info("packageHandler:package info does not have csarid,generate UUID."); - String id = CatalogDbUtil.generateId(); - packageData.setCsarId(id); - } - Object result = create(packageData, CatalogResuorceType.PACKAGE.name()); - if (result != null) { - data = (PackageData) result; - } else { - logger.info("packageHandler: query package info is null."); - } - logger.info("packageHandler: create package info end."); - return data; - } - - /** - * delete data. - * @param id package id - * @throws CatalogResourceException e - */ - public void delete(String id) throws CatalogResourceException { - logger.info("packageHandler:start delete package info."); - PackageData packageData = new PackageData(); - packageData.setCsarId(id); - delete(packageData, CatalogResuorceType.PACKAGE.name()); - logger.info("packageHandler: delete package info end."); - } - - /** - * delete data. - * @param queryParam query parameter - * @throws CatalogResourceException e - */ - public void delete(Map<String, String> queryParam) throws CatalogResourceException { - logger.info("packageHandler:start delete package info."); - delete(queryParam, CatalogResuorceType.PACKAGE.name()); - logger.info("packageHandler:delete package info end."); - } - - /** - * update data. - * @param packageData packate data to update - * @param id package id - * @throws CatalogResourceException e - */ - public void update(PackageData packageData, String id) throws CatalogResourceException { - // HostData host = gson.fromJson(hostJson, HostData.class); - logger.info("packageHandler:start update package info."); - update(packageData, HqlFactory.getOidFilter(Parameters.csarId.name(), id), - CatalogResuorceType.PACKAGE.name()); - logger.info("packageHandler:update package info end."); - } - - /** - * union delete. - * @param filter delete filter - * @return int - * @throws CatalogResourceException e - */ - public int unionDelete(String filter) throws CatalogResourceException { - logger.info("packageHandler delete package info by union.filter:" + filter); - int num = 0; - Object result = unionDelete(filter, CatalogResuorceType.PACKAGE.name()); - if (result != null) { - num = (int) result; - } else { - logger.warn("packageHandler: delete package info is null."); - } - logger.info("packageHandler: delete package info end.num:" + num); - return num; - } - - /** - * union query. - * @param filter query filter - * @return PackageData list - * @throws CatalogResourceException e - */ - public ArrayList<PackageData> unionQuery(String filter) throws CatalogResourceException { - logger.info("packageHandler query package info by union.filter:" + filter); - ArrayList<PackageData> data = new ArrayList<PackageData>(); - Object result = unionQuery(filter, CatalogResuorceType.PACKAGE.name()); - if (result != null) { - data = data = (ArrayList<PackageData>) result; - } else { - logger.info("packageHandler: query package info is null."); - } - logger.info("packageHandler: query package info end"); - return data; - } - - /** - * query package data by map. - * @param queryParam map data - * @return PackageData list - * @throws CatalogResourceException e - */ - public ArrayList<PackageData> query(Map<String, String> queryParam) - throws CatalogResourceException { - logger.info("packageHandler:start query package info."); - ArrayList<PackageData> data = new ArrayList<PackageData>(); - Object result = query(queryParam, CatalogResuorceType.PACKAGE.name()); - if (result != null) { - data = (ArrayList<PackageData>) result; - } else { - logger.info("packageHandler: query package info is null."); - } - logger.info("packageHandler: query package info end."); - return data; - } - - @Override - public void check(PackageData packageData) throws CatalogResourceException { - - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/ServiceTemplateHandler.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/ServiceTemplateHandler.java deleted file mode 100644 index 8d7d2a1b..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/ServiceTemplateHandler.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * 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.db.wrapper; - -import org.openo.commontosca.catalog.db.common.CatalogResuorceType; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; -import org.openo.commontosca.catalog.db.entity.TemplateData; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Map; - -public class ServiceTemplateHandler extends BaseHandler<TemplateData> { - private static final Logger logger = LoggerFactory.getLogger(ServiceTemplateHandler.class); - - @Override - public void check(TemplateData data) throws CatalogResourceException { - // TODO Auto-generated method stub - - } - - /** - * query service template data by map. - * @param queryParam map data - * @return ServiceTemplateData list - * @throws CatalogResourceException e - */ - public ArrayList<ServiceTemplateData> query(Map<String, String> queryParam) - throws CatalogResourceException { - logger.info("ServiceTemplateHandler query serviceTemplate info."); - ArrayList<ServiceTemplateData> data = new ArrayList<ServiceTemplateData>(); - Object result = query(queryParam, CatalogResuorceType.SERVICETEMPLATE.name()); - if (result != null) { - data = (ArrayList<ServiceTemplateData>) result; - } else { - logger.info("ServiceTemplateHandler: query serviceTemplate info is null."); - } - logger.info("ServiceTemplateHandler: query serviceTemplate info end."); - return data; - } - - /** - * query service template by union query. - * @param filter query filter - * @return ServiceTemplateData list - * @throws CatalogResourceException e - */ - public ArrayList<ServiceTemplateData> unionQuery(String filter) throws CatalogResourceException { - logger.info("ServiceTemplateHandler query serviceTemplate info by union.filter:" + filter); - ArrayList<ServiceTemplateData> data = new ArrayList<ServiceTemplateData>(); - Object result = unionQuery(filter, CatalogResuorceType.SERVICETEMPLATE.name()); - if (result != null) { - data = (ArrayList<ServiceTemplateData>) result; - } else { - logger.info("ServiceTemplateHandler: query serviceTemplate info is null."); - } - logger.info("ServiceTemplateHandler: query serviceTemplate info end."); - return data; - } - - /** - * union delete. - * @param filter delete filter - * @return int - * @throws CatalogResourceException e - */ - public int unionDelete(String filter) throws CatalogResourceException { - logger.info("ServiceTemplateHandler delete serviceTemplate info by union.filter:" + filter); - int num = 0; - Object result = unionDelete(filter, CatalogResuorceType.SERVICETEMPLATE.name()); - if (result != null) { - num = (int) result; - } else { - logger.info("ServiceTemplateHandler: delete serviceTemplate info is null."); - } - logger.info("ServiceTemplateHandler: delete serviceTemplate info end.num:" + num); - return num; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/ServiceTemplateMappingHandler.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/ServiceTemplateMappingHandler.java deleted file mode 100644 index dfa16f5d..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/ServiceTemplateMappingHandler.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * 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.db.wrapper; - -import org.openo.commontosca.catalog.db.common.CatalogResuorceType; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.util.CatalogDbUtil; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Map; - - -public class ServiceTemplateMappingHandler extends BaseHandler<ServiceTemplateMappingData> { - private static final Logger logger = LoggerFactory.getLogger(ServiceTemplateMappingHandler.class); - - /** - * create service template data. - * @param serviceTemplateMappingData service template maping data - * @return ServiceTemplateMappingData - * @throws CatalogResourceException e - */ - public ServiceTemplateMappingData create(ServiceTemplateMappingData serviceTemplateMappingData) - throws CatalogResourceException { - logger.info("ServiceTemplateMappingHandler:start create serviceTemplateMapping info."); - ServiceTemplateMappingData data = null; - if (!CatalogDbUtil.isNotEmpty(serviceTemplateMappingData.getMappingId())) { - logger.info( - "ServiceTemplateMappingHandler:mapping info " + "does not have mappingId,generate UUID."); - String id = CatalogDbUtil.generateId(); - serviceTemplateMappingData.setMappingId(id); - } - Object result = - create(serviceTemplateMappingData, CatalogResuorceType.SERVICETEMPLATEMAPPING.name()); - if (result != null) { - data = (ServiceTemplateMappingData) result; - } else { - logger.info("ServiceTemplateMappingHandler: query mapping info is null."); - } - logger.info("ServiceTemplateMappingHandler: create mapping info end."); - return data; - } - - /** - * delete data by id. - * @param id service template id - * @throws CatalogResourceException e - */ - public void delete(String id) throws CatalogResourceException { - logger.info("ServiceTemplateMappingHandler:start delete mapping info."); - ServiceTemplateMappingData serviceTemplateMappingData = new ServiceTemplateMappingData(); - serviceTemplateMappingData.setMappingId(id); - delete(serviceTemplateMappingData, CatalogResuorceType.SERVICETEMPLATEMAPPING.name()); - logger.info("ServiceTemplateMappingHandler: delete mapping info end."); - } - - /** - * delete data. - * @param delParam delete data according to delParam - * @throws CatalogResourceException e - */ - public void delete(Map<String, String> delParam) throws CatalogResourceException { - logger.info("ServiceTemplateMappingHandler:start delete mapping info."); - delete(delParam, CatalogResuorceType.SERVICETEMPLATEMAPPING.name()); - logger.info("ServiceTemplateMappingHandler:delete mapping info end."); - } - - /** - * query service template mapping data. - * @param queryParam query map - * @return ServiceTemplateMappingData list - * @throws CatalogResourceException e - */ - public ArrayList<ServiceTemplateMappingData> query(Map<String, String> queryParam) - throws CatalogResourceException { - logger.info("ServiceTemplateMappingHandler:start query mapping info."); - ArrayList<ServiceTemplateMappingData> data = new ArrayList<ServiceTemplateMappingData>(); - Object result = query(queryParam, CatalogResuorceType.SERVICETEMPLATEMAPPING.name()); - if (result != null) { - data = (ArrayList<ServiceTemplateMappingData>) result; - } else { - logger.info("ServiceTemplateMappingHandler: query mapping info is null."); - } - logger.info("ServiceTemplateMappingHandler: query mapping info end."); - return data; - - } - - @Override - public void check(ServiceTemplateMappingData data) throws CatalogResourceException { - // TODO Auto-generated method stub - - } - - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/TemplateHandler.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/TemplateHandler.java deleted file mode 100644 index 43b8ae64..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/db/wrapper/TemplateHandler.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * 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.db.wrapper; - -import org.openo.commontosca.catalog.db.common.CatalogResuorceType; -import org.openo.commontosca.catalog.db.entity.NodeTemplateData; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; -import org.openo.commontosca.catalog.db.entity.TemplateData; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.util.CatalogDbUtil; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; - -public class TemplateHandler extends BaseHandler<TemplateData> { - private static final Logger logger = LoggerFactory.getLogger(TemplateHandler.class); - - /** - * create template data. - * @param templateData template data to create - * @return TemplateData - * @throws CatalogResourceException e - */ - public TemplateData create(TemplateData templateData) throws CatalogResourceException { - logger.info("TemplateHandler create template info."); - TemplateData data = null; - String serviceTemplateOid = templateData.getServiceTemplate().getServiceTemplateId(); - if (!CatalogDbUtil.isNotEmpty(serviceTemplateOid)) { - logger.info("TemplateHandler:template info does not have oid,generate UUID."); - serviceTemplateOid = CatalogDbUtil.generateId(); - templateData.getServiceTemplate().setServiceTemplateId(serviceTemplateOid); - } - for (NodeTemplateData nodeData : templateData.getNodeTemplates()) { - String nodeTemplateOid = nodeData.getNodeTemplateId(); - if (!CatalogDbUtil.isNotEmpty(nodeTemplateOid)) { - logger.info("TemplateHandler:nodeTemplate info does not have id,generate UUID."); - nodeData.setNodeTemplateId(CatalogDbUtil.generateId()); - } - nodeData.setServiceTemplateId(serviceTemplateOid); - } - Object result = create(templateData, CatalogResuorceType.TEMPLATE.name()); - if (result != null) { - data = (TemplateData) result; - } else { - logger.info("TemplateHandler: query template info is null."); - } - logger.info("TemplateHandler: create template info end."); - return data; - } - - @Override - public void check(TemplateData data) throws CatalogResourceException { - // TODO Auto-generated method stub - - } - - /** - * delete node template. - * @param serviceTemplateId service template id - * @param nodeTemplateList node template list - * @throws CatalogResourceException e - */ - public void delete(String serviceTemplateId, ArrayList<NodeTemplateData> nodeTemplateList) - throws CatalogResourceException { - logger.info("TemplateHandler delete Template info."); - TemplateData templateData = new TemplateData(); - ServiceTemplateData serviceTemplateData = new ServiceTemplateData(); - serviceTemplateData.setServiceTemplateId(serviceTemplateId); - templateData.setServiceTemplate(serviceTemplateData); - templateData.setNodeTemplates(nodeTemplateList); - delete(templateData, CatalogResuorceType.TEMPLATE.name()); - logger.info("TemplateHandler: delete Template info end."); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/CsarPackage.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/CsarPackage.java deleted file mode 100644 index bf7a2d3d..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/CsarPackage.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * 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.entity; - -public class CsarPackage { - private String id; - private String name; - private String createTime; - private String size; - private String status; - private String deletionPending; - private String format; - private String url; - private String type; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getFormat() { - return format; - } - - public void setFormat(String format) { - this.format = format; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDeletionPending() { - return deletionPending; - } - - public void setDeletionPending(String deletionPending) { - this.deletionPending = deletionPending; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getCreateTime() { - return createTime; - } - - public void setCreateTime(String createTime) { - this.createTime = createTime; - } - - public String getSize() { - return size; - } - - public void setSize(String size) { - this.size = size; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/CsarQueryCondition.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/CsarQueryCondition.java deleted file mode 100644 index 5e3ba2ab..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/CsarQueryCondition.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class CsarQueryCondition { - - private String csarId; - - private String name; - - private String provider; - - private String version; - - private Boolean deletionPending; - - private EnumType type; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumOnboardState.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumOnboardState.java deleted file mode 100644 index d89c31a6..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumOnboardState.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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.entity; - -public enum EnumOnboardState { - onBoarded("onBoarded"), nonOnBoarded("non-onBoarded"); - - String value; - - EnumOnboardState(String value) { - this.value = value; - } - - public String getValue() { - return value; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumOperationalState.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumOperationalState.java deleted file mode 100644 index 3294d25e..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumOperationalState.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * 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.entity; - -public enum EnumOperationalState { - Enabled, Disabled -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumProcessState.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumProcessState.java deleted file mode 100644 index ef1a59d5..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumProcessState.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * 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.entity; - -public enum EnumProcessState { - normal, onBoarding, onBoardFailed, deleting, deleteFailed -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumType.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumType.java deleted file mode 100644 index 969c18c0..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumType.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * 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.entity; - -public enum EnumType { - GSAR, SSAR, NSAR, NFAR -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumUsageState.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumUsageState.java deleted file mode 100644 index c5766ff6..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/EnumUsageState.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * 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.entity; - -public enum EnumUsageState { - InUse, NotInUse -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/VnfPackage.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/VnfPackage.java deleted file mode 100644 index afbd9a43..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/VnfPackage.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * 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.entity; - -public class VnfPackage { - private String vnfPackageId; - private String name; - private String version; - private String provider; - private String vnfd; - private EnumOperationalState operationalState = EnumOperationalState.Disabled; - private EnumUsageState usageState = EnumUsageState.InUse; - private String deletionPending; - private String vnfPackageUrl; - - public String getVnfPackageId() { - return vnfPackageId; - } - - public void setVnfPackageId(String vnfPackageId) { - this.vnfPackageId = vnfPackageId; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getProvider() { - return provider; - } - - public void setProvider(String provider) { - this.provider = provider; - } - - public String getVnfd() { - return vnfd; - } - - public void setVnfd(String vnfd) { - this.vnfd = vnfd; - } - - public EnumOperationalState getOperationalState() { - return operationalState; - } - - public void setOperationalState(EnumOperationalState operationalState) { - this.operationalState = operationalState; - } - - public EnumUsageState getUsageState() { - return usageState; - } - - public void setUsageState(EnumUsageState usageState) { - this.usageState = usageState; - } - - public String getVnfPackageUrl() { - return vnfPackageUrl; - } - - public void setVnfPackageUrl(String vnfPackageUrl) { - this.vnfPackageUrl = vnfPackageUrl; - } - - public String getDeletionPending() { - return deletionPending; - } - - public void setDeletionPending(String deletionPending) { - this.deletionPending = deletionPending; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/request/PackageBasicInfo.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/request/PackageBasicInfo.java deleted file mode 100644 index 0ff5b2f7..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/request/PackageBasicInfo.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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.entity.request; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import org.openo.commontosca.catalog.entity.EnumType; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class PackageBasicInfo { - - private String provider; - - private EnumType type; - - private String version; - - private String format; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/CsarFileUriResponse.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/CsarFileUriResponse.java deleted file mode 100644 index a9e1b0c6..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/CsarFileUriResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * 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.entity.response; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class CsarFileUriResponse { - - private String downloadUri; - - private String localPath; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/PackageMeta.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/PackageMeta.java deleted file mode 100644 index aba10a1d..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/PackageMeta.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * 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.entity.response; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import org.openo.commontosca.catalog.entity.EnumOperationalState; -import org.openo.commontosca.catalog.entity.EnumProcessState; -import org.openo.commontosca.catalog.entity.EnumUsageState; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class PackageMeta { - - private String csarId; - - private String name; - - private String downloadUri; - - private String size; - - private String version; - - private String provider; - - private String type; - - private String format; - - private boolean deletionPending; - - private String createTime; - - private String modifyTime; - - private EnumOperationalState operationalState; - - private EnumUsageState usageState; - - private String onBoardState; - - private EnumProcessState processState; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/UploadPackageResponse.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/UploadPackageResponse.java deleted file mode 100644 index d1ec09bf..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/entity/response/UploadPackageResponse.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * 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.entity.response; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class UploadPackageResponse { - - private String csarId; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/ApiRouteInfo.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/ApiRouteInfo.java deleted file mode 100644 index d98af250..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/ApiRouteInfo.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * 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.externalservice.msb; - -import java.io.Serializable; - -public class ApiRouteInfo implements Serializable { - private static final long serialVersionUID = 1L; - private String serviceName; - private String version = ""; - private String url; - private String apiJson = ""; - private String apiJsonType = "1"; - private String metricsUrl = ""; - private String control = "0"; - private String status = "1"; - - private RouteServer []servers; - - - public String getServiceName() { - return serviceName; - } - - public void setServiceName(String serviceName) { - this.serviceName = serviceName; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getApiJson() { - return apiJson; - } - - public void setApiJson(String apiJson) { - this.apiJson = apiJson; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public RouteServer[] getServers() { - return servers; - } - - public void setServers(RouteServer[] servers) { - this.servers = servers; - } - - public String getApiJsonType() { - return apiJsonType; - } - - public void setApiJsonType(String apiJsonType) { - this.apiJsonType = apiJsonType; - } - - public String getMetricsUrl() { - return metricsUrl; - } - - public void setMetricsUrl(String metricsUrl) { - this.metricsUrl = metricsUrl; - } - - public String getControl() { - return control; - } - - public void setControl(String control) { - this.control = control; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/MicroserviceBusConsumer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/MicroserviceBusConsumer.java deleted file mode 100644 index 6732d6e5..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/MicroserviceBusConsumer.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * 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.externalservice.msb; - -import com.eclipsesource.jaxrs.consumer.ConsumerFactory; -import org.glassfish.jersey.client.ClientConfig; - -import org.openo.commontosca.catalog.common.Config; -import org.openo.commontosca.catalog.db.util.CatalogDbUtil; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class MicroserviceBusConsumer { - private static final Logger LOG = LoggerFactory.getLogger(MicroserviceBusConsumer.class); - - /** - * register service to MSB. - * - * @param entity ServiceRegisterEntity - * @return boolean - */ - public static boolean registerService(ServiceRegisterEntity entity) { - ClientConfig config = new ClientConfig(); - LOG.info("microservice register body:" + CatalogDbUtil.objectToString(entity)); - try { - MicroserviceBusRest resourceserviceproxy = ConsumerFactory.createConsumer( - Config.getConfigration().getMsbServerAddr(), config, MicroserviceBusRest.class); - resourceserviceproxy.registerServce("false", entity); - } catch (Exception e1) { - LOG.error("microservice register failed!" + e1.getMessage()); - return false; - } - return true; - } - - public static ApiRouteInfo queryApiRouteInfo(String serviceName, String version) { - ClientConfig config = new ClientConfig(); - LOG.info("microservice register body:" + "serviceName:" + serviceName + " version:" + version); - ApiRouteInfo apiRouteInfo = null; - try { - MicroserviceBusRest resourceserviceproxy = ConsumerFactory.createConsumer( - Config.getConfigration().getMsbServerAddr(), config, MicroserviceBusRest.class); - apiRouteInfo = resourceserviceproxy.queryApiRouteInfo(serviceName, version); - } catch (Exception e1) { - LOG.error("query api route failed!" + e1.getMessage()); - - } - return apiRouteInfo; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/MicroserviceBusRest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/MicroserviceBusRest.java deleted file mode 100644 index 51a5971d..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/MicroserviceBusRest.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.externalservice.msb; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - -@Path("/openoapi/microservices/v1/services") -// @Path("/api/microservices/v1/services") -public interface MicroserviceBusRest { - @Path("") - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate, - ServiceRegisterEntity entity) throws Exception; - - @Path("") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public ApiRouteInfo queryApiRouteInfo(@PathParam("serviceName") String serviceName, - @PathParam("version") String version ) throws Exception; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/RouteServer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/RouteServer.java deleted file mode 100644 index 8aa22a0d..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/RouteServer.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.externalservice.msb; - -import java.io.Serializable; - -public class RouteServer implements Serializable { - private static final long serialVersionUID = 1L; - private String ip; - private int weight; - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } - - - - public int getWeight() { - return weight; - } - - public void setWeight(int weight) { - this.weight = weight; - } - - public RouteServer() { - - } - - public RouteServer(String ip) { - this.ip = ip; - this.weight = 0; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/ServiceNode.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/ServiceNode.java deleted file mode 100644 index 55195e8e..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/ServiceNode.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.externalservice.msb; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -public class ServiceNode { - private String ip; - private String port; - private int ttl; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/ServiceRegisterEntity.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/ServiceRegisterEntity.java deleted file mode 100644 index 7732437a..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/externalservice/msb/ServiceRegisterEntity.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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.externalservice.msb; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.ArrayList; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -public class ServiceRegisterEntity { - private String serviceName; - private String version; - private String url; - private String protocol; - private String visualRange; - private ArrayList<ServiceNode> nodes = new ArrayList<ServiceNode>(); - - /** - * set single node. - * @param ip ip - * @param port port - * @param ttl ttl - */ - public void setSingleNode(String ip, String port, int ttl) { - ServiceNode node = new ServiceNode(); - if (ip != null && ip.length() > 0) { - node.setIp(ip); - } else { - node.setIp(null); - } - node.setPort(port); - node.setTtl(ttl); - nodes.add(node); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManager.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManager.java deleted file mode 100644 index 1965ee01..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManager.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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.filemanage; - - -public interface FileManager { - - /** - * package upload api. - * @param srcPath source path - * @param dstPath/packageType/provider/packageName/version - * @return boolean - */ - boolean upload(String srcPath, String dstPath); - - boolean download(String srcPath, String dstPath); - - boolean delete(String srcPath); - - //ArrayList<FileLink> queryWorkFlow(String path); - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManagerFactory.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManagerFactory.java deleted file mode 100644 index 8030ea92..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManagerFactory.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.filemanage; - -import org.openo.commontosca.catalog.filemanage.http.HttpFileManagerImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FileManagerFactory { - private static final Logger logger = LoggerFactory.getLogger(FileManagerFactory.class); - - private static FileManager getHttpFileManager() { - return new HttpFileManagerImpl(); - } - - /** - * create file manager. - * @return FileManager - */ - public static FileManager createFileManager() { - switch (getType()) { - case http: - return getHttpFileManager(); - case ftp: - return null; - default: - return getHttpFileManager(); - } - } - - private static FileManagerType getType() { - String type = System.getenv("useFtp"); - logger.info("read environment varibale uesFtp:" + type); - if (type != null && "true".equals(type)) { - return FileManagerType.ftp; - } else { - return FileManagerType.http; - } - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManagerType.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManagerType.java deleted file mode 100644 index f238e438..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/FileManagerType.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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.filemanage; - -public enum FileManagerType { - ftp, http; - public static FileManagerType getType(String type) { - return valueOf(type); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/HttpFileManagerImpl.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/HttpFileManagerImpl.java deleted file mode 100644 index 0d3df052..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/HttpFileManagerImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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.filemanage.http; - -import org.openo.commontosca.catalog.filemanage.FileManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.IOException; - - -public class HttpFileManagerImpl implements FileManager { - private static final Logger LOGGER = LoggerFactory.getLogger(HttpFileManagerImpl.class); - - @Override - public boolean upload(String srcPath, String dstPath) { - boolean flag = true; - LOGGER.info("start upload file.srcPath:" + srcPath + " dstPath" + dstPath); - File srcFile = new File(srcPath); - if (!srcFile.exists()) { - LOGGER.error("src file not exist!"); - return false; - } - // File dstFile = new File(ToolUtil.getHttpServerPath() + dstPath); - // LOGGER.info("dstFile AbsolutePath:" + dstFile.getAbsolutePath()); - String targetDir = ToolUtil.getHttpServerAbsolutePath() + dstPath; - try { - ToolUtil.copyDirectory(srcPath, targetDir, true); - } catch (IOException e1) { - flag = false; - LOGGER.error("copy file failed.errorMsg:" + e1.getMessage()); - } - LOGGER.info("upload file success!"); - return flag; - } - - @Override - public boolean download(String srcPath, String dstPath) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean delete(String srcPath) { - boolean flag = true; - LOGGER.info("start delete file from http server.srcPath:" + srcPath); - flag = ToolUtil.deleteDir(new File(ToolUtil.getHttpServerAbsolutePath() + srcPath)); - LOGGER.info("delete file from http server end.flag:" + flag); - return flag; - } - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/ToolUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/ToolUtil.java deleted file mode 100644 index d2fd8393..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/filemanage/http/ToolUtil.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * 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.filemanage.http; - -import org.openo.commontosca.catalog.common.HttpServerPathConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - - -public class ToolUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(ToolUtil.class); - - /** - * copy from directory. - * @param srcDirName source directory name - * @param destDirName destination directory name - * @param overlay overwrite or not - * @return boolean - * @throws IOException e - */ - public static boolean copyDirectory(String srcDirName, String destDirName, boolean overlay) - throws IOException { - File srcDir = new File(srcDirName); - if (!srcDir.exists()) { - return false; - } else if (!srcDir.isDirectory()) { - return false; - } - - if (!destDirName.endsWith(File.separator)) { - destDirName = destDirName + File.separator; - } - File destDir = new File(destDirName); - if (destDir.exists()) { - if (overlay) { - new File(destDirName).delete(); - } else { - return false; - } - } else { - if (!destDir.mkdirs()) { - return false; - } - } - boolean flag = true; - File[] files = srcDir.listFiles(); - for (int i = 0; i < files.length; i++) { - if (files[i].isFile()) { - flag = copyFile(files[i].getAbsolutePath(), destDirName + files[i].getName(), true); - if (!flag) { - break; - } - } else if (files[i].isDirectory()) { - flag = copyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName(), overlay); - if (!flag) { - break; - } - } - } - if (!flag) { - String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!"; - LOGGER.error(message); - return false; - } else { - return true; - } - } - - /** - * copy file. - * @param srcFileName source file name - * @param destFileName target file name - * @param overlay overwrite or not - * @return boolean - */ - public static boolean copyFile(String srcFileName, String destFileName, boolean overlay) { - File srcFile = new File(srcFileName); - - if (!srcFile.exists()) { - String message = "Source file : " + srcFileName + " not exist !"; - LOGGER.error(message); - return false; - } else if (!srcFile.isFile()) { - return false; - } - - File destFile = new File(destFileName); - if (destFile.exists()) { - if (overlay) { - new File(destFileName).delete(); - } - } else { - if (!destFile.getParentFile().exists()) { - if (!destFile.getParentFile().mkdirs()) { - return false; - } - } - } - - int byteread = 0; - InputStream in = null; - OutputStream out = null; - - try { - in = new FileInputStream(srcFile); - out = new FileOutputStream(destFile); - byte[] buffer = new byte[1024]; - - while ((byteread = in.read(buffer)) != -1) { - out.write(buffer, 0, byteread); - } - return true; - } catch (FileNotFoundException e1) { - return false; - } catch (IOException e1) { - return false; - } finally { - try { - if (out != null) { - out.close(); - } - if (in != null) { - in.close(); - } - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } - - /** - * create directory. - * @param destDirName target directory name - * @return boolean - */ - public static boolean createDir(String destDirName) { - File dir = new File(destDirName); - if (dir.exists()) { - dir.delete(); - } - if (!destDirName.endsWith(File.separator)) { - destDirName = destDirName + File.separator; - } - if (dir.mkdirs()) { - return true; - } else { - return false; - } - } - - public static String getHttpServerAbsolutePath() { - return Class.class.getClass().getResource("/").getPath() + HttpServerPathConfig.getHttpServerPath(); - } - - /** - * delete directory. - * @param dir file to delete - * @return boolean - */ - public static boolean deleteDir(File dir) { - if (dir.isDirectory()) { - String[] children = dir.list(); - for (int i = 0; i < children.length; i++) { - boolean success = deleteDir(new File(dir, children[i])); - if (!success) { - return false; - } - } - } - return dir.delete(); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/ftp/Ftp.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/ftp/Ftp.java deleted file mode 100644 index 4318dcc5..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/ftp/Ftp.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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.ftp; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Ftp { - - private String ipAddr; - - private Integer port; - - private String userName; - - private String pwd; - - private String path; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/ftp/FtpUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/ftp/FtpUtil.java deleted file mode 100644 index 933871ae..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/ftp/FtpUtil.java +++ /dev/null @@ -1,206 +0,0 @@ -/** - * 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.ftp; - -import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPFile; -import org.apache.commons.net.ftp.FTPReply; -import org.apache.log4j.Logger; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -public class FtpUtil { - - private static Logger logger = Logger.getLogger(FtpUtil.class); - - private static FTPClient ftp; - - /** - * get ftp connection. - * - * @param conftp Ftp - * @return boolean - * @throws Exception e - */ - public static boolean connectFtp(Ftp conftp) throws Exception { - ftp = new FTPClient(); - boolean flag = false; - if (conftp.getPort() == null) { - ftp.connect(conftp.getIpAddr(), 21); - } else { - ftp.connect(conftp.getIpAddr(), conftp.getPort()); - } - ftp.login(conftp.getUserName(), conftp.getPwd()); - ftp.setFileType(FTPClient.BINARY_FILE_TYPE); - int reply = ftp.getReplyCode(); - if (!FTPReply.isPositiveCompletion(reply)) { - ftp.disconnect(); - return flag; - } - ftp.changeWorkingDirectory(conftp.getPath()); - flag = true; - return flag; - } - - /** - * close ftp connection. - */ - public static void closeFtp() { - if (ftp != null && ftp.isConnected()) { - try { - ftp.logout(); - ftp.disconnect(); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } - - /** - * upload file by ftp. - * - * @param file file to upload - * @throws Exception e - */ - public static void upload(File file) throws Exception { - if (file.isDirectory()) { - ftp.makeDirectory(file.getName()); - ftp.changeWorkingDirectory(file.getName()); - String[] files = file.list(); - for (String fstr : files) { - File file1 = new File(file.getPath() + "/" + fstr); - if (file1.isDirectory()) { - upload(file1); - ftp.changeToParentDirectory(); - } else { - File file2 = new File(file.getPath() + "/" + fstr); - FileInputStream input = new FileInputStream(file2); - ftp.storeFile(file2.getName(), input); - input.close(); - } - } - } else { - File file2 = new File(file.getPath()); - FileInputStream input = new FileInputStream(file2); - ftp.storeFile(file2.getName(), input); - input.close(); - } - } - - /** - * download inline config. - * - * @param downftp ftp to download - * @param localBaseDir local directory - * @param remoteBaseDir remote directory - * @throws Exception e - */ - public static void startDown(Ftp downftp, String localBaseDir, String remoteBaseDir) - throws Exception { - if (FtpUtil.connectFtp(downftp)) { - - try { - FTPFile[] files = null; - boolean changedir = ftp.changeWorkingDirectory(remoteBaseDir); - if (changedir) { - ftp.setControlEncoding("GBK"); - files = ftp.listFiles(); - for (int i = 0; i < files.length; i++) { - try { - downloadFile(files[i], localBaseDir, remoteBaseDir); - } catch (Exception e1) { - logger.error(e1); - logger.error("<" + files[i].getName() + ">download failed"); - } - } - } - } catch (Exception e1) { - logger.error(e1); - logger.error("error occoured while download"); - } - } else { - logger.error("Connect failed !"); - } - - } - - - /** - * download ftp file. - * - * @param ftpFile ftp file to download - * @param relativeLocalPath relative local path - * @param relativeRemotePath relative remote path - */ - private static void downloadFile(FTPFile ftpFile, String relativeLocalPath, - String relativeRemotePath) { - if (ftpFile.isFile()) { - if (ftpFile.getName().indexOf("?") == -1) { - OutputStream outputStream = null; - try { - File locaFile = new File(relativeLocalPath + ftpFile.getName()); - if (locaFile.exists()) { - return; - } else { - outputStream = new FileOutputStream(relativeLocalPath + ftpFile.getName()); - ftp.retrieveFile(ftpFile.getName(), outputStream); - outputStream.flush(); - outputStream.close(); - } - } catch (Exception e1) { - logger.error(e1); - } finally { - try { - if (outputStream != null) { - outputStream.close(); - } - } catch (IOException e1) { - logger.error("OutputStream error !"); - } - } - } - } else { - String newlocalRelatePath = relativeLocalPath + ftpFile.getName(); - String newRemote = new String(relativeRemotePath + ftpFile.getName().toString()); - File fl = new File(newlocalRelatePath); - if (!fl.exists()) { - fl.mkdirs(); - } - try { - newlocalRelatePath = newlocalRelatePath + '/'; - newRemote = newRemote + "/"; - String currentWorkDir = ftpFile.getName().toString(); - boolean changedir = ftp.changeWorkingDirectory(currentWorkDir); - if (changedir) { - FTPFile[] files = null; - files = ftp.listFiles(); - for (int i = 0; i < files.length; i++) { - downloadFile(files[i], newlocalRelatePath, newRemote); - } - } - if (changedir) { - ftp.changeToParentDirectory(); - } - } catch (Exception e1) { - logger.error(e1); - } - } - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/health/ConsoleHealthCheck.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/health/ConsoleHealthCheck.java deleted file mode 100644 index ed3fb5e6..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/health/ConsoleHealthCheck.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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.health; - -import com.codahale.metrics.health.HealthCheck; - -public class ConsoleHealthCheck extends HealthCheck { - private final String template; - - public ConsoleHealthCheck(String template) { - this.template = template; - } - - @Override - protected Result check() throws Exception { - final String saying = String.format(template, "TEST"); - if (!saying.contains("TEST")) { - return Result.unhealthy("template doesn't include a name"); - } - return Result.healthy(); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/EnumToscaNodeTypeDefinition.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/EnumToscaNodeTypeDefinition.java deleted file mode 100644 index 3c341094..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/EnumToscaNodeTypeDefinition.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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.model.common; - -public enum EnumToscaNodeTypeDefinition { - VNF { - @Override - public String getName() { - return "tosca.nodes.nfv.VNF"; - } - }, - VDU { - @Override - public String getName() { - return "tosca.nodes.nfv.VDU"; - } - }, - VNFC { - @Override - public String getName() { - return "tosca.nodes.nfv.VNFC"; - } - }, - VL { - @Override - public String getName() { - return "tosca.nodes.nfv.VL"; - } - }, - CP { - @Override - public String getName() { - return "tosca.nodes.nfv.CP"; - } - }; - - public abstract String getName(); - - /** - * judge wether is tosca node type definition or not. - * @param type node type - * @return boolean - */ - public static boolean isToscaNodeTypeDef(String type) { - for (EnumToscaNodeTypeDefinition enumDef : EnumToscaNodeTypeDefinition.values()) { - if (type.indexOf(enumDef.getName()) != -1) { - return true; - } - } - return false; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/EnumToscaRelationShipDefinition.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/EnumToscaRelationShipDefinition.java deleted file mode 100644 index d1d26cef..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/EnumToscaRelationShipDefinition.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.model.common; - -public enum EnumToscaRelationShipDefinition { - VirtualBindsTo { - @Override - public String getName() { - return "tosca.relationships.nfv.VirtualBindsTo"; - } - }, - VirtualLinksTo { - @Override - public String getName() { - return "tosca.relationships.nfv.VirtualLinksTo"; - } - }, - DeployedOn { - @Override - public String getName() { - return "tosca.relationships.nfv.DeployedOn"; - } - }, - BelongTo { - @Override - public String getName() { - return "tosca.relationships.nfv.BelongTo"; - } - }; - - public abstract String getName(); - -} 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 deleted file mode 100644 index a26a32bc..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateDataHelper.java +++ /dev/null @@ -1,267 +0,0 @@ -/** - * 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.model.common; - -import org.openo.commontosca.catalog.common.ToolUtil; -import org.openo.commontosca.catalog.db.entity.NodeTemplateData; -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; -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.SubstitutionMapping; -import org.openo.commontosca.catalog.wrapper.PackageWrapper; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public class TemplateDataHelper { - - /** - * convert to template data. - * @param st ServiceTemplate - * @param ntList NodeTemplate list - * @return TemplateData - */ - public static TemplateData convert2TemplateData(ServiceTemplate st, String rawData, - List<NodeTemplate> ntList) { - TemplateData td = new TemplateData(); - td.setServiceTemplate(convert2ServiceTemplateData(st, rawData)); - td.setNodeTemplates(convert2NodeTemplateDataList(ntList, st.getServiceTemplateId())); - return td; - } - - /** - * convert to service template data. - * @param st ServiceTemplate - * @return ServiceTemplateData - */ - private static ServiceTemplateData convert2ServiceTemplateData(ServiceTemplate st, - 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()); - std.setCsarId(st.getCsarId()); - std.setType(st.getType()); - std.setDownloadUri(st.getDownloadUri()); - Parameters parameters = new Parameters(st.getInputs(), st.getOutputs()); - std.setInputs(ToolUtil.toJson(parameters)); - std.setOperations(ToolUtil.toJson(st.getOperations())); - std.setRowData(rawData); - return std; - } - - /** - * convert to nodeTemplate data list. - * @param ntList NodeTemplate list - * @param serviceTemplateId service template id - * @return NodeTemplateData list - */ - private static ArrayList<NodeTemplateData> convert2NodeTemplateDataList(List<NodeTemplate> ntList, - String serviceTemplateId) { - ArrayList<NodeTemplateData> ntdList = new ArrayList<>(); - for (NodeTemplate nt : ntList) { - ntdList.add(convert2NodeTemplateData(nt, serviceTemplateId)); - - } - return ntdList; - } - - - /** - * convert to nodeTemplate data. - * @param nt NodeTemplate - * @param serviceTemplateId service template id - * @return NodeTemplateData - */ - private static NodeTemplateData convert2NodeTemplateData(NodeTemplate nt, - String serviceTemplateId) { - NodeTemplateData ntd = new NodeTemplateData(); - - ntd.setNodeTemplateId(nt.getId()); - ntd.setName(nt.getName()); - ntd.setType(nt.getType()); - ntd.setServiceTemplateId(serviceTemplateId); - ntd.setProperties(ToolUtil.toJson(nt.getProperties())); - ntd.setRelationShips(ToolUtil.toJson(nt.getRelationShips())); - - return ntd; - } - - - /** - * convert to service templates. - * @param stdList ServiceTemplateData list - * @return ServiceTemplate list - * @throws CatalogResourceException - */ - public static ServiceTemplate[] convert2ServiceTemplates(List<ServiceTemplateData> stdList) throws CatalogResourceException { - List<ServiceTemplate> stList = new ArrayList<>(); - for (ServiceTemplateData std : stdList) { - stList.add(convert2ServiceTemplate(std)); - } - - return stList.toArray(new ServiceTemplate[0]); - } - - /** - * covert to service template. - * @param std ServiceTemplateData - * @return ServiceTemplate - * @throws CatalogResourceException - */ - public static ServiceTemplate convert2ServiceTemplate(ServiceTemplateData std) throws CatalogResourceException { - Parameters parameters = ToolUtil.fromJson(std.getInputs(), Parameters.class); - ServiceTemplateOperation[] operations = - ToolUtil.fromJson(std.getOperations(), ServiceTemplateOperation[].class); - String downloadUri = buildSTDownloadUri(std.getCsarId(), std.getDownloadUri()); - - return new ServiceTemplate(std.getServiceTemplateId(), std.getServiceTemplateOriginalId(), - std.getTemplateName(), std.getVendor(), - std.getVersion(), std.getCsarId(), std.getType(), downloadUri, - 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) - throws CatalogResourceException { - CsarFileUriResponse stDownloadUri = - PackageWrapper.getInstance().getCsarFileDownloadUri(packageId, stFileName); - return stDownloadUri.getDownloadUri(); - } - - /** - * covert to nodeTemplates. - * @param ntdList NodeTemplateData list - * @return NodeTemplate list - */ - public static NodeTemplate[] convert2NodeTemplates(List<NodeTemplateData> ntdList) { - List<NodeTemplate> ntList = new ArrayList<>(); - for (NodeTemplateData ntd : ntdList) { - ntList.add(convert2NodeTemplate(ntd)); - } - return ntList.toArray(new NodeTemplate[0]); - } - - /** - * covert to nodeTemplate. - * @param ntd NodeTemplateData - * @return NodeTemplate - */ - public static NodeTemplate convert2NodeTemplate(NodeTemplateData ntd) { - List<RelationShip> relationShips = convert2RelationShipList(ntd.getRelationShips()); - return new NodeTemplate(ntd.getNodeTemplateId(), ntd.getName(), ntd.getType(), - convert2Property(ntd.getProperties()), relationShips); - } - - /** - * covert to relationship list. - * @param sRelationShips relationships - * @return RelationShip list - */ - private static List<RelationShip> convert2RelationShipList(String srelationShips) { - RelationShip[] relationShips = ToolUtil.fromJson(srelationShips, RelationShip[].class); - return Arrays.asList(relationShips); - } - - /** - * convert to propterty. - * @param properties properties to covert - * @return map - */ - private static Map<String, Object> convert2Property(String properties) { - JsonObject jsonObject = new Gson().fromJson(properties, JsonObject.class); - return parseMapValue(jsonObject); - } - - private static Map<String, Object> parseMapValue(JsonObject jsonObject) { - Map<String, Object> map = new HashMap<>(); - - Iterator<Entry<String, JsonElement>> iterator = jsonObject.entrySet().iterator(); - while (iterator.hasNext()) { - Entry<String, JsonElement> next = iterator.next(); - if (next.getValue() instanceof JsonPrimitive) { - map.put(next.getKey(), next.getValue().getAsString()); - continue; - } - - if (next.getValue() instanceof JsonObject) { - map.put(next.getKey(), parseMapValue((JsonObject) next.getValue())); - continue; - } - } - return map; - } - - - /** - * covert to template mapping data. - * @param stm data to convert - * @return ServiceTemplateMappingData - */ - public static ServiceTemplateMappingData convert2TemplateMappingData(SubstitutionMapping stm) { - ServiceTemplateMappingData stmd = new ServiceTemplateMappingData(); - - stmd.setMappingId(ToolUtil.generateId()); - stmd.setServiceTemplateId(stm.getServiceTemplateId()); - stmd.setNodeType(stm.getNodeType()); - stmd.setRequirements(ToolUtil.toJson(stm.getRequirements())); - stmd.setCapabilities(ToolUtil.toJson(stm.getCapabilities())); - - return stmd; - } - - /** - * convert to substitution mapping. - * @param stmData data to covert - * @return SubstitutionMapping - */ - public static SubstitutionMapping convert2SubstitutionMapping( - ServiceTemplateMappingData stmData) { - return new SubstitutionMapping(stmData.getServiceTemplateId(), stmData.getNodeType()); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateUtils.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateUtils.java deleted file mode 100644 index 697ca1ab..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateUtils.java +++ /dev/null @@ -1,197 +0,0 @@ -/** - * 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.model.common; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.model.parser.yaml.yamlmodel.Input; -import org.openo.commontosca.catalog.model.parser.yaml.yamlmodel.Plan; -import org.openo.commontosca.catalog.model.parser.yaml.yamlmodel.ServiceTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.esotericsoftware.yamlbeans.YamlConfig; -import com.esotericsoftware.yamlbeans.YamlException; -import com.esotericsoftware.yamlbeans.YamlReader; - -public class TemplateUtils { - private static final Logger logger = LoggerFactory.getLogger(TemplateUtils.class); - - public static Map<String, Plan> loadPlan(String yamlString) throws CatalogResourceException { - ServiceTemplate st = loadServiceTemplate(yamlString); - return st.getPlans(); - } - - /** - * @param yamlString - * @return - * @throws CatalogResourceException - */ - public static ServiceTemplate loadServiceTemplate(String yamlString) throws CatalogResourceException { - if (yamlString == null || yamlString.isEmpty()) { - return new ServiceTemplate(); - } - final YamlReader reader = new YamlReader(yamlString); - adjustConfig(reader.getConfig()); - try { - return reader.read(ServiceTemplate.class); - } catch (final YamlException e) { - throw new CatalogResourceException("Load plan information failed.", e); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - } - } - } - } - - - /** - * @param config - */ - private static void adjustConfig(YamlConfig config) { - config.setPropertyElementType(ServiceTemplate.class, "plans", Plan.class); - config.setPropertyElementType(Plan.class, "inputs", Input.class); - } - - - /** - * @param zipFileName - * @param zipEntryName - * @return - * @throws CatalogResourceException - */ - public static String readStringFromZipFile(String zipFileName, String zipEntryName) throws CatalogResourceException { - String[] lines = readFromZipFile(zipFileName, zipEntryName); - StringBuffer sb = new StringBuffer(); - for (String line : lines) { - sb.append(line).append(System.lineSeparator()); - } - return sb.toString(); - } - - /** - * @param zipFileName - * @param zipEntryName - * @return - * @throws CatalogResourceException - */ - public static String[] readFromZipFile(String zipFileName, String zipEntryName) - throws CatalogResourceException { - ZipFile zf = null; - InputStream ins = null; - try { - zf = new ZipFile(zipFileName); - ZipEntry ze = getZipEntryZipFile(zf, zipEntryName); - - if (ze != null) { - ins = zf.getInputStream(ze); - return readFromInputStream(ins); - } - } catch (IOException e) { - throw new CatalogResourceException("readFromZipFile failed.", e); - } finally { - closeInputStream(ins); - closeZipFile(zf); - } - return new String[0]; - } - - public static ZipEntry getZipEntryZipFile(ZipFile zf, String zipEntryName) { - Enumeration<?> zes = zf.entries(); - while (zes.hasMoreElements()) { - ZipEntry ze = (ZipEntry) zes.nextElement(); - if (zipEntryName.equals(ze.getName()) - || (zipEntryName.replaceAll("\\\\", "/")).equals(ze.getName())) { - return ze; - } - } - - return null; - } - - /** - * @param ins - */ - public static void closeInputStream(InputStream ins) { - if (ins != null) { - try { - ins.close(); - } catch (IOException e) { - logger.warn("closeInputStream failed.", e); - } - } - } - - /** - * @param zf - */ - public static void closeZipFile(ZipFile zf) { - if (zf != null) { - try { - zf.close(); - } catch (IOException e) { - logger.warn("closeZipFile failed.", e); - } - } - } - - private static String[] readFromInputStream(InputStream ins) throws CatalogResourceException { - InputStreamReader insReader = new InputStreamReader(ins); - BufferedReader reader = new BufferedReader(insReader); - - List<String> lineList = new ArrayList<>(); - String line; - try { - while ((line = reader.readLine()) != null) { - lineList.add(line); - } - } catch (IOException e) { - throw new CatalogResourceException("readFromInputStream failed.", e); - } finally { - closeReader(reader); - closeReader(insReader); - } - - return lineList.toArray(new String[0]); - } - - /** - * @param reader - */ - private static void closeReader(Reader reader) { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - logger.warn("closeReader failed.", e); - } - } - } -} 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 deleted file mode 100644 index 6afbd492..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/CapReqMapping.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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/InputParameter.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/InputParameter.java deleted file mode 100644 index b77d272f..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/InputParameter.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class InputParameter { - private String name; - private String type = "string"; - private String description; - private Object defaultValue; - private boolean required; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/KeyValuePair.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/KeyValuePair.java deleted file mode 100644 index cb2acde7..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/KeyValuePair.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class KeyValuePair { - private String key; - private String value; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/NfvTemplate.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/NfvTemplate.java deleted file mode 100644 index d5307c77..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/NfvTemplate.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class NfvTemplate { - private List<NodeTemplate> vduNodes; - private List<NodeTemplate> networkNodes; - private List<NodeTemplate> vnfcNodes; - private List<NodeTemplate> vnfNodes; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/NodeTemplate.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/NodeTemplate.java deleted file mode 100644 index 03939dd7..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/NodeTemplate.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; -import java.util.Map; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class NodeTemplate { - private String id; - private String name; - private String type; - private Map<String, Object> properties; - private List<RelationShip> relationShips; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/OutputParameter.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/OutputParameter.java deleted file mode 100644 index 298370c2..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/OutputParameter.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class OutputParameter { - - private String name; - - private String description; - - private Object value; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/Parameters.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/Parameters.java deleted file mode 100644 index 249c2975..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/Parameters.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Parameters { - - private InputParameter[] inputs; - - private OutputParameter[] outputs; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/QueryRawDataCondition.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/QueryRawDataCondition.java deleted file mode 100644 index a1493aa7..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/QueryRawDataCondition.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class QueryRawDataCondition { - private String csarId; - private KeyValuePair[] inputParameters; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/RelationShip.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/RelationShip.java deleted file mode 100644 index 6e101802..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/RelationShip.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class RelationShip { - - private String sourceNodeName; - - private String targetNodeName; - - private String sourceNodeId; - - private String targetNodeId; - - private String type; - -} 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 deleted file mode 100644 index 6f5dfb3a..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplate.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class ServiceTemplate { - - private String serviceTemplateId; - - private String id; - - private String templateName; - - private String vendor; - - private String version; - - private String csarId; - - private String type; - - private String downloadUri; - - private InputParameter[] inputs; - - private OutputParameter[] outputs; - - private ServiceTemplateOperation[] operations; - - private SubstitutionMapping substitution; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplateOperation.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplateOperation.java deleted file mode 100644 index 510a1592..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplateOperation.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class ServiceTemplateOperation { - - private String name; - - private String description; - - private String packageName; - - private String processId; - - private InputParameter[] inputs; - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplateRawData.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplateRawData.java deleted file mode 100644 index 505444d6..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplateRawData.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class ServiceTemplateRawData { - - private String rawData; - -} 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 deleted file mode 100644 index 2f34a4a9..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/SubstitutionMapping.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.model.entity; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import com.fasterxml.jackson.annotation.JsonIgnore; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class SubstitutionMapping { - @JsonIgnore - private String serviceTemplateId; - private String nodeType; - private CapReqMapping[] requirements; - private CapReqMapping[] capabilities; - - /** - * substitution mapping. - * @param serviceTemplateId service template id - * @param nodeType node type - */ - public SubstitutionMapping(String serviceTemplateId, String nodeType) { - super(); - this.serviceTemplateId = serviceTemplateId; - this.nodeType = nodeType; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerSelfServiceProvider.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerSelfServiceProvider.java deleted file mode 100644 index e6690920..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerSelfServiceProvider.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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.model.externalservice.container; - -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerSelfService; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.MessageBodyReader; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; - - - - -/** - * The opentosca container self service returns data to the entity. - * - * @author 10189609 - * - */ -public class ContainerSelfServiceProvider implements MessageBodyReader<ContainerSelfService> { - - @Override - public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, - MediaType mediaType) { - return ContainerSelfService.class.isAssignableFrom(type); - } - - @Override - public ContainerSelfService readFrom(Class<ContainerSelfService> type, Type genericType, - Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, - InputStream entityStream) throws IOException, WebApplicationException { - ContainerSelfService object = null; - - try { - JAXBContext jaxbContext = JAXBContext.newInstance(ContainerSelfService.class); - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - object = (ContainerSelfService) unmarshaller.unmarshal(entityStream); - } catch (JAXBException e1) { - e1.printStackTrace(); - } - - return object; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServiceConsumer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServiceConsumer.java deleted file mode 100644 index da809fb7..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServiceConsumer.java +++ /dev/null @@ -1,228 +0,0 @@ -/** - * 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.model.externalservice.container; - -import com.google.gson.JsonObject; - -import com.eclipsesource.jaxrs.consumer.ConsumerFactory; - -import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.media.multipart.BodyPart; -import org.glassfish.jersey.media.multipart.FormDataBodyPart; -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataMultiPart; -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.openo.commontosca.catalog.common.Config; -import org.openo.commontosca.catalog.common.ToolUtil; -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerSelfService; -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerSelfServiceOption; -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServiceNodeTemplateList; -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServiceTemplateList; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.InputStream; -import java.util.List; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - - - -/** - * By rest requesting access container services. - * - * @author 10189609 - * - */ -public class ContainerServiceConsumer { - private static final Logger LOG = LoggerFactory.getLogger(ContainerServiceConsumer.class); - - /** - * get service template by template id from container service. - * - * @param templateid id - * @return template list entity - */ - public static ContainerServiceTemplateList getServiceTemplates(final String templateid) { - ClientConfig config = new ClientConfig(new ContainerServiceTemplateProvider()); - IContainerTemplateRest containerservicetemplateproxy = - ConsumerFactory.createConsumer(getBaseUrl(), config, IContainerTemplateRest.class); - return containerservicetemplateproxy.getToscaServiceTemplate(templateid); - } - - /** - * get operation input param xml from container service. - * - * @param csarId package Id - * @param operationId operation id - * @return xml - */ - public static String getOperationInputParamXml(final String csarId, final String operationId) { - String inputparamsSoapXml = null; - ClientConfig config = new ClientConfig().register(new ContainerSelfServiceProvider()); - IContainerSelfServiceRest containerserviceoperationproxy = - ConsumerFactory.createConsumer(getPackageUrl(), config, IContainerSelfServiceRest.class); - String csarid = ToolUtil.formatCsar(csarId); - ContainerSelfService containerselfservice = - containerserviceoperationproxy.getContainerSelfService(csarid); - if (containerselfservice != null) { - for (int i = 0; i < containerselfservice.getOptionList().size(); i++) { - ContainerSelfServiceOption serviceOption = containerselfservice.getOptionList().get(i); - if (serviceOption != null && operationId.equals(serviceOption.getId())) { - inputparamsSoapXml = - containerserviceoperationproxy.getContainerSelfServiceOptionInputMessage(csarid, - serviceOption.getPlanInputMessageUrl()); - break; - } - } - } - return inputparamsSoapXml; - } - - /** - * get operations by csar id. - * - * @param csarId package id - * @return xml - */ - public static String getOperations(final String csarId) { - ClientConfig config = new ClientConfig().register(new ContainerSelfServiceProvider()); - IContainerSelfServiceRest containerselfserviceproxy = - ConsumerFactory.createConsumer(getPackageUrl(), config, IContainerSelfServiceRest.class); - return containerselfserviceproxy.getContainerSelfServiceXml(ToolUtil.formatCsar(csarId)); - } - - /** - * get operation list. - * @param csarId package id - * @return container operation list - */ - public static List<ContainerSelfServiceOption> getOperationList(final String csarId) { - ClientConfig config = new ClientConfig().register(new ContainerSelfServiceProvider()); - IContainerSelfServiceRest containerserviceoperationproxy = - ConsumerFactory.createConsumer(getPackageUrl(), config, IContainerSelfServiceRest.class); - String csarid = ToolUtil.formatCsar(csarId); - ContainerSelfService containerselfservice = - containerserviceoperationproxy.getContainerSelfService(csarid); - return containerselfservice.getOptionList(); - } - - /** - * upload csar package to opentosca containerapi service. - * - * @param uploadedInputStream stream - * @param fileDetail file detail - * @return response - */ - public static Response uploadServicePackage(InputStream uploadedInputStream, - FormDataContentDisposition fileDetail) { - final FormDataMultiPart formData = new FormDataMultiPart(); - final BodyPart bodyPart = - new FormDataBodyPart(fileDetail, uploadedInputStream, - MediaType.APPLICATION_OCTET_STREAM_TYPE); - formData.bodyPart(bodyPart); - formData.setContentDisposition(fileDetail); - formData.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE); - final Client client = ClientBuilder.newBuilder().register(MultiPartFeature.class).build(); - final WebTarget target = client.target(getPackageUrl()).path("/containerapi/CSARs"); - final Response response = - target.request().post(Entity.entity(formData, formData.getMediaType())); - return response; - } - - /** - * upload csar package by file location. - * - * @param fileLocation file location - * @return response - */ - public static Response uploadServicePackageByLocation(String fileLocation) { - ClientConfig config = new ClientConfig(); - IContainerExtPackageRest containerservicepackageproxy = - ConsumerFactory.createConsumer(getBaseUrl(), config, IContainerExtPackageRest.class); - String result = containerservicepackageproxy.uploadPackageByToscaService(fileLocation); - JsonObject json = new JsonObject(); - json.addProperty("result", result); - return Response.ok(json.toString()).build(); - } - - /** - * delete a csar package by csar name. - * - * @param csarName package name - * @return package id which deleted - */ - public static String delServicePackage(final String csarName) { - ClientConfig config = new ClientConfig(); - IContainerExtPackageRest containerservicepackageproxy = - ConsumerFactory.createConsumer(getBaseUrl(), config, IContainerExtPackageRest.class); - LOG.info("url:" + getBaseUrl() + " csarName:" + csarName); - return containerservicepackageproxy.deletePackageById(csarName); - } - - /** - * get node template list. - * - * @param templateId template id - * @return container service nodeTemplate list - */ - public static ContainerServiceNodeTemplateList getNodeTemplates(final String templateId) { - ClientConfig config = new ClientConfig(new ContainerServiceNodeTemplateProvider()); - IContainerTemplateRest containertemplateproxy = - ConsumerFactory.createConsumer(getBaseUrl(), config, IContainerTemplateRest.class); - return containertemplateproxy.getToscaServiceNodeTemplates(templateId); - } - - /** - * get policy infomation by service template id from vnfd. - * - * @param serviceTemplateId service template id - * @return tosca policys - */ - public static String getPolicys(String serviceTemplateId) { - ClientConfig config = new ClientConfig(new StringProvider()); - IContainerPortabilityRest containerPolicyproxy = - ConsumerFactory.createConsumer(getBaseUrl(), config, IContainerPortabilityRest.class); - return containerPolicyproxy.getToscaPolicys(serviceTemplateId); - } - - /** - * http://127.0.0.1:1337/containerapi/extension. - * - * @return base url - */ - private static String getBaseUrl() { - StringBuffer buffer = new StringBuffer(); - buffer.append(Config.getConfigration().getMsbServerAddr() + "/containerapi/extension"); - return buffer.toString(); - } - - /** - * http://127.0.0.1:1337 - * - * @return package url - */ - private static String getPackageUrl() { - StringBuffer buffer = new StringBuffer(); - buffer.append(Config.getConfigration().getMsbServerAddr()); - return buffer.toString(); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServiceNodeTemplateProvider.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServiceNodeTemplateProvider.java deleted file mode 100644 index f2593d49..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServiceNodeTemplateProvider.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 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.model.externalservice.container; - -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServiceNodeTemplateList; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.MessageBodyReader; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.Source; -import javax.xml.transform.sax.SAXSource; - -/** - * The opentosca container service returns data to the node template entity. - * - * @author 10189609 - * - */ -public class ContainerServiceNodeTemplateProvider implements - MessageBodyReader<ContainerServiceNodeTemplateList> { - - @Override - public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, - MediaType mediaType) { - return ContainerServiceNodeTemplateList.class.isAssignableFrom(type); - } - - @Override - public ContainerServiceNodeTemplateList readFrom(Class<ContainerServiceNodeTemplateList> type, - Type genericType, Annotation[] annotations, MediaType mediaType, - MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, - WebApplicationException { - ContainerServiceNodeTemplateList nodetemplatelist = null; - - try { - JAXBContext jaxbContext = JAXBContext.newInstance(ContainerServiceNodeTemplateList.class); - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - // ignore namespace - NamespaceFilter inFilter = new NamespaceFilter(null, false); - XMLReader reader = XMLReaderFactory.createXMLReader(); - inFilter.setParent(reader); - Source source = new SAXSource(inFilter, new InputSource(entityStream)); - - nodetemplatelist = (ContainerServiceNodeTemplateList) unmarshaller.unmarshal(source); - } catch (Exception e1) { - e1.printStackTrace(); - } - - return nodetemplatelist; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServicePackageProvider.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServicePackageProvider.java deleted file mode 100644 index c0cf0f7d..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServicePackageProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * 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.model.externalservice.container; - -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServicePackageList; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.MessageBodyReader; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; - - - -/** - * The opentosca container service returns data to the package entity. - * - * @author 10189609 - * - */ -public class ContainerServicePackageProvider implements - MessageBodyReader<ContainerServicePackageList> { - - @Override - public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, - MediaType mediaType) { - return ContainerServicePackageList.class.isAssignableFrom(type); - } - - @Override - public ContainerServicePackageList readFrom(Class<ContainerServicePackageList> type, - Type genericType, Annotation[] annotations, MediaType mediaType, - MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, - WebApplicationException { - ContainerServicePackageList packageList = null; - - try { - JAXBContext jaxbContext = JAXBContext.newInstance(ContainerServicePackageList.class); - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - packageList = (ContainerServicePackageList) unmarshaller.unmarshal(entityStream); - } catch (JAXBException e1) { - e1.printStackTrace(); - } - - return packageList; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServiceTemplateProvider.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServiceTemplateProvider.java deleted file mode 100644 index bfd1b04a..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/ContainerServiceTemplateProvider.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * 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.model.externalservice.container; - -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServiceTemplateList; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.MessageBodyReader; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; - - -/** - * The opentosca container self service returns data to the service template entity. - * - * @author 10189609 - * - */ -public class ContainerServiceTemplateProvider implements - MessageBodyReader<ContainerServiceTemplateList> { - - @Override - public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, - MediaType mediaType) { - return ContainerServiceTemplateList.class.isAssignableFrom(type); - } - - @Override - public ContainerServiceTemplateList readFrom(Class<ContainerServiceTemplateList> type, - Type genericType, Annotation[] annotations, MediaType mediaType, - MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, - WebApplicationException { - ContainerServiceTemplateList object = null; - - try { - JAXBContext jaxbContext = JAXBContext.newInstance(ContainerServiceTemplateList.class); - Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); - object = (ContainerServiceTemplateList) jaxbUnmarshaller.unmarshal(entityStream); - } catch (JAXBException e1) { - e1.printStackTrace(); - } - - return object; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerExtPackageRest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerExtPackageRest.java deleted file mode 100644 index 15823ea1..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerExtPackageRest.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * 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.model.externalservice.container; - -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServicePackageList; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - -/** - * The opentosca container interface for csar. - * - * @author 10189609 - * - */ -@Path("/csars") -public interface IContainerExtPackageRest { - @GET - @Produces(MediaType.APPLICATION_OCTET_STREAM) - public ContainerServicePackageList getToscaServicePackage( - @QueryParam("csarName") String csarName); - - @POST - @Consumes(MediaType.TEXT_PLAIN) - public String uploadPackageByToscaService(@QueryParam("fileLocation") String fileLocation); - - @Path("/{csarId}") - @DELETE - public String deletePackageById(@PathParam("csarId") String csarId); -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerPortabilityRest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerPortabilityRest.java deleted file mode 100644 index b864c74f..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerPortabilityRest.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.model.externalservice.container; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -/** - * The opentosca container interface for policy. - * - * @author 10189609 - * - */ -@Path("/servicetemplates") -public interface IContainerPortabilityRest { - - @Path("/{templateid}/policys") - @GET - String getToscaPolicys(@PathParam("templateid") String serviceTemplateId); -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerSelfServiceRest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerSelfServiceRest.java deleted file mode 100644 index 9149c5b2..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerSelfServiceRest.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.model.externalservice.container; - -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerSelfService; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - - -/** - * The opentosca container interface for self service. - * - * @author 10189609 - * - */ -@Path("/containerapi/CSARs/{csarid}/Content/SELFSERVICE-Metadata") -public interface IContainerSelfServiceRest { - @GET - @Path("/data.xml") - @Produces({"application/octet-stream"}) - ContainerSelfService getContainerSelfService(@PathParam("csarid") String csarId); - - @GET - @Path("/data.xml") - @Produces({"application/octet-stream"}) - String getContainerSelfServiceXml(@PathParam("csarid") String csarId); - - @GET - @Path("/{inputmessageurl}") - @Produces({"application/octet-stream"}) - String getContainerSelfServiceOptionInputMessage(@PathParam("csarid") String csarId, - @PathParam("inputmessageurl") String inputmessageUrl); -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerTemplateRest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerTemplateRest.java deleted file mode 100644 index a39840c3..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/IContainerTemplateRest.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.model.externalservice.container; - -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServiceNodeTemplateList; -import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServiceTemplateList; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - - -/** - * The opentosca container interface for service template. - * - * @author 10189609 - * - */ -@Path("/servicetemplates") -public interface IContainerTemplateRest { - @GET - @Produces(MediaType.APPLICATION_OCTET_STREAM) - ContainerServiceTemplateList getToscaServiceTemplate(@QueryParam("templateid") String templateId); - - @Path("/{templateid}/nodetemplates") - @GET - @Produces(MediaType.APPLICATION_OCTET_STREAM) - ContainerServiceNodeTemplateList getToscaServiceNodeTemplates( - @PathParam("templateid") String templateId); -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/NamespaceFilter.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/NamespaceFilter.java deleted file mode 100644 index ad440c4f..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/NamespaceFilter.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * 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.model.externalservice.container; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.XMLFilterImpl; - -/** - * NamespaceFilter. - * - * @author 10189609 - * - */ -public class NamespaceFilter extends XMLFilterImpl { - - private String usedNamespaceUri; - private boolean addNamespace; - - // State variable - private boolean addedNamespace = false; - - /** - * constructor. - * @param namespaceUri namspace uri - * @param addNamespace add namespace or not - */ - public NamespaceFilter(String namespaceUri, boolean addNamespace) { - super(); - - if (addNamespace) { - this.usedNamespaceUri = namespaceUri; - } else { - this.usedNamespaceUri = ""; - } - this.addNamespace = addNamespace; - } - - - - @Override - public void startDocument() throws SAXException { - super.startDocument(); - if (addNamespace) { - startControlledPrefixMapping(); - } - } - - - - @Override - public void startElement(String arg0, String arg1, String arg2, Attributes arg3) - throws SAXException { - - super.startElement(this.usedNamespaceUri, arg1, arg2, arg3); - } - - @Override - public void endElement(String arg0, String arg1, String arg2) throws SAXException { - - super.endElement(this.usedNamespaceUri, arg1, arg2); - } - - @Override - public void startPrefixMapping(String prefix, String url) throws SAXException { - - - if (addNamespace) { - this.startControlledPrefixMapping(); - } else { - // Remove the namespace, i.e. don´t call startPrefixMapping for parent! - } - - } - - private void startControlledPrefixMapping() throws SAXException { - - if (this.addNamespace && !this.addedNamespace) { - // We should add namespace since it is set and has not yet been done. - super.startPrefixMapping("", this.usedNamespaceUri); - - // Make sure we dont do it twice - this.addedNamespace = true; - } - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/StringProvider.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/StringProvider.java deleted file mode 100644 index 085865ba..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/container/StringProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.model.externalservice.container; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.ext.MessageBodyReader; - -/** - * The opentosca container service returns data directly. - * - * @author 10189609 - * - */ -public class StringProvider implements MessageBodyReader<String> { - - @Override - public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, - MediaType mediaType) { - return false;// false representation not convert query results , returned directly - } - - @Override - public String readFrom(Class<String> type, Type genericType, Annotation[] annotations, - MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) - throws IOException, WebApplicationException { - return null; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerSelfService.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerSelfService.java deleted file mode 100644 index 6fd02289..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerSelfService.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "Application", namespace = ContainerSelfService.NAMESPACE_OF_SELFSERVICE) -public class ContainerSelfService { - public static final String NAMESPACE_OF_SELFSERVICE = - "http://www.eclipse.org/winery/model/selfservice"; - - @XmlElement(namespace = NAMESPACE_OF_SELFSERVICE) - private String displayName; - - @XmlElement(namespace = NAMESPACE_OF_SELFSERVICE) - private String description; - - @XmlElement(namespace = NAMESPACE_OF_SELFSERVICE) - private String iconUrl; - - @XmlElement(namespace = NAMESPACE_OF_SELFSERVICE) - private String imageUrl; - - @XmlElementWrapper(name = "options", namespace = NAMESPACE_OF_SELFSERVICE) - @XmlElement(name = "option", namespace = NAMESPACE_OF_SELFSERVICE) - private List<ContainerSelfServiceOption> optionList; - - public String getDisplayName() { - return displayName; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getIconUrl() { - return iconUrl; - } - - public void setIconUrl(String iconUrl) { - this.iconUrl = iconUrl; - } - - public String getImageUrl() { - return imageUrl; - } - - public void setImageUrl(String imageUrl) { - this.imageUrl = imageUrl; - } - - public List<ContainerSelfServiceOption> getOptionList() { - return optionList; - } - - public void setOptionList(List<ContainerSelfServiceOption> optionList) { - this.optionList = optionList; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerSelfServiceOption.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerSelfServiceOption.java deleted file mode 100644 index 48bf9cdc..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerSelfServiceOption.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlTransient; - -@XmlAccessorType(XmlAccessType.FIELD) -public class ContainerSelfServiceOption { - @XmlElement(namespace = ContainerSelfService.NAMESPACE_OF_SELFSERVICE) - private String description; - @XmlElement(namespace = ContainerSelfService.NAMESPACE_OF_SELFSERVICE) - private String iconUrl; - @XmlElement(namespace = ContainerSelfService.NAMESPACE_OF_SELFSERVICE) - private String planServiceName; - @XmlElement(namespace = ContainerSelfService.NAMESPACE_OF_SELFSERVICE) - private String planInputMessageUrl; - @XmlAttribute - private String id; - @XmlAttribute - private String name; - @XmlTransient - private String inputMessageSoap; - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getIconUrl() { - return iconUrl; - } - - public void setIconUrl(String iconUrl) { - this.iconUrl = iconUrl; - } - - public String getPlanServiceName() { - return planServiceName; - } - - public void setPlanServiceName(String planServiceName) { - this.planServiceName = planServiceName; - } - - public String getPlanInputMessageUrl() { - return planInputMessageUrl; - } - - public void setPlanInputMessageUrl(String planInputMessageUrl) { - this.planInputMessageUrl = planInputMessageUrl; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getInputMessageSoap() { - return inputMessageSoap; - } - - public void setInputMessageSoap(String inputMessageSoap) { - this.inputMessageSoap = inputMessageSoap; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceCommonParam.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceCommonParam.java deleted file mode 100644 index 14b5191e..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceCommonParam.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; - -@XmlAccessorType(XmlAccessType.FIELD) -public class ContainerServiceCommonParam { - @XmlElement - private String key; - - @XmlElement - private String value; - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceNodeTemplate.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceNodeTemplate.java deleted file mode 100644 index 1300f82c..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceNodeTemplate.java +++ /dev/null @@ -1,315 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -import org.openo.commontosca.catalog.common.ToolUtil; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement -@XmlAccessorType(XmlAccessType.NONE) -public class ContainerServiceNodeTemplate { - - @XmlAttribute(name = "nodetemplateid") - private String id; - - @XmlAttribute(name = "nodetemplatename") - private String name; - - @XmlAttribute - private String type; - - @XmlElementWrapper(name = "properties") - @XmlElement(name = "property") - private List<ContainerServiceCommonParam> properties; - - @XmlElementWrapper(name = "relationshipInfos") - @XmlElement(name = "relationship") - private List<ContainerServiceRelationShip> relationShips; - - @XmlElement(name = "Capabilities") - private ContainerServiceNodeTemplate.Capablitiies capabilities; - - public ContainerServiceNodeTemplate.Capablitiies getCapabilities() { - return capabilities; - } - - public void setCapabilities(ContainerServiceNodeTemplate.Capablitiies capabilities) { - this.capabilities = capabilities; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public List<ContainerServiceCommonParam> getProperties() { - return properties; - } - - public void setProperties(List<ContainerServiceCommonParam> properties) { - this.properties = properties; - } - - public List<ContainerServiceRelationShip> getRelationShips() { - return relationShips; - } - - public void setRelationShips(List<ContainerServiceRelationShip> relationShips) { - this.relationShips = relationShips; - } - - @XmlRootElement - @XmlAccessorType(XmlAccessType.NONE) - public static class Capablitiies { - @XmlElement(name = "Capability") - private List<ContainerServiceNodeTemplate.Capability> capabilityList; - - public List<ContainerServiceNodeTemplate.Capability> getCapabilityList() { - return capabilityList; - } - - public void setCapabilityList(List<ContainerServiceNodeTemplate.Capability> capabilityList) { - this.capabilityList = capabilityList; - } - } - - @XmlRootElement - @XmlAccessorType(XmlAccessType.NONE) - public static class Capability { - @XmlAttribute(name = "id") - private String flavorName; - - @XmlElement(name = "Properties") - private ContainerServiceNodeTemplate.CapabilityProperties properties; - - public String getFlavorName() { - return flavorName; - } - - public void setFlavorName(String flavorName) { - this.flavorName = flavorName; - } - - public ContainerServiceNodeTemplate.CapabilityProperties getProperties() { - return properties; - } - - public void setProperties(ContainerServiceNodeTemplate.CapabilityProperties properties) { - this.properties = properties; - } - - } - - @XmlRootElement - @XmlAccessorType(XmlAccessType.NONE) - public static class CapabilityProperties { - @XmlElement(name = "Properties") - private ContainerServiceNodeTemplate.CapabilityProperty property; - - public ContainerServiceNodeTemplate.CapabilityProperty getProperty() { - return property; - } - - public void setProperty(ContainerServiceNodeTemplate.CapabilityProperty property) { - this.property = property; - } - } - - @XmlRootElement - @XmlAccessorType(XmlAccessType.FIELD) - public static class CapabilityProperty { - @XmlElement - private String vcpu; - - @XmlElement - private String vram; - - @XmlElement - private String rootDisk; - - @XmlElement - private String swapDisk; - - @XmlElement - private String tempDisk; - - public String getVcpu() { - return vcpu; - } - - public void setVcpu(String vcpu) { - this.vcpu = vcpu; - } - - public String getVram() { - return vram; - } - - public void setVram(String vram) { - this.vram = vram; - } - - public String getRootDisk() { - return rootDisk; - } - - public void setRootDisk(String rootDisk) { - this.rootDisk = rootDisk; - } - - public String getSwapDisk() { - return swapDisk; - } - - public void setSwapDisk(String swapDisk) { - this.swapDisk = swapDisk; - } - - public String getTempDisk() { - return tempDisk; - } - - public void setTempDisk(String tempDisk) { - this.tempDisk = tempDisk; - } - } - - public class NtFlavor { - private String flavorName; - - private String vcpu; - - private String vram; - - private String rootDisk; - - private String swapDisk; - - private String tempDisk; - - public String getFlavorName() { - return flavorName; - } - - public void setFlavorName(String flavorName) { - this.flavorName = flavorName; - } - - public String getVcpu() { - return vcpu; - } - - public void setVcpu(String vcpu) { - this.vcpu = vcpu; - } - - public String getVram() { - return vram; - } - - public void setVram(String vram) { - this.vram = vram; - } - - public String getRootDisk() { - return rootDisk; - } - - public void setRootDisk(String rootDisk) { - this.rootDisk = rootDisk; - } - - public String getSwapDisk() { - return swapDisk; - } - - public void setSwapDisk(String swapDisk) { - this.swapDisk = swapDisk; - } - - public String getTempDisk() { - return tempDisk; - } - - public void setTempDisk(String tempDisk) { - this.tempDisk = tempDisk; - } - - } - - /** - * get nt flavor list. - * @return nt flavor list - */ - public List<NtFlavor> getNtFlavorList() { - if (null == this.capabilities || ToolUtil.isEmptyCollection(capabilities.getCapabilityList())) { - return null; - } - - List<NtFlavor> ntFlavors = new ArrayList<NtFlavor>(); - List<Capability> capabilityList = capabilities.getCapabilityList(); - for (Capability capabilty : capabilityList) { - NtFlavor ntFlavor = convertCap2Flavor(capabilty); - ntFlavors.add(ntFlavor); - } - - return ntFlavors; - } - - private NtFlavor convertCap2Flavor(Capability capabilty) { - NtFlavor ntFlavor = new NtFlavor(); - ntFlavor.setFlavorName(capabilty.getFlavorName()); - if (null != capabilty.getProperties() && null != capabilty.getProperties().getProperty()) { - CapabilityProperty property = capabilty.getProperties().getProperty(); - ntFlavor.setRootDisk(property.getRootDisk()); - ntFlavor.setSwapDisk(property.getSwapDisk()); - ntFlavor.setTempDisk(property.getTempDisk()); - ntFlavor.setVcpu(property.getVcpu()); - ntFlavor.setVram(property.getVram()); - } - - return ntFlavor; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceNodeTemplateList.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceNodeTemplateList.java deleted file mode 100644 index a65bdaab..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceNodeTemplateList.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "nodetemplates") -public class ContainerServiceNodeTemplateList { - @XmlElement(name = "nodetemplate") - private List<ContainerServiceNodeTemplate> nodeTemplate; - - public List<ContainerServiceNodeTemplate> getNodeTemplate() { - return nodeTemplate; - } - - public void setNodeTemplate(List<ContainerServiceNodeTemplate> nodeTemplate) { - this.nodeTemplate = nodeTemplate; - } - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceOperationParameter.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceOperationParameter.java deleted file mode 100644 index 701a1318..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceOperationParameter.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -public class ContainerServiceOperationParameter { - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServicePackage.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServicePackage.java deleted file mode 100644 index 398d0e9c..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServicePackage.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement -public class ContainerServicePackage { - @XmlAttribute - private String name; - @XmlAttribute - private String createTime; - @XmlAttribute - private String size; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getCreateTime() { - return createTime; - } - - public void setCreateTime(String createTime) { - this.createTime = createTime; - } - - public String getSize() { - return size; - } - - public void setSize(String size) { - this.size = size; - } - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServicePackageList.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServicePackageList.java deleted file mode 100644 index e841784c..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServicePackageList.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "packages") -public class ContainerServicePackageList { - public static final String NAMESPACE_OF_SELFSERVICE = - "http://www.eclipse.org/winery/model/selfservice"; - - @XmlElement(name = "package") - private List<ContainerServicePackage> packageList; - - public List<ContainerServicePackage> getPackageList() { - return packageList; - } - - public void setPackageList(List<ContainerServicePackage> packageList) { - this.packageList = packageList; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceRelationShip.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceRelationShip.java deleted file mode 100644 index d0e7cde1..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceRelationShip.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; - -@XmlAccessorType(XmlAccessType.FIELD) -public class ContainerServiceRelationShip { - @XmlElement - private String sourceNodeName; - - @XmlElement - private String targetNodeName; - - @XmlElement - private String sourceNodeId; - - @XmlElement - private String targetNodeId; - - @XmlElement - private String type; - - public String getSourceNodeId() { - return sourceNodeId; - } - - public void setSourceNodeId(String sourceNodeId) { - this.sourceNodeId = sourceNodeId; - } - - public String getTargetNodeId() { - return targetNodeId; - } - - public void setTargetNodeId(String targetNodeId) { - this.targetNodeId = targetNodeId; - } - - public String getSourceNodeName() { - return sourceNodeName; - } - - public void setSourceNodeName(String sourceNodeName) { - this.sourceNodeName = sourceNodeName; - } - - public String getTargetNodeName() { - return targetNodeName; - } - - public void setTargetNodeName(String targetNodeName) { - this.targetNodeName = targetNodeName; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceTemplate.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceTemplate.java deleted file mode 100644 index 54e02cdb..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceTemplate.java +++ /dev/null @@ -1,329 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement -@XmlAccessorType(XmlAccessType.NONE) -public class ContainerServiceTemplate { - @XmlAttribute - private String templateid; - - @XmlAttribute - private String templatename; - - @XmlElement(name = "BoundaryDefinitions") - private BoundaryDefinitions boundary; - - public String getTemplateid() { - return templateid; - } - - public void setTemplateid(String templateid) { - this.templateid = templateid; - } - - public String getTemplatename() { - return templatename; - } - - public void setTemplatename(String templatename) { - this.templatename = templatename; - } - - public BoundaryDefinitions getBoundary() { - return boundary; - } - - public void setBoundary(BoundaryDefinitions boundary) { - this.boundary = boundary; - } - - @XmlRootElement - @XmlAccessorType(XmlAccessType.NONE) - public static class BoundaryDefinitions { - @XmlElement(name = "Properties", namespace = "http://docs.oasis-open.org/tosca/ns/2011/12") - private BoundaryProperties properties; - - public BoundaryProperties getProperties() { - return properties; - } - - public void setProperties(BoundaryProperties properties) { - this.properties = properties; - } - - } - - @XmlRootElement - @XmlAccessorType(XmlAccessType.NONE) - public static class BoundaryProperties { - @XmlElement(name = "Properties") - private BoundaryProperty property; - - public BoundaryProperty getProperty() { - return property; - } - - public void setProperty(BoundaryProperty property) { - this.property = property; - } - } - - @XmlRootElement - @XmlAccessorType(XmlAccessType.NONE) - public static class BoundaryProperty { - public String getTemplateVersion() { - return templateVersion; - } - - public void setTemplateVersion(String templateVersion) { - this.templateVersion = templateVersion; - } - - public String getTemplateAuthor() { - return templateAuthor; - } - - public void setTemplateAuthor(String templateAuthor) { - this.templateAuthor = templateAuthor; - } - - public String getVendor() { - return vendor; - } - - public void setVendor(String vendor) { - this.vendor = vendor; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getNfvType() { - return nfvType; - } - - public void setNfvType(String nfvType) { - this.nfvType = nfvType; - } - - public String getMoc() { - return moc; - } - - public void setMoc(String moc) { - this.moc = moc; - } - - public String getFlavor() { - return flavor; - } - - public void setFlavor(String flavor) { - this.flavor = flavor; - } - - public List<StFlavor> getStFlavor() { - return stFlavor; - } - - public void setStFlavor(List<StFlavor> stFlavor) { - this.stFlavor = stFlavor; - } - - @XmlElement - private String templateVersion; - - @XmlElement - private String templateAuthor; - - @XmlElement - private String vendor; - - @XmlElement - private String version; - - @XmlElement - private String nfvType; - - @XmlElement - private String moc; - - @XmlElement - private String flavor; - - @XmlElementWrapper(name = "flavorList") - @XmlElement(name = "flavor") - private List<StFlavor> stFlavor; - } - - @XmlRootElement - @XmlAccessorType(XmlAccessType.NONE) - public static class StFlavor { - @XmlAttribute - private String name; - - @XmlAttribute - private String desc; - - @XmlElementWrapper(name = "nodeList") - @XmlElement(name = "node") - private List<StFlavorConstituent> stFlavorConstituent; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDesc() { - return desc; - } - - public void setDesc(String desc) { - this.desc = desc; - } - - public List<StFlavorConstituent> getStFlavorConstituent() { - return stFlavorConstituent; - } - - public void setStFlavorConstituent(List<StFlavorConstituent> stFlavorConstituent) { - this.stFlavorConstituent = stFlavorConstituent; - } - } - - @XmlRootElement - @XmlAccessorType(XmlAccessType.NONE) - public static class StFlavorConstituent { - @XmlAttribute - private String numberOfInstances; - - @XmlAttribute - private String name; - - @XmlAttribute - private String refNodeFlavor; - - @XmlAttribute - private String affinity; - - @XmlAttribute - private String redundancyModel; - - @XmlAttribute - private String capability; - - public String getAffinity() { - return affinity; - } - - public void setAffinity(String affinity) { - this.affinity = affinity; - } - - public String getRedundancyModel() { - return redundancyModel; - } - - public void setRedundancyModel(String redundancyModel) { - this.redundancyModel = redundancyModel; - } - - public String getCapability() { - return capability; - } - - public void setCapability(String capability) { - this.capability = capability; - } - - public String getNumberOfInstances() { - return numberOfInstances; - } - - public void setNumberOfInstances(String numberOfInstances) { - this.numberOfInstances = numberOfInstances; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getRefNodeFlavor() { - return refNodeFlavor; - } - - public void setRefNodeFlavor(String refNodeFlavor) { - this.refNodeFlavor = refNodeFlavor; - } - } - - private Boolean propNullFlag; - - private boolean isPropNotNull() { - if (null == propNullFlag) { - propNullFlag = - null != this.getBoundary() && null != this.getBoundary().getProperties() - && null != this.getBoundary().getProperties().getProperty(); - } - return propNullFlag; - } - - public String getProductType() { - return isPropNotNull() ? this.getBoundary().getProperties().getProperty().getMoc() : null; - } - - public String getVendor() { - return isPropNotNull() ? this.getBoundary().getProperties().getProperty().getVendor() : null; - } - - public String getVersion() { - return isPropNotNull() ? this.getBoundary().getProperties().getProperty().getVersion() : null; - } - - public String getNfvtype() { - return isPropNotNull() ? this.getBoundary().getProperties().getProperty().getNfvType() : null; - } - - public String getFlavor() { - return isPropNotNull() ? this.getBoundary().getProperties().getProperty().getFlavor() : null; - } - - public List<StFlavor> getStFlavorList() { - return isPropNotNull() ? this.getBoundary().getProperties().getProperty().getStFlavor() : null; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceTemplateList.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceTemplateList.java deleted file mode 100644 index c4ebfbc4..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/container/ContainerServiceTemplateList.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 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.model.externalservice.entity.container; - -import java.util.List; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "servicetemplates") -public class ContainerServiceTemplateList { - public static final String NAMESPACE_OF_SELFSERVICE = - "http://www.eclipse.org/winery/model/selfservice"; - - @XmlElement(name = "serviceTemplate") - private List<ContainerServiceTemplate> serviceTemplateList; - - public List<ContainerServiceTemplate> getServiceTemplateList() { - return serviceTemplateList; - } - - public void setServiceTemplateList(List<ContainerServiceTemplate> optionList) { - this.serviceTemplateList = optionList; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/lifecycle/InstanceEntity.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/lifecycle/InstanceEntity.java deleted file mode 100644 index caace7e8..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/lifecycle/InstanceEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * 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.model.externalservice.entity.lifecycle; - -public class InstanceEntity { - private String serviceTemplateId; - - public String getServiceTemplateId() { - return serviceTemplateId; - } - - public void setServiceTemplateId(String serviceTemplateId) { - this.serviceTemplateId = serviceTemplateId; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/ro/ResourceResponseEntity.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/ro/ResourceResponseEntity.java deleted file mode 100644 index f6da4549..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/ro/ResourceResponseEntity.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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.model.externalservice.entity.ro; - -import java.util.ArrayList; - -public class ResourceResponseEntity { - ArrayList<VimEntity> data = new ArrayList<VimEntity>(); - String operationResult; - - public String getOperationResult() { - return operationResult; - } - - public void setOperationResult(String operationResult) { - this.operationResult = operationResult; - } - - public ArrayList<VimEntity> getData() { - return data; - } - - public void setData(ArrayList<VimEntity> data) { - this.data = data; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/ro/VimEntity.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/ro/VimEntity.java deleted file mode 100644 index 98edf112..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/entity/ro/VimEntity.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * 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.model.externalservice.entity.ro; - -public class VimEntity { - private String oid; - private String name; - private String user; - private String url; - private String userName; - private String password; - - public String getOid() { - return oid; - } - - public void setOid(String oid) { - this.oid = oid; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/lifecycle/ILifeCycleServiceRest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/lifecycle/ILifeCycleServiceRest.java deleted file mode 100644 index 8e33c9b1..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/lifecycle/ILifeCycleServiceRest.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.model.externalservice.lifecycle; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -/** - * The lifecycle interface. - * - * @author 10189609 - * - */ -@Path("/appinstances") -public interface ILifeCycleServiceRest { - @GET - @Produces(MediaType.APPLICATION_JSON) - public String getVnfInstances(); -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/lifecycle/LifeCycleServiceConsumer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/lifecycle/LifeCycleServiceConsumer.java deleted file mode 100644 index 9c264ada..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/lifecycle/LifeCycleServiceConsumer.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * 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.model.externalservice.lifecycle; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; - -import com.eclipsesource.jaxrs.consumer.ConsumerFactory; -import org.openo.commontosca.catalog.common.MsbUtil; -import org.openo.commontosca.catalog.common.ToolUtil; -import org.openo.commontosca.catalog.model.externalservice.entity.lifecycle.InstanceEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.Type; -import java.util.ArrayList; - - - -/** - * The lifecycle service. - * - * @author 10189609 - * - */ -public class LifeCycleServiceConsumer { - private static final Logger LOG = LoggerFactory.getLogger(LifeCycleServiceConsumer.class); - - /** - * get lifecycle application instances. - * - * @return instance entity - */ - public static ArrayList<InstanceEntity> getInstances() { - ILifeCycleServiceRest resourceserviceproxy = - ConsumerFactory.createConsumer(MsbUtil.getNsocLifecycleBaseUrl(), - ILifeCycleServiceRest.class); - String result = ""; - try { - result = resourceserviceproxy.getVnfInstances(); - } catch (Exception e1) { - LOG.error("query vim info faild.", e1); - return null; - } - if (ToolUtil.isEmptyString(result)) { - return null; - } - - Gson gson = new Gson(); - Type listType = new TypeToken<ArrayList<InstanceEntity>>() {}.getType(); - return gson.fromJson(result, listType); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/ro/IResourceServiceRest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/ro/IResourceServiceRest.java deleted file mode 100644 index 5c45776c..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/ro/IResourceServiceRest.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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.model.externalservice.ro; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -/** - * The roc resource interface. - * - * @author 10189609 - * - */ -@Path("/resource") -public interface IResourceServiceRest { - @Path("/vims/{vim_id}") - @GET - @Produces(MediaType.APPLICATION_JSON) - public String getResourceVim(@PathParam("vim_id") String vimId) throws Exception; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/ro/ResourceServiceConsumer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/ro/ResourceServiceConsumer.java deleted file mode 100644 index b06d7667..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/externalservice/ro/ResourceServiceConsumer.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * 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.model.externalservice.ro; - -import com.google.gson.Gson; - -import com.eclipsesource.jaxrs.consumer.ConsumerFactory; - -import org.openo.commontosca.catalog.common.MsbUtil; -import org.openo.commontosca.catalog.common.ToolUtil; -import org.openo.commontosca.catalog.model.externalservice.entity.ro.ResourceResponseEntity; -import org.openo.commontosca.catalog.model.externalservice.entity.ro.VimEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * The roc resource service. - * - * @author 10189609 - * - */ -public class ResourceServiceConsumer { - private static final Logger LOG = LoggerFactory.getLogger(ResourceServiceConsumer.class); - - private static final String RESOURCE_REST_RESULT = "SUCCESS"; - - /** - * get vim entity from roc by vimid. - * - * @param vimId id - * @return vim entity - */ - public static VimEntity getResourceVim(String vimId) { - LOG.info("begin query vim info from roc,vimId:" + vimId); - IResourceServiceRest resourceserviceproxy = - ConsumerFactory.createConsumer(MsbUtil.getRocBaseUrl(), IResourceServiceRest.class); - String result = ""; - try { - result = resourceserviceproxy.getResourceVim(vimId); - } catch (Exception e1) { - LOG.error("query vim info faild.", e1); - return null; - } - if (ToolUtil.isEmptyString(result)) { - LOG.error("query vim info faild, vim info is null, vimId:" + vimId); - return null; - } - - Gson gson = new Gson(); - ResourceResponseEntity responseEntity = gson.fromJson(result, ResourceResponseEntity.class); - if (!RESOURCE_REST_RESULT.equalsIgnoreCase(responseEntity.getOperationResult())) { - LOG.error("query vim info faild.vimId:" + vimId); - return null; - } - if (responseEntity.getData().size() <= 0) { - LOG.error("query vim info faild, vim info is empty, vimId:" + vimId); - return null; - } - - LOG.info("end query vim info from roc."); - return responseEntity.getData().get(0); - } -} 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 deleted file mode 100644 index 76cc97a0..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java +++ /dev/null @@ -1,260 +0,0 @@ -/** - * 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.model.parser; - -import org.openo.commontosca.catalog.common.MsbAddrConfig; -import org.openo.commontosca.catalog.common.ToolUtil; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.model.common.TemplateUtils; -import org.openo.commontosca.catalog.model.entity.InputParameter; -import org.openo.commontosca.catalog.model.entity.NodeTemplate; -import org.openo.commontosca.catalog.model.entity.ServiceTemplateOperation; -import org.openo.commontosca.catalog.model.parser.yaml.yamlmodel.Input; -import org.openo.commontosca.catalog.model.parser.yaml.yamlmodel.Plan; -import org.openo.commontosca.catalog.model.plan.wso2.Wso2ServiceConsumer; -import org.openo.commontosca.catalog.model.plan.wso2.entity.DeployPackageResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public abstract class AbstractModelParser { - private static final Logger logger = LoggerFactory.getLogger(AbstractModelParser.class); - - public abstract String parse(String packageId, String fileLocation) - throws CatalogResourceException; - - public String copyTemporaryFile2HttpServer(String fileLocation) throws CatalogResourceException { - String destPath = org.openo.commontosca.catalog.filemanage.http.ToolUtil.getHttpServerAbsolutePath() - + toTempFilePath(fileLocation); - if (!org.openo.commontosca.catalog.filemanage.http.ToolUtil.copyFile( - fileLocation, destPath, true)) { - throw new CatalogResourceException("Copy Temporary To HttpServer Failed."); - } - - logger.info("destPath = " + destPath); - return destPath; - } - - public String getUrlOnHttpServer(String path) { - if (MsbAddrConfig.getMsbAddress().endsWith("/")) { - return MsbAddrConfig.getMsbAddress() + "files/catalog-http" + path; - } else { - return MsbAddrConfig.getMsbAddress() + "/files/catalog-http" + path; - } - } - - protected String toTempFilePath(String fileLocation) { - return "/temp/" + (new File(fileLocation)).getName(); - } - - protected EnumTemplateType getTemplateType(String substitutionType, List<NodeTemplate> ntList) { - if (isNsType(substitutionType)) { - return EnumTemplateType.NS; - } - - if (isVnfType(substitutionType)) { - return EnumTemplateType.VNF; - } - - return getTemplateTypeFromNodeTemplates(ntList); - } - - private boolean isVnfType(String type) { - if (ToolUtil.isTrimedEmptyString(type)) { - return false; - } - return type.toUpperCase().endsWith(".VNF") || type.toUpperCase().contains(".VNF."); - } - - private boolean isNsType(String type) { - if (ToolUtil.isTrimedEmptyString(type)) { - return false; - } - return type.toUpperCase().endsWith(".NS") || type.toUpperCase().contains(".NS."); - } - - private EnumTemplateType getTemplateTypeFromNodeTemplates(List<NodeTemplate> ntList) { - for (NodeTemplate nt : ntList) { - if (isNsType(nt.getType()) || isVnfType(nt.getType())) { - return EnumTemplateType.NS; - } - } - - return EnumTemplateType.VNF; - } - - private static final String TOSCA_META_FIELD_ENTRY_DEFINITIONS = "Entry-Definitions"; - - protected String parseServiceTemplateFileName(String packageId, String fileLocation) - throws CatalogResourceException { - return "/" + parseToscaMeta(fileLocation).get(TOSCA_META_FIELD_ENTRY_DEFINITIONS); - } - - private static final String TOSCA_META_FILE_NAME = "TOSCA-Metadata/TOSCA.meta"; - protected Map<String, String> parseToscaMeta(String zipLocation) throws CatalogResourceException { - Map<String, String> toscaMeta = new HashMap<>(); - String[] lines = TemplateUtils.readFromZipFile(zipLocation, TOSCA_META_FILE_NAME); - - for (String line : lines) { - String[] tmps; - if (line.indexOf(":") > 0) { - tmps = line.split(":"); - toscaMeta.put(tmps[0].trim(), tmps[1].trim()); - } - } - - return toscaMeta; - } - - /** - * @param fileLocation - * @return - * @throws CatalogResourceException - */ - protected ServiceTemplateOperation[] parseOperations(String fileLocation) throws CatalogResourceException { - String sPlan = TemplateUtils.readStringFromZipFile(fileLocation, "Definitions/plans.yaml"); - Map<String, Plan> plans = TemplateUtils.loadPlan(sPlan); - return parseAndDeployPlans(plans, fileLocation); - } - - /** - * @param plans - * @param fileLocation - * @return - * @throws CatalogResourceException - */ - private ServiceTemplateOperation[] parseAndDeployPlans(Map<String, Plan> plans, - String zipFileLocation) throws CatalogResourceException { - if (plans == null || plans.isEmpty()) { - return new ServiceTemplateOperation[0]; - } - - List<ServiceTemplateOperation> opList = new ArrayList<>(); - for (Entry<String, Plan> plan : plans.entrySet()) { - ServiceTemplateOperation op = new ServiceTemplateOperation(); - op.setName(plan.getKey()); - op.setDescription(plan.getValue().getDescription()); - checkPlanLanguage(plan.getValue().getPlanLanguage()); - DeployPackageResponse response = - Wso2ServiceConsumer.deployPackage(zipFileLocation, plan.getValue().getReference()); - op.setPackageName(parsePackageName(response)); - op.setProcessId(response.getProcessId()); - op.setInputs(parsePlanInputs(plan.getValue().getInputs())); - - opList.add(op); - } - - return opList.toArray(new ServiceTemplateOperation[0]); - } - - private String parsePackageName(DeployPackageResponse response) { - String packageName = response.getPackageName(); - if (packageName != null && packageName.indexOf("-") > 0) { - packageName = packageName.substring(0, packageName.lastIndexOf("-")); - } - return packageName; - } - - private void checkPlanLanguage(String planLanguage) throws CatalogResourceException { - if (planLanguage == null || planLanguage.isEmpty()) { - throw new CatalogResourceException("Plan Language is empty."); - } - if (planLanguage.equalsIgnoreCase("bpel")) { - return; - } - if (planLanguage.equalsIgnoreCase("bpmn")) { - return; - } - if (planLanguage.equalsIgnoreCase("bpmn4tosca")) { - return; - } - throw new CatalogResourceException( - "Plan Language is not supported. Language = " + planLanguage); - } - - /** - * @param inputs - * @return - */ - private InputParameter[] parsePlanInputs( - Map<String, Input> inputs) { - if (inputs == null || inputs.isEmpty()) { - return new InputParameter[0]; - } - - List<InputParameter> retList = new ArrayList<>(); - for (Entry<String, Input> input : inputs.entrySet()) { - retList.add(new InputParameter( - input.getKey(), - input.getValue().getType(), - input.getValue().getDescription(), - input.getValue().getDefault(), - input.getValue().isRequired())); - } - return retList.toArray(new InputParameter[0]); - } - - /** - * @param metadata - * @return - */ - 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 - * @return - */ - public String parserServiceTemplateVendor(Map<String, String> metadata) { - if (metadata.containsKey("vendor")) { - return metadata.get("vendor"); - } - return metadata.get("template_author"); - } - - /** - * @param metadata - * @return - */ - public String parserServiceTemplateVersion(Map<String, String> metadata) { - if (metadata.containsKey("version")) { - return metadata.get("version"); - } - return metadata.get("template_version"); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/EnumPackageFormat.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/EnumPackageFormat.java deleted file mode 100644 index 5aaf9061..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/EnumPackageFormat.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * 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.model.parser; - -/** - * enum data. - * - * @author 10189609 - * - */ -public enum EnumPackageFormat { - TOSCA_XML, TOSCA_YAML -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/EnumTemplateType.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/EnumTemplateType.java deleted file mode 100644 index 44e21e5f..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/EnumTemplateType.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * 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.model.parser; - -public enum EnumTemplateType { - NS, VNF -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/ModelParserFactory.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/ModelParserFactory.java deleted file mode 100644 index 5e9ef1aa..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/ModelParserFactory.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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.model.parser; - -import org.openo.commontosca.catalog.common.Config; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.model.parser.yaml.aria.AriaModelParser; -import org.openo.commontosca.catalog.model.parser.yaml.zte.ToscaYamlModelParser; - -import java.util.HashMap; -import java.util.Map; - - -public class ModelParserFactory { - private static final ModelParserFactory instance = new ModelParserFactory(); - - public static ModelParserFactory getInstance() { - return instance; - } - - private Map<EnumPackageFormat, AbstractModelParser> pkgType2ParseMap = - new HashMap<EnumPackageFormat, AbstractModelParser>(); - - /** - * @param format - * @param parse - */ - public void put(EnumPackageFormat format, AbstractModelParser parse) { - if (parse != null) { - pkgType2ParseMap.put(format, parse); - } - } - - private ModelParserFactory() { - // PackageParseMap.put(EnumPackageFormat.TOSCA_XML, new ToscaXmlModelParser()); - if (isAriaParser()) { - pkgType2ParseMap.put(EnumPackageFormat.TOSCA_YAML, new AriaModelParser()); - } else { - pkgType2ParseMap.put(EnumPackageFormat.TOSCA_YAML, new ToscaYamlModelParser()); - } - } - - /** - * @return - */ - private boolean isAriaParser() { - return "aria".equalsIgnoreCase(Config.getConfigration().getParserType()); - } - - /** - * parse package. - * @param packageId package id - * @param fileLocation package location - * @param format package format - * @return service template id - * @throws CatalogResourceException e - */ - public String parse(String packageId, String fileLocation, EnumPackageFormat format) - throws CatalogResourceException { - if (pkgType2ParseMap.get(format) == null) { - throw new CatalogResourceException("Can't find its parser. package type = " - + format.toString()); - } - - return pkgType2ParseMap.get(format).parse(packageId, fileLocation); - } -} 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 deleted file mode 100644 index 8d37319c..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java +++ /dev/null @@ -1,311 +0,0 @@ -/** - * 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.model.parser.yaml.aria; - -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.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; -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.SubstitutionMapping; -import org.openo.commontosca.catalog.model.parser.AbstractModelParser; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Input; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Node; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Node.Relationship; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Output; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Substitution.Mapping; -import org.openo.commontosca.catalog.model.parser.yaml.aria.service.AriaParserServiceConsumer; -import org.openo.commontosca.catalog.wrapper.PackageWrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author 10090474 - * - */ -public class AriaModelParser extends AbstractModelParser { - private static final Logger logger = LoggerFactory.getLogger(AriaModelParser.class); - - /* (non-Javadoc) - * @see org.openo.commontosca.catalog.model.parser.AbstractModelParser#parse(java.lang.String, java.lang.String) - */ - @Override - public String parse(String packageId, String fileLocation) throws CatalogResourceException { - logger.info("Parse begin."); - - String stFileLocation = parseServiceTemplateFileName(packageId, fileLocation); - AriaParserResult result = getAriaParserResult(packageId, stFileLocation); - - // service template - ServiceTemplate st = parseServiceTemplate(result, packageId, stFileLocation); - // workflow - ServiceTemplateOperation[] operations = parseOperations(fileLocation); - st.setOperations(operations); - // node templates - List<NodeTemplate> ntList = parseNodeTemplates(packageId, st.getServiceTemplateId(), result); - st.setType(getTemplateType(getSubstitutionType(result), ntList).toString()); - // save to db - TemplateManager.getInstance().addServiceTemplate( - TemplateDataHelper.convert2TemplateData(st, result.getRawData(), ntList)); - - // substitution - SubstitutionMapping stm = parseSubstitutionMapping(st.getServiceTemplateId(), result); - if (stm != null) { - TemplateManager.getInstance() - .addServiceTemplateMapping(TemplateDataHelper.convert2TemplateMappingData(stm)); - } - - return st.getServiceTemplateId(); - } - - - /** - * @param serviceTemplateId - * @param result - * @return - */ - private SubstitutionMapping parseSubstitutionMapping(String serviceTemplateId, - AriaParserResult result) { - String type = getSubstitutionType(result); - if (ToolUtil.isTrimedEmptyString(type)) { - return null; - } - - org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult.Instance.Substitution stm = - result.getInstance().getSubstitution(); - return new SubstitutionMapping( - serviceTemplateId, - type, - parseSubstitutionRequirements(stm.getRequirement()), - parseSubstitutionCapabilities(stm.getCapabilities())); - } - - - /** - * @param capabilities - * @return - */ - private CapReqMapping[] parseSubstitutionCapabilities(Mapping[] capabilities) { - return parseMappings(capabilities); - } - - /** - * @param requirement - * @return - */ - 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 - */ - private String getSubstitutionType(AriaParserResult result) { - if (result.getInstance().getSubstitution() == null) { - return null; - } - return result.getInstance().getSubstitution().getNode_type_name(); - } - - - /** - * @param packageId - * @param serviceTemplateId - * @param result - * @return - * @throws CatalogResourceException - */ - private List<NodeTemplate> parseNodeTemplates(String packageId, String serviceTemplateId, - AriaParserResult result) throws CatalogResourceException { - Node[] nodes = result.getInstance().getNodes(); - if (nodes == null || nodes.length == 0) { - return null; - } - - List<NodeTemplate> retList = new ArrayList<>(); - for (Node node : nodes) { - NodeTemplate ret = new NodeTemplate(); - ret.setId(node.getTemplate_name()); - ret.setName(node.getTemplate_name()); - ret.setType(node.getType_name()); - ret.setProperties(node.getPropertyAssignments()); - List<RelationShip> relationShipList = - parseNodeTemplateRelationShip(node.getRelationships(), node, nodes); - ret.setRelationShips(relationShipList); - - retList.add(ret); - } - - return retList; - } - - - /** - * @param relationships - * @param sourceNode - * @param nodes - * @return - * @throws CatalogResourceException - */ - private List<RelationShip> parseNodeTemplateRelationShip(Relationship[] relationships, - Node sourceNode, Node[] nodes) throws CatalogResourceException { - List<RelationShip> retList = new ArrayList<>(); - - if (relationships == null || relationships.length == 0) { - return retList; - } - - for (Relationship relationship : relationships) { - if (relationship.getTarget_node_id().equals(sourceNode.getId())) { - continue; // target == source, ignore. - } - - RelationShip ret = new RelationShip(); - ret.setSourceNodeId(sourceNode.getTemplate_name()); - ret.setSourceNodeName(sourceNode.getTemplate_name()); - Node targetNode = getNodeById(nodes, relationship.getTarget_node_id()); - ret.setTargetNodeId(targetNode.getTemplate_name()); - ret.setTargetNodeName(targetNode.getTemplate_name()); - ret.setType(relationship.getType_name()); - retList.add(ret); - } - - return retList; - } - - - /** - * @param nodes - * @param nodeId - * @return - * @throws CatalogResourceException - */ - private Node getNodeById(Node[] nodes, String nodeId) throws CatalogResourceException { - if (nodeId == null) { - throw new CatalogResourceException("Target node id is null."); - } - if (nodes == null || nodes.length == 0) { - throw new CatalogResourceException("Can't find target node. nodeId = " + nodeId); - } - - for (Node node : nodes) { - if (nodeId.equals(node.getId())) { - return node; - } - } - - throw new CatalogResourceException("Can't find target node. nodeId = " + nodeId); - } - - - /** - * @param result - * @param packageId - * @param downloadUri - * @return - */ - private ServiceTemplate parseServiceTemplate(AriaParserResult result, String packageId, - String downloadUri) { - ServiceTemplate st = new ServiceTemplate(); - - st.setServiceTemplateId(ToolUtil.generateId()); - st.setId(parserId(result.getInstance().getMetadata())); - st.setTemplateName(parserServiceTemplateName(result.getInstance().getMetadata())); - st.setVendor(parserServiceTemplateVendor(result.getInstance().getMetadata())); - st.setVersion(parserServiceTemplateVersion(result.getInstance().getMetadata())); - st.setCsarId(packageId); - st.setDownloadUri(downloadUri); - st.setInputs(parseInputs(result)); - st.setOutputs(parseOutputs(result)); - return st; - } - - - /** - * @param result - * @return - */ - private InputParameter[] parseInputs(AriaParserResult result) { - Map<String, Input> inputs = result.getInstance().getInputs(); - if (inputs == null || inputs.isEmpty()) { - return new InputParameter[0]; - } - List<InputParameter> retList = new ArrayList<InputParameter>(); - for (Entry<String, Input> e : inputs.entrySet()) { - retList.add( - new InputParameter( - e.getKey(), - e.getValue().getType_name(), - e.getValue().getDescription(), - e.getValue().getValue(), - false)); - } - return retList.toArray(new InputParameter[0]); - } - - /** - * @param result - * @return - */ - private OutputParameter[] parseOutputs(AriaParserResult result) { - Map<String, Output> outputs = result.getInstance().getOutpus(); - if (outputs == null || outputs.isEmpty()) { - return new OutputParameter[0]; - } - - List<OutputParameter> retList = new ArrayList<OutputParameter>(); - for (Entry<String, Output> e: outputs.entrySet()) { - retList.add( - new OutputParameter( - e.getKey(), e.getValue().getDescription(), e.getValue().getValue())); - } - - return retList.toArray(new OutputParameter[0]); - } - - private AriaParserResult getAriaParserResult(String packageId, String stFileLocation) throws CatalogResourceException { - CsarFileUriResponse stDownloadUri = - PackageWrapper.getInstance().getCsarFileDownloadUri(packageId, stFileLocation); - return AriaParserServiceConsumer.parseCsarPackage(stDownloadUri.getDownloadUri()); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserExceptionResult.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserExceptionResult.java deleted file mode 100644 index b06c97de..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserExceptionResult.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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.model.parser.yaml.aria.entity; - -//import lombok.AllArgsConstructor; -//import lombok.Data; -//import lombok.NoArgsConstructor; -// -//@Data -//@NoArgsConstructor -//@AllArgsConstructor -//public class AriaParserExceptionResult { -// private Issue[] issues; -// -// @Data -// public class Issue { -// private int level; -// private String message; -// private String location; -// private String line; -// private String column; -// private String snippet; -// private String exception; -// } -//} - diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserRequest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserRequest.java deleted file mode 100644 index aae8008d..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserRequest.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 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.model.parser.yaml.aria.entity; - -/** - * - */ -import java.util.List; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class AriaParserRequest { - private String uri; - private List<Parameter> inputs; - - @Data - @NoArgsConstructor - @AllArgsConstructor - public class Parameter { - private String name; - private String value; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserResult.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserResult.java deleted file mode 100644 index f2968fd5..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/entity/AriaParserResult.java +++ /dev/null @@ -1,233 +0,0 @@ -/** - * 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.model.parser.yaml.aria.entity; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class AriaParserResult { - private Issue[] issues; - private Instance instance = new Instance(); - - private String rawData; -// private Type[] types; -// private Model model; - -// @Data -// public class Type { -// } -// @Data -// public class Model { -// } - @Data - public class Issue { - private int level; - private String message; - private String location; - private String line; - private String column; - private String snippet; - private String exception; - } - - @Data - public class Instance { - private String description; - private Map<String, String> metadata; - private Node[] nodes; - private Group[] groups; - private Policy[] policies; - private Substitution substitution; - private Map<String, Input> inputs; - private Map<String, Output> outpus; - - public Map<String, String> getMetadata() { - if (this.metadata == null) { - return new HashMap<>(); - } - - return metadata; - } - - @Data - public class Node { - private String id; - private String type_name; - private String template_name; - private Map<String, Property> properties; - private Interface[] interfaces; - private Artifact[] artifacts; - private Capability[] capabilities; - private Relationship[] relationships; - - @Data - public class Artifact { - private String name; - private String type_name; - private String source_path; - private String target_path; - private String repository_url; - private Credential repository_credential; - private Map<String, Property> properties; - - @Data - public class Credential { - private String protocol; - private String token_type; - private Map<String, String> keys; - private String user; - } - } - - @Data - public class Capability { - private String name; - private String type_name; - private Map<String, Property> properties; - } - - @Data - public class Relationship { - private String target_node_id; - private String target_capability_name; - private String type_name; - private String template_name; - private Map<String, Property> properties; - private Interface[] source_interfaces; - private Interface[] target_interfaces; - } - - /** - * @return - */ - public Map<String, Object> getPropertyAssignments() { - if (this.properties == null || this.properties.isEmpty()) { - return new HashMap<String, Object>(); - } - - Map<String, Object> ret = new HashMap<String, Object>(); - for (Entry<String, Property> e : this.properties.entrySet()) { - ret.put(e.getKey(), e.getValue().getValue()); - } - - return ret; - } - } - - @Data - public class Group { - private String id; - private String type_name; - private String template_name; - private Map<String, Property> properties; - private Interface[] interfaces; - private GroupPolicy[] policies; - private String[] member_node_ids; - - @Data - public class GroupPolicy { - private String id; - private String type_name; - private Map<String, Property> properties; - private Trigger[] triggers; - - @Data - public class Trigger { - private String name; - private String implementation; - private Map<String, Property> properties; - } - } - - } - - - @Data - public class Policy { - private String name; - private String type_name; - private Map<String, Property> properties; - private String[] target_node_ids; - private String[] target_group_ids; - } - - @Data - public class Substitution { - private String node_type_name; - private Mapping[] requirement; - private Mapping[] capabilities; - - @Data - public class Mapping { - private String mapped_name; - private String node_id; - private String name; - - } - } - - @Data - public class Input { - private String type_name; - private Object value; - private String description; - } - - @Data - public class Output { - private String type_name; - private Object value; - private String description; - } - } - -} - - -@Data -class Property { - private String type_name; - private Object value; - private String description; -} - -@Data -class Interface { - private String name; - private String type_name; - private Map<String, Property> inputs; - private Operation[] operation; - - @Data - class Operation { - private String name; - private String implementation; - private String[] dependencies; - private String executor; - private int max_retries; - private int retry_interval; - private Map<String, Property> inputs; - } -} - diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/service/AriaParserServiceConsumer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/service/AriaParserServiceConsumer.java deleted file mode 100644 index 1701c60f..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/service/AriaParserServiceConsumer.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * 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.model.parser.yaml.aria.service; - -import org.glassfish.jersey.client.ClientConfig; -import org.openo.commontosca.catalog.common.Config; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserRequest; -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.eclipsesource.jaxrs.consumer.ConsumerFactory; -import com.google.gson.Gson; - - -public class AriaParserServiceConsumer { - private static final Logger logger = LoggerFactory.getLogger(AriaParserServiceConsumer.class); - - public static AriaParserResult parseCsarPackage(String uri) throws CatalogResourceException { - logger.info("parseCsarPackage uri = " + uri); - return parseCsarPackage(new AriaParserRequest(uri, null)); - } - /** - * parse csar package via aria parser. - * - * @param request parse yaml request - * @return parase yaml result - * @throws CatalogResourceException e - */ - public static AriaParserResult parseCsarPackage(AriaParserRequest request) - throws CatalogResourceException { - try { - IAriaParserRest parseProxy = - ConsumerFactory.createConsumer( - Config.getConfigration().getMsbServerAddr(), - new ClientConfig(), - IAriaParserRest.class); - String strResult = parseProxy.parse(request); - AriaParserResult result = new Gson().fromJson(strResult, AriaParserResult.class); - result.setRawData(strResult); - validateResult(result, strResult); - return result; - } catch (Exception e) { - throw new CatalogResourceException("Call aria parser api failed.", e); - } - - } - private static void validateResult(AriaParserResult result, String strResult) throws CatalogResourceException { - if (result.getIssues() != null && result.getIssues().length > 0) { - logger.error("Aria parser return failure message: " + strResult); - throw new CatalogResourceException("Aria parser return failure message: " + strResult); - } - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/service/IAriaParserRest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/service/IAriaParserRest.java deleted file mode 100644 index df9e50d3..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/service/IAriaParserRest.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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.model.parser.yaml.aria.service; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.openo.commontosca.catalog.model.parser.yaml.aria.entity.AriaParserRequest; - - -@Path("/openoapi/tosca/v1") -public interface IAriaParserRest { - - @POST - @Path("/indirect/instance") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - String parse(AriaParserRequest request) throws Exception; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/EntrySchema.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/EntrySchema.java deleted file mode 100644 index 42542c6d..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/EntrySchema.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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.model.parser.yaml.yamlmodel; - -/** - * @author 10090474 - * - */ -public class EntrySchema { - private String type = ""; - - public EntrySchema() { - - } - - public EntrySchema(String type) { - super(); - this.type = type; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/Input.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/Input.java deleted file mode 100644 index 87483ffa..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/Input.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * 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.model.parser.yaml.yamlmodel; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class Input extends YAMLElement { - - private String type = ""; - private String defaultValue = ""; - private boolean required = false; - private List<Map<String, Object>> constraints = new ArrayList<Map<String, Object>>(); - private EntrySchema entry_schema; - - public String getType() { - return this.type; - } - - public void setType(String type) { - if (type != null) { - this.type = type; - } - } - - public String getDefault() { - return this.defaultValue; - } - - public void setDefault(String defaultValue) { - if (defaultValue != null) { - this.defaultValue = defaultValue; - } - } - - public List<Map<String, Object>> getConstraints() { - return this.constraints; - } - - public void setConstraints(List<Map<String, Object>> constraints) { - if (constraints != null) { - this.constraints = constraints; - } - } - - public boolean isRequired() { - return required; - } - - public void setRequired(boolean required) { - this.required = required; - } - - public EntrySchema getEntry_schema() { - return entry_schema; - } - - public void setEntry_schema(EntrySchema entry_schema) { - if (entry_schema != null) { - this.entry_schema = entry_schema; - } - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/Plan.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/Plan.java deleted file mode 100644 index c59a81c6..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/Plan.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.model.parser.yaml.yamlmodel; - -import java.util.HashMap; -import java.util.Map; - -/** - * - */ -public class Plan extends YAMLElement { - private String reference = ""; - private String planLanguage = ""; - private Map<String, Input> inputs = new HashMap<String, Input>(); - public String getReference() { - return reference; - } - public void setReference(String reference) { - this.reference = reference; - } - public String getPlanLanguage() { - return planLanguage; - } - public void setPlanLanguage(String planLanguage) { - this.planLanguage = planLanguage; - } - public Map<String, Input> getInputs() { - return inputs; - } - public void setInputs(Map<String, Input> inputs) { - this.inputs = inputs; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/ServiceTemplate.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/ServiceTemplate.java deleted file mode 100644 index c92e3c5b..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/ServiceTemplate.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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.model.parser.yaml.yamlmodel; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author 10090474 - * - */ -public class ServiceTemplate extends YAMLElement { - private Map<String, Plan> plans = new HashMap<>(); - - public Map<String, Plan> getPlans() { - return plans; - } - - public void setPlans(Map<String, Plan> plans) { - if (plans != null) { - this.plans = plans; - } - } -}
\ No newline at end of file diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/YAMLElement.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/YAMLElement.java deleted file mode 100644 index 0572f2fa..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/yamlmodel/YAMLElement.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.model.parser.yaml.yamlmodel; - -public abstract class YAMLElement { - - private String description = ""; - - public void setDescription(String description) { - if (description != null) { - this.description = description; - } - } - - public String getDescription() { - return this.description; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - YAMLElement element = (YAMLElement) o; - - if (!description.equals(element.description)) return false; - - return true; - } - - @Override - public int hashCode() { - return description.hashCode(); - } -}
\ No newline at end of file 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 deleted file mode 100644 index 632d60c4..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java +++ /dev/null @@ -1,235 +0,0 @@ -/** - * 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.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; -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.SubstitutionMapping; -import org.openo.commontosca.catalog.model.parser.AbstractModelParser; -import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlRequestParemeter; -import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlResult; -import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlResult.TopologyTemplate.Input; -import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlResult.TopologyTemplate.NodeTemplate.Relationship; -import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlResult.TopologyTemplate.Output; -import org.openo.commontosca.catalog.model.parser.yaml.zte.service.YamlParseServiceConsumer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ToscaYamlModelParser extends AbstractModelParser { - private static final Logger logger = LoggerFactory.getLogger(ToscaYamlModelParser.class); - - @Override - public String parse(String packageId, String fileLocation) throws CatalogResourceException { - logger.info("tosca-yaml-parser parse begin."); - ParseYamlResult result = getParseYamlResult(fileLocation); - - // service template - ServiceTemplate st = parseServiceTemplate( - result, packageId, parseServiceTemplateFileName(packageId, fileLocation)); - // workflow - ServiceTemplateOperation[] operations = parseOperations(fileLocation); - st.setOperations(operations); - // node templates - List<NodeTemplate> ntList = parseNodeTemplates(packageId, st.getServiceTemplateId(), result); - st.setType(getTemplateType(getSubstitutionType(result), ntList).toString()); - // save to db - TemplateManager.getInstance().addServiceTemplate( - TemplateDataHelper.convert2TemplateData(st, result.getRawData(), ntList)); - - // substitution - SubstitutionMapping stm = parseSubstitutionMapping(st.getServiceTemplateId(), result); - if (stm != null) { - TemplateManager.getInstance() - .addServiceTemplateMapping(TemplateDataHelper.convert2TemplateMappingData(stm)); - } - - return st.getServiceTemplateId(); - } - - private ParseYamlResult getParseYamlResult(String fileLocation) throws CatalogResourceException { - String destPath = copyTemporaryFile2HttpServer(fileLocation); - try { - String url = getUrlOnHttpServer(toTempFilePath(fileLocation)); - return YamlParseServiceConsumer.getServiceTemplates(comboRequest(url)); - } finally { - if (destPath != null && !destPath.isEmpty() && (new File(destPath)).exists()) { - (new File(destPath)).delete(); - } - } - } - - private ParseYamlRequestParemeter comboRequest(String fileLocation) { - ParseYamlRequestParemeter request = new ParseYamlRequestParemeter(); - request.setPath(fileLocation); - return request; - } - - private SubstitutionMapping parseSubstitutionMapping(String serviceTemplateId, - ParseYamlResult result) { - String type = getSubstitutionType(result); - if (ToolUtil.isTrimedEmptyString(type)) { - return null; - } - - org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlResult - .TopologyTemplate.SubstitutionMapping stm = - result.getTopologyTemplate().getSubstitutionMappings(); - 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, - String stDownloadUri) { - ServiceTemplate st = new ServiceTemplate(); - - st.setServiceTemplateId(ToolUtil.generateId()); - st.setId(parserId(result.getMetadata())); - st.setTemplateName(parserServiceTemplateName(result.getMetadata())); - st.setVendor(parserServiceTemplateVendor(result.getMetadata())); - st.setVersion(parserServiceTemplateVersion(result.getMetadata())); - st.setCsarId(packageId); - st.setDownloadUri(stDownloadUri); - st.setInputs(parseInputs(result)); - st.setOutputs(parseOutputs(result)); - return st; - } - - private InputParameter[] parseInputs(ParseYamlResult result) { - List<Input> inputList = result.getTopologyTemplate().getInputs(); - if (inputList == null) { - return new InputParameter[0]; - } - List<InputParameter> retList = new ArrayList<InputParameter>(); - for (Input input : inputList) { - retList.add(new InputParameter(input.getName(), input.getType(), - input.getDescription(), input.getDefault(), input.isRequired())); - } - return retList.toArray(new InputParameter[0]); - } - - private OutputParameter[] parseOutputs(ParseYamlResult result) { - List<Output> outputList = result.getTopologyTemplate().getOutputs(); - if (outputList == null || outputList.isEmpty()) { - return new OutputParameter[0]; - } - List<OutputParameter> retList = new ArrayList<OutputParameter>(); - for (Output output : outputList) { - retList - .add(new OutputParameter(output.getName(), output.getDescription(), output.getValue())); - } - return retList.toArray(new OutputParameter[0]); - } - - private List<NodeTemplate> parseNodeTemplates(String csarId, String templateId, - ParseYamlResult result) { - List<ParseYamlResult.TopologyTemplate.NodeTemplate> nodetemplateList = - result.getTopologyTemplate().getNodeTemplates(); - if (nodetemplateList == null) { - return null; - } - - List<NodeTemplate> retList = new ArrayList<>(); - for (ParseYamlResult.TopologyTemplate.NodeTemplate nodeTemplate : nodetemplateList) { - NodeTemplate ret = new NodeTemplate(); - ret.setId(nodeTemplate.getName()); - ret.setName(nodeTemplate.getName()); - ret.setType(nodeTemplate.getNodeType()); - ret.setProperties(nodeTemplate.getPropertyList()); - List<RelationShip> relationShipList = - parseNodeTemplateRelationShip(nodeTemplate.getRelationships()); - ret.setRelationShips(relationShipList); - - retList.add(ret); - } - - return retList; - } - - - private List<RelationShip> parseNodeTemplateRelationShip(List<Relationship> relationshipList) { - List<RelationShip> retList = new ArrayList<>(); - - if (relationshipList == null) { - return retList; - } - - for (Relationship relationship : relationshipList) { - RelationShip ret = new RelationShip(); - ret.setSourceNodeId(relationship.getSourceNodeName()); - ret.setSourceNodeName(relationship.getSourceNodeName()); - ret.setTargetNodeId(relationship.getTargetNodeName()); - ret.setTargetNodeName(relationship.getTargetNodeName()); - ret.setType(relationship.getType()); - retList.add(ret); - } - - return retList; - } - - private String getSubstitutionType(ParseYamlResult result) { - if (result.getTopologyTemplate().getSubstitutionMappings() == null) { - return null; - } - return result.getTopologyTemplate().getSubstitutionMappings().getNode_type(); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/EnumYamlServiceTemplateInfo.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/EnumYamlServiceTemplateInfo.java deleted file mode 100644 index a6a75ebf..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/EnumYamlServiceTemplateInfo.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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.model.parser.yaml.zte.entity; - - -//public enum EnumYamlServiceTemplateInfo { -// ID { -// @Override -// public String getName() { -// return "id"; -// } -// }, -// VERSION { -// @Override -// public String getName() { -// return "version"; -// } -// }, -// PROVIDER { -// @Override -// public String getName() { -// return "vendor"; -// } -// }; -// -// public abstract String getName(); -//} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/ParseYamlRequestParemeter.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/ParseYamlRequestParemeter.java deleted file mode 100644 index e598ef73..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/ParseYamlRequestParemeter.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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.model.parser.yaml.zte.entity; - -import java.util.List; - -public class ParseYamlRequestParemeter { - private String path = "E:\\NFVO\\130. yaml2xml\\0. tosca-parser\\sample\\ag-vnfd-floatingIp.zip"; - - private List<Extension> extension; - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public List<Extension> getExtension() { - return extension; - } - - public void setExtension(List<Extension> extension) { - this.extension = extension; - } - - public Extension createExtension() { - return new Extension(); - } - - public class Extension { - private String name; - private String value; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/ParseYamlResult.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/ParseYamlResult.java deleted file mode 100644 index 4fc2d825..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/ParseYamlResult.java +++ /dev/null @@ -1,883 +0,0 @@ -/** - * 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.model.parser.yaml.zte.entity; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import org.openo.commontosca.catalog.common.ToolUtil; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.annotations.SerializedName; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class ParseYamlResult { - private String toscaDefinitionsVersion; - private String description; - private JsonObject nodeTypes; - private JsonObject capabilityTypes; - private JsonObject relationshipTypes; - private JsonObject policyTypes; - private TopologyTemplate topologyTemplate; - private Map<String, String> metadata; - private JsonObject plans; - - private String rawData; - - public String getToscaDefinitionsVersion() { - return toscaDefinitionsVersion; - } - - public void setToscaDefinitionsVersion(String toscaDefinitionsVersion) { - this.toscaDefinitionsVersion = toscaDefinitionsVersion; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public JsonObject getNodeTypes() { - return nodeTypes; - } - - public void setNodeTypes(JsonObject nodeTypes) { - this.nodeTypes = nodeTypes; - } - - public List<NodeType> getNodeTypeList() { - return jsonObject2NodeTypes(nodeTypes); - } - - private ArrayList<NodeType> jsonObject2NodeTypes(JsonObject nodeTypes) { - ArrayList<NodeType> nodeTypeList = new ArrayList<NodeType>(); - Iterator<Entry<String, JsonElement>> iterator = nodeTypes.entrySet().iterator(); - while (iterator.hasNext()) { - NodeType type = new NodeType(); - Entry<String, JsonElement> next = iterator.next(); - type.setType(next.getKey()); - type.setValue(new Gson().fromJson(next.getValue(), NodeType.NodeTypeValue.class)); - nodeTypeList.add(type); - } - return nodeTypeList; - } - - public JsonObject getCapabilityTypes() { - return capabilityTypes; - } - - public void setCapabilityTypes(JsonObject capabilityTypes) { - this.capabilityTypes = capabilityTypes; - } - - public JsonObject getRelationshipTypes() { - return relationshipTypes; - } - - public void setRelationshipTypes(JsonObject relationshipTypes) { - this.relationshipTypes = relationshipTypes; - } - - public List<RelationshipType> getRelationshipTypeList() { - return jsonObject2RelationshipTypes(relationshipTypes); - } - - private ArrayList<RelationshipType> jsonObject2RelationshipTypes(JsonObject relationshipTypes) { - ArrayList<RelationshipType> relationshipTypeList = new ArrayList<RelationshipType>(); - Iterator<Entry<String, JsonElement>> iterator = relationshipTypes.entrySet().iterator(); - while (iterator.hasNext()) { - RelationshipType type = new RelationshipType(); - Entry<String, JsonElement> next = iterator.next(); - type.setType(next.getKey()); - type.setValue(new Gson().fromJson(next.getValue(), RelationshipType.RelationshipValue.class)); - relationshipTypeList.add(type); - } - return relationshipTypeList; - } - - public JsonObject getPolicyTypes() { - return policyTypes; - } - - public void setPolicyTypes(JsonObject policyTypes) { - this.policyTypes = policyTypes; - } - - public TopologyTemplate getTopologyTemplate() { - return topologyTemplate; - } - - public void setTopologyTemplate(TopologyTemplate topologyTemplate) { - this.topologyTemplate = topologyTemplate; - } - - public Map<String, String> getMetadata() { - if (this.metadata == null) { - return new HashMap<>(); - } - return metadata; - } - - public void setMetadata(Map<String, String> metadata) { - this.metadata = metadata; - } - - public JsonObject getPlans() { - return plans; - } - - public void setPlans(JsonObject plans) { - this.plans = plans; - } - - public List<Plan> getPlanList() { - return jsonObject2PlanList(this.plans); - } - - private List<Plan> jsonObject2PlanList(JsonObject plans) { - if (plans == null) { - return new ArrayList<>(); - } - List<Plan> retList = new ArrayList<>(); - Iterator<Entry<String, JsonElement>> iterator = plans.entrySet().iterator(); - while (iterator.hasNext()) { - Plan ret = new Plan(); - Entry<String, JsonElement> next = iterator.next(); - ret.setName(next.getKey()); - ret.setValue(new Gson().fromJson(next.getValue(), Plan.PlanValue.class)); - retList.add(ret); - } - return retList; - } - - public class TopologyTemplate { - private String description; - private List<Input> inputs; - private List<Output> outputs; - private List<NodeTemplate> nodeTemplates; - private SubstitutionMapping substitutionMappings; - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public List<Input> getInputs() { - return inputs; - } - - public void setInputs(List<Input> inputs) { - this.inputs = inputs; - } - - public List<Output> getOutputs() { - return outputs; - } - - public void setOutputs(List<Output> outputs) { - this.outputs = outputs; - } - - public List<NodeTemplate> getNodeTemplates() { - return nodeTemplates; - } - - public void setNodeTemplates(List<NodeTemplate> nodeTemplates) { - this.nodeTemplates = nodeTemplates; - } - - public SubstitutionMapping getSubstitutionMappings() { - return substitutionMappings; - } - - public void setSubstitutionMappings(SubstitutionMapping substitutionMappings) { - this.substitutionMappings = substitutionMappings; - } - - public class Input { - private String name; - private String type; - private String description; - private String defaultValue; - private boolean required; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getDefault() { - return defaultValue; - } - - public void setDefault(String defaultValue) { - this.defaultValue = defaultValue; - } - - public boolean isRequired() { - return required; - } - - public void setRequired(boolean required) { - this.required = required; - } - } - - public class Output { - private String name; - private String description; - private Object value; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Object getValue() { - return value; - } - - public void setValue(Object value) { - this.value = value; - } - } - - public class NodeTemplate { - private String name; - private String nodeType; - private JsonObject properties; - private JsonObject[] requirements; - private JsonObject capabilities; - private List<Relationship> relationships; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getNodeType() { - return nodeType; - } - - public void setNodeType(String nodeType) { - this.nodeType = nodeType; - } - - public JsonObject getProperties() { - return properties; - } - - public void setProperties(JsonObject properties) { - this.properties = properties; - } - - public Map<String, Object> getPropertyList() { - return jsonObject2Properties(properties); - } - - private Map<String, Object> jsonObject2Properties(JsonObject properties) { - Map<String, Object> ret = new HashMap<>(); - Iterator<Entry<String, JsonElement>> iterator = properties.entrySet().iterator(); - while (iterator.hasNext()) { - Entry<String, JsonElement> next = iterator.next(); - ret.put(next.getKey(), ToolUtil.getAsString(next.getValue())); - } - return ret; - } - - public JsonObject[] getRequirements() { - return requirements; - } - - public void setRequirements(JsonObject[] requirements) { - this.requirements = requirements; - } - - public JsonObject getCapabilities() { - return capabilities; - } - - public void setCapabilities(JsonObject capabilities) { - this.capabilities = capabilities; - } - - public List<Relationship> getRelationships() { - return relationships; - } - - public void setRelationships(List<Relationship> relationships) { - this.relationships = relationships; - } - - /** - * get scalable. - * @return NodeTemplateScalable - */ - public NodeTemplateScalable getScalable() { - if (capabilities == null) { - return null; - } - JsonElement scaleableJson = capabilities.get("scalable"); - if (scaleableJson == null || !scaleableJson.isJsonObject()) { - return null; - } - JsonElement propertyJson = scaleableJson.getAsJsonObject().get("properties"); - if (propertyJson == null || !propertyJson.isJsonObject()) { - return null; - } - - NodeTemplateScalable scalable = new NodeTemplateScalable(); - scalable.setMin_instances( - ToolUtil.getAsString(propertyJson.getAsJsonObject().get("min_instances"))); - scalable.setMax_instances( - ToolUtil.getAsString(propertyJson.getAsJsonObject().get("max_instances"))); - scalable.setDefault_instances( - ToolUtil.getAsString(propertyJson.getAsJsonObject().get("default_instances"))); - return scalable; - } - - public class Relationship { - private String targetNodeName; - private String type; - private String sourceNodeName; - - public String getTargetNodeName() { - return targetNodeName; - } - - public void setTargetNodeName(String targetNodeName) { - this.targetNodeName = targetNodeName; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getSourceNodeName() { - return sourceNodeName; - } - - public void setSourceNodeName(String sourceNodeName) { - this.sourceNodeName = sourceNodeName; - } - } - - public class NodeTemplateScalable { - private String minInstances; - private String maxInstances; - private String defaultInstances; - - public String getMin_instances() { - return minInstances; - } - - public void setMin_instances(String minInstances) { - this.minInstances = minInstances; - } - - public String getMax_instances() { - return maxInstances; - } - - public void setMax_instances(String maxInstances) { - this.maxInstances = maxInstances; - } - - public String getDefault_instances() { - return defaultInstances; - } - - public void setDefault_instances(String defaultInstances) { - this.defaultInstances = defaultInstances; - } - } - } - - public class SubstitutionMapping { - private String node_type; - private JsonObject requirements; - private JsonObject capabilities; - - public String getNode_type() { - return node_type; - } - - public void setNode_type(String node_type) { - this.node_type = node_type; - } - - public JsonObject getRequirements() { - return requirements; - } - - public void setRequirements(JsonObject requirements) { - this.requirements = requirements; - } - - public Map<String, String[]> getRequirementList() { - return jsonObjects2Requirements(this.requirements); - } - - private Map<String, String[]> jsonObjects2Requirements(JsonObject requirements) { - if (requirements == null) { - return new HashMap<String, String[]>(); - } - - Map<String, String[]> ret = new HashMap<String, String[]>(); - Iterator<Entry<String, JsonElement>> iterator = requirements.entrySet().iterator(); - while (iterator.hasNext()) { - Entry<String, JsonElement> next = iterator.next(); - if (next.getValue().isJsonPrimitive() || next.getValue().isJsonObject()) { - ret.put(next.getKey(), new String[] {ToolUtil.getAsString(next.getValue())}); - continue; - } - - if (next.getValue().isJsonArray()) { - String[] value = parseListValue((JsonArray) next.getValue()); - ret.put(next.getKey(), value); - } - } - - return ret; - } - - private String[] parseListValue(JsonArray jsonArray) { - String[] value = new String[jsonArray.size()]; - for (int i = 0, size = jsonArray.size(); i < size; i++) { - value[i] = ToolUtil.getAsString(jsonArray.get(i)); - } - return value; - } - - public JsonObject getCapabilities() { - return capabilities; - } - - public void setCapabilities(JsonObject capabilities) { - this.capabilities = capabilities; - } - - public Map<String, String[]> getCapabilityList() { - return jsonObject2Capabilities(this.capabilities); - } - - private Map<String, String[]> jsonObject2Capabilities(JsonObject capabilities) { - if (capabilities == null) { - return new HashMap<String, String[]>(); - } - - Map<String, String[]> ret = new HashMap<String, String[]>(); - Iterator<Entry<String, JsonElement>> iterator = capabilities.entrySet().iterator(); - while (iterator.hasNext()) { - Entry<String, JsonElement> next = iterator.next(); - if (next.getValue().isJsonPrimitive() || next.getValue().isJsonObject()) { - ret.put(next.getKey(), new String[] {ToolUtil.getAsString(next.getValue())}); - continue; - } - - if (next.getValue().isJsonArray()) { - String[] value = parseListValue((JsonArray) next.getValue()); - ret.put(next.getKey(), value); - } - } - - return ret; - } - } - } - - - public class RelationshipType { - private String type; - private RelationshipValue value; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public RelationshipValue getValue() { - return value; - } - - public void setValue(RelationshipValue value) { - this.value = value; - } - - public class RelationshipValue { - private String derivedFrom; - private String[] validTargetTypes; - - public String getDerivedFrom() { - return derivedFrom; - } - - public void setDerivedFrom(String derivedFrom) { - this.derivedFrom = derivedFrom; - } - - public String[] getValid_target_types() { - return validTargetTypes; - } - - public void setValid_target_types(String[] validTargetTypes) { - this.validTargetTypes = validTargetTypes; - } - } - } - - - public class NodeType { - private String type; - private NodeTypeValue value; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public NodeTypeValue getValue() { - return value; - } - - public void setValue(NodeTypeValue value) { - this.value = value; - } - - public class NodeTypeValue { - private String derivedFrom; - private JsonObject properties; - private JsonObject[] requirements; - private JsonObject capabilities; - - public String getDerivedFrom() { - return derivedFrom; - } - - public void setDerived_from(String derivedFrom) { - this.derivedFrom = derivedFrom; - } - - public JsonObject getProperties() { - return properties; - } - - public void setProperties(JsonObject properties) { - this.properties = properties; - } - - public List<NodeTypeProperty> getPropertyList() { - return jsonObject2Properties(properties); - } - - private List<NodeTypeProperty> jsonObject2Properties(JsonObject properties) { - List<NodeTypeProperty> propertieList = new ArrayList<NodeTypeProperty>(); - Iterator<Entry<String, JsonElement>> iterator = properties.entrySet().iterator(); - while (iterator.hasNext()) { - NodeTypeProperty type = new NodeTypeProperty(); - Entry<String, JsonElement> next = iterator.next(); - type.setKey(next.getKey()); - type.setValue(new Gson().fromJson(next.getValue(), JsonObject.class)); - propertieList.add(type); - } - return propertieList; - } - - public class NodeTypeProperty { - private String key; - private JsonObject value; - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - /** - * get default value. - * @return default value - */ - public String getDefaultValue() { - JsonElement defaultValue = value.get("default"); - if (defaultValue == null || defaultValue.isJsonObject()) { - return ""; - } - - return ToolUtil.getAsString(defaultValue); - } - - public JsonObject getValue() { - return value; - } - - public void setValue(JsonObject value) { - this.value = value; - } - } - - public JsonObject[] getRequirements() { - return requirements; - } - - public void setRequirements(JsonObject[] requirements) { - this.requirements = requirements; - } - - public JsonObject getCapabilities() { - return capabilities; - } - - public void setCapabilities(JsonObject capabilities) { - this.capabilities = capabilities; - } - } - } - - public class Plan { - private String name; - private PlanValue value; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return value.getDescription(); - } - - public String getReference() { - return value.getReference(); - } - - public String getPlanLanguage() { - return value.getPlanLanguage(); - } - - public List<PlanValue.PlanInput> getInputList() { - return value.getInputList(); - } - - public PlanValue getValue() { - return value; - } - - public void setValue(PlanValue value) { - this.value = value; - } - - public class PlanValue { - private String description; - private String reference; - private String planLanguage; - private JsonObject inputs; - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getReference() { - return reference; - } - - public void setReference(String reference) { - this.reference = reference; - } - - public String getPlanLanguage() { - return planLanguage; - } - - public void setPlanLanguage(String planLanguage) { - this.planLanguage = planLanguage; - } - - public JsonObject getInputs() { - return inputs; - } - - public void setInputs(JsonObject inputs) { - this.inputs = inputs; - } - - public List<PlanInput> getInputList() { - return jsonObject2PlanInputList(inputs); - - } - - private List<PlanInput> jsonObject2PlanInputList(JsonObject inputs) { - List<PlanInput> retList = new ArrayList<PlanInput>(); - Iterator<Entry<String, JsonElement>> iterator = inputs.entrySet().iterator(); - while (iterator.hasNext()) { - PlanInput ret = new PlanInput(); - Entry<String, JsonElement> next = iterator.next(); - ret.setName(next.getKey()); - ret.setValue(new Gson().fromJson(next.getValue(), PlanInput.PlanInputValue.class)); - retList.add(ret); - } - return retList; - } - - public class PlanInput { - private String name; - private PlanInputValue value; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getType() { - return value.getType(); - } - - public String getDescription() { - return value.getDescription(); - } - - public String getDefault() { - return value.getDefaultValue(); - } - - public boolean isRequired() { - return value.isRequired(); - } - - public PlanInputValue getValue() { - return value; - } - - public void setValue(PlanInputValue value) { - this.value = value; - } - - public class PlanInputValue { - private String type; - private String description; - @SerializedName("default") - private String defaultValue; - private boolean required; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getDefaultValue() { - return defaultValue; - } - - public void setDefaultValue(String defaultValue) { - this.defaultValue = defaultValue; - } - - public boolean isRequired() { - return required; - } - - public void setRequired(boolean required) { - this.required = required; - } - } - } - } - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/service/IYamlParseRest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/service/IYamlParseRest.java deleted file mode 100644 index 157a5073..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/service/IYamlParseRest.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.model.parser.yaml.zte.service; - -import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlRequestParemeter; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - - -@Path("/parse") -public interface IYamlParseRest { - - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - String parse(ParseYamlRequestParemeter request) throws Exception; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/service/YamlParseServiceConsumer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/service/YamlParseServiceConsumer.java deleted file mode 100644 index 2d9bd045..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/service/YamlParseServiceConsumer.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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.model.parser.yaml.zte.service; - -import com.google.gson.Gson; -import com.eclipsesource.jaxrs.consumer.ConsumerFactory; - -import org.glassfish.jersey.client.ClientConfig; -import org.openo.commontosca.catalog.common.MsbUtil; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlRequestParemeter; -import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class YamlParseServiceConsumer { - private static final Logger logger = LoggerFactory.getLogger(YamlParseServiceConsumer.class); - /** - * get service template by template id from container service. - * - * @param request parse yaml request - * @return parase yaml result - * @throws CatalogResourceException e - */ - public static ParseYamlResult getServiceTemplates(ParseYamlRequestParemeter request) - throws CatalogResourceException { - logger.info("parseCsarPackage uri = " + request.getPath()); - - try { - ClientConfig config = new ClientConfig(); - IYamlParseRest yamlParseProxy = - ConsumerFactory.createConsumer(MsbUtil.getYamlParseBaseUrl(), config, - IYamlParseRest.class); - String jsonStr = yamlParseProxy.parse(request); - ParseYamlResult result = new Gson().fromJson(jsonStr, ParseYamlResult.class); - result.setRawData(jsonStr); - return result; - } catch (Exception e1) { - throw new CatalogResourceException("Call parser api failed.", e1); - } - - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Iwso2RestService.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Iwso2RestService.java deleted file mode 100644 index 8442d1f5..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Iwso2RestService.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * 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.model.plan.wso2; - -import org.openo.commontosca.catalog.model.plan.wso2.entity.DeletePackageResponse; -import org.openo.commontosca.catalog.model.plan.wso2.entity.StartProcessRequest; -import org.openo.commontosca.catalog.model.plan.wso2.entity.StartProcessResponse; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -@Path("/openoapi/wso2bpel/v1") -public interface Iwso2RestService { - // /** - // * @param request - // * @return - // * @throws Exception - // */ - // @Path("/package") - // @POST - // @Consumes(MediaType.APPLICATION_JSON) - // @Produces(MediaType.APPLICATION_JSON) - // DeployPackageResponse deployPackage(FormDataMultiPart request) throws Exception; - - @Path("/package/{packageName}") - @DELETE - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - DeletePackageResponse deletePackage( - @PathParam("packageName") String packageName) throws Exception; - - @Path("process/instance") - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - StartProcessResponse startProcess(StartProcessRequest request) - throws Exception; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/RestResponse.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/RestResponse.java deleted file mode 100644 index d10e5825..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/RestResponse.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.model.plan.wso2; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -public class RestResponse { - - private Integer statusCode; - - private String result; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/RestfulClient.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/RestfulClient.java deleted file mode 100644 index aecd5e10..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/RestfulClient.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * 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.model.plan.wso2; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -public class RestfulClient { - private static final String HTTP = "http"; - private static final Logger logger = LoggerFactory.getLogger(RestfulClient.class); - - enum HttpMethod { - GET, POST, PUT, DELETE - } - - /** - * execute http. - * @param method http method - * @param ip ip - * @param port port - * @param url url - * @param body http body - * @return RestResponse - */ - public static RestResponse executeHttp(HttpMethod method, String ip, int port, String url, - HttpEntity body) { - CloseableHttpClient httpclient = HttpClients.createDefault(); - HttpResponse httpResponse = null; - RestResponse result = new RestResponse(); - try { - // specify the host, protocol, and port - HttpHost target = new HttpHost(ip, port, HTTP); - // specify the get request - HttpRequest request = getRequest(method, url, body); - httpResponse = httpclient.execute(target, request); - HttpEntity entity = httpResponse.getEntity(); - if (entity != null) { - result.setStatusCode(httpResponse.getStatusLine().getStatusCode()); - result.setResult(EntityUtils.toString(entity)); - } - } catch (Exception e1) { - logger.error("send get rest request error:", e1.getMessage()); - } finally { - if (httpclient != null) { - try { - httpclient.close(); - } catch (IOException e2) { - logger.error("close httpclient error:", e2.getMessage()); - } - } - } - return result; - } - - private static HttpRequest getRequest(HttpMethod method, String url, HttpEntity body) { - HttpRequest request = null; - switch (method) { - case GET: - request = new HttpGet(url); - break; - case POST: - request = new HttpPost(url); - ((HttpPost) request).setEntity(body); - break; - case PUT: - request = new HttpPut(url); - ((HttpPut) request).setEntity(body); - break; - case DELETE: - request = new HttpDelete(url); - break; - default: - break; - } - return request; - } - - public static String get(String ip, int port, String url) { - return executeHttp(HttpMethod.GET, ip, port, url, null).getResult(); - } - - public static RestResponse delete(String ip, int port, String url) { - return executeHttp(HttpMethod.GET, ip, port, url, null); - } - - public static RestResponse post(String ip, int port, String url, HttpEntity requestBody) { - return executeHttp(HttpMethod.POST, ip, port, url, requestBody); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Wso2ServiceConsumer.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Wso2ServiceConsumer.java deleted file mode 100644 index 67f9a9e3..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/Wso2ServiceConsumer.java +++ /dev/null @@ -1,185 +0,0 @@ -/** - * 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.model.plan.wso2; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import org.apache.http.HttpEntity; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.mime.MultipartEntityBuilder; -import org.glassfish.jersey.client.ClientConfig; -import org.openo.commontosca.catalog.common.Config; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.model.common.TemplateUtils; -import org.openo.commontosca.catalog.model.plan.wso2.entity.DeletePackageResponse; -import org.openo.commontosca.catalog.model.plan.wso2.entity.DeployPackageResponse; -import org.openo.commontosca.catalog.model.plan.wso2.entity.StartProcessRequest; -import org.openo.commontosca.catalog.model.plan.wso2.entity.StartProcessResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.eclipsesource.jaxrs.consumer.ConsumerFactory; -import com.google.gson.Gson; - - -public class Wso2ServiceConsumer { - public static final String WSO2_APP_URL = "/openoapi/wso2bpel/v1/package"; - private static final Logger logger = LoggerFactory.getLogger(Wso2ServiceConsumer.class); - - /** - * deploy package. - * @param zipFileLocation zip file location - * @param planFilePath plan file path - * @return DeployPackageResponse - * @throws CatalogResourceException e1 - */ - public static DeployPackageResponse deployPackage(String zipFileLocation, String planFilePath) - throws CatalogResourceException { - IpPort ipPort = getIpPort(Config.getConfigration().getMsbServerAddr()); - if (ipPort == null) { - throw new CatalogResourceException("getMsbServerAddr failed."); - } - ZipFile zf = null; - InputStream ins = null; - try { - zf = new ZipFile(zipFileLocation); - ins = getInputStream(zf, planFilePath); - RestResponse res = RestfulClient.post( - ipPort.getIp(), ipPort.getPort(), WSO2_APP_URL, - buildRequest(ins, planFilePath)); - - if (res.getStatusCode() == null || res.getResult() == null) { - throw new CatalogResourceException( - "Deploy Package return null. Response = " + res); - } - - if (200 == res.getStatusCode() || 201 == res.getStatusCode()) { - DeployPackageResponse response = - new Gson().fromJson(res.getResult(), DeployPackageResponse.class); - if (response.isSuccess()) { - return response; - } - } - - throw new CatalogResourceException( - "Deploy Package return failed. Response = " + res.getResult()); - } catch (FileNotFoundException e) { - throw new CatalogResourceException("buildRequest failed.", e); - } catch (IOException e) { - throw new CatalogResourceException("ZipFile failed.", e); - } finally { - TemplateUtils.closeInputStream(ins); - TemplateUtils.closeZipFile(zf); - } - } - - @Data - @NoArgsConstructor - @AllArgsConstructor - public static class IpPort { - private String ip; - private int port; - } - - private static IpPort getIpPort(String addr) { - Pattern p = Pattern.compile("//(.*?):(.*)"); - Matcher m = p.matcher(addr); - while(m.find()){ - return new IpPort(m.group(1), Integer.valueOf(m.group(2))); - } - return null; - } - - private static HttpEntity buildRequest(InputStream inputStream, String filePath) - throws FileNotFoundException { - MultipartEntityBuilder builder = MultipartEntityBuilder.create(); - builder.seContentType(ContentType.MULTIPART_FORM_DATA); - builder.addBinaryBody("file", inputStream, ContentType.APPLICATION_OCTET_STREAM, - new File(filePath).getName()); - return builder.build(); - } - - private static InputStream getInputStream(ZipFile zf, String planFilePath) - throws CatalogResourceException, IOException { - ZipEntry ze = TemplateUtils.getZipEntryZipFile(zf, planFilePath); - - if (ze == null) { - throw new CatalogResourceException("Can't file plan file in the csar. planFilePath = " + planFilePath); - } - return zf.getInputStream(ze); - } - - /** - * delet package. - * @param packageName package to delete according packageName - * @return DeletePackageResponse - * @throws CatalogResourceException e1 - */ - public static DeletePackageResponse deletePackage(String packageName) - throws CatalogResourceException { - try { - ClientConfig config = new ClientConfig(); - Iwso2RestService wso2Proxy = ConsumerFactory.createConsumer( - Config.getConfigration().getMsbServerAddr(), config, Iwso2RestService.class); - DeletePackageResponse response = wso2Proxy.deletePackage(packageName); - if (response.isSuccess()) { - return response; - } - throw new CatalogResourceException(response.toString()); - } catch (Exception e) { - throw new CatalogResourceException( - "Call Delete Package api failed. packageName = " + packageName, e); - } - } - - - /** - * start process. - * @param processId process id - * @param params params - * @return StartProcessResponse - * @throws CatalogResourceException e1 - */ - public static StartProcessResponse startProcess(String processId, Map<String, Object> params) - throws CatalogResourceException { - try { - ClientConfig config = new ClientConfig(); - Iwso2RestService wso2Proxy = ConsumerFactory.createConsumer( - Config.getConfigration().getMsbServerAddr(), config, Iwso2RestService.class); - StartProcessResponse response = - wso2Proxy.startProcess(new StartProcessRequest(processId, params)); - if (response.isSuccess()) { - return response; - } - throw new CatalogResourceException(response.toString()); - } catch (Exception e) { - throw new CatalogResourceException("Call Start Process api failed.", e); - } - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/DeletePackageResponse.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/DeletePackageResponse.java deleted file mode 100644 index c3b04092..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/DeletePackageResponse.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.model.plan.wso2.entity; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -public class DeletePackageResponse { - private static final int STATUS_SUCCESS = 1; - - private int status; - private String message; - private String exception; - - public boolean isSuccess() { - return this.status == STATUS_SUCCESS; - } - - @Override - public String toString() { - return "DeletePackageResponse [status=" + status + ", message=" + message + ", exception=" - + exception + "]"; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/DeployPackageResponse.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/DeployPackageResponse.java deleted file mode 100644 index d106b89d..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/DeployPackageResponse.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.model.plan.wso2.entity; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -public class DeployPackageResponse { - private static final int STATUS_SUCCESS = 1; - - private int status; - private String message; - private String packageName; - private String processId; - private String exception; - - public boolean isSuccess() { - return this.status == STATUS_SUCCESS; - } - - @Override - public String toString() { - return "DeployPackageResponse [status=" + status + ", message=" + message + ", packageName=" - + packageName + ", processId=" + processId + ", exception=" + exception + "]"; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/StartProcessRequest.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/StartProcessRequest.java deleted file mode 100644 index 69ada249..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/StartProcessRequest.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.model.plan.wso2.entity; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.Map; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -public class StartProcessRequest { - private String processId; - private Map<String, Object> params; -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/StartProcessResponse.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/StartProcessResponse.java deleted file mode 100644 index 7e01e770..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/plan/wso2/entity/StartProcessResponse.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.model.plan.wso2.entity; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -public class StartProcessResponse { - private static final int STATUS_SUCCESS = 1; - - private int status; - private String message; - private String response; - private String exception; - - public boolean isSuccess() { - return this.status == STATUS_SUCCESS; - } - - @Override - public String toString() { - return "StartProcessResponse [status=" + status + ", message=" + message + ", response=" - + response + ", exception=" + exception + "]"; - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/service/ModelService.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/service/ModelService.java deleted file mode 100644 index bdbafb87..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/service/ModelService.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * 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.model.service; - -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.resource.TemplateManager; -import org.openo.commontosca.catalog.model.entity.ServiceTemplate; -import org.openo.commontosca.catalog.model.entity.ServiceTemplateOperation; -import org.openo.commontosca.catalog.model.plan.wso2.Wso2ServiceConsumer; -import org.openo.commontosca.catalog.model.wrapper.ServiceTemplateWrapper; -import org.openo.commontosca.catalog.resources.CatalogBadRequestException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ModelService { - private static final Logger logger = LoggerFactory.getLogger(ModelService.class); - - private static ModelService instance; - - public static ModelService getInstance() { - if (instance == null) { - instance = new ModelService(); - } - return instance; - } - - - /** - * delete service template according package id. - * - * @param packageId package id - * @throws CatalogBadRequestException e1 - * @throws CatalogResourceException e2 - */ - public void delete(String packageId) throws CatalogResourceException { - logger.info("delete package model data begin."); - - ServiceTemplate st = getServiceTemplateByCsarIdIgnoreError(packageId); - if (st == null) { - return; - } - - undeployOperationPackage(st.getOperations()); - - TemplateManager.getInstance().deleteServiceTemplateById(st.getServiceTemplateId()); - TemplateManager.getInstance().deleteServiceTemplateMapping(null, st.getServiceTemplateId()); - - logger.info("delete package model data end."); - } - - private void undeployOperationPackage(ServiceTemplateOperation[] operations) - throws CatalogResourceException { - if (operations != null && operations.length > 0) { - for (ServiceTemplateOperation op : operations) { - Wso2ServiceConsumer.deletePackage(op.getPackageName()); - } - } - } - - private ServiceTemplate getServiceTemplateByCsarIdIgnoreError(String packageId) { - try { - return ServiceTemplateWrapper.getInstance().getServiceTemplateByCsarId(packageId); - } catch (CatalogBadRequestException ignore) { - logger.info("delete package model data ignore.", ignore); - } catch (CatalogResourceException ignore) { - logger.info("delete package model data ignore.", ignore); - } - - return null; - } - - /** - * delete service template data only, not undeploy operation package. - * - * @param packageId package id - * @throws CatalogBadRequestException e1 - * @throws CatalogResourceException e2 - */ - public void deleteServiceTemplateData(String packageId) throws CatalogResourceException { - logger.info("delete service template data begin."); - - ServiceTemplate st = getServiceTemplateByCsarIdIgnoreError(packageId); - if (st == null) { - return; - } - - TemplateManager.getInstance().deleteServiceTemplateById(st.getServiceTemplateId()); - TemplateManager.getInstance().deleteServiceTemplateMapping(null, st.getServiceTemplateId()); - - logger.info("delete service template data end."); - } - - /** - * undeploy operation package of the service template. - * - * @param packageId package id - * @throws CatalogBadRequestException e1 - * @throws CatalogResourceException e2 - */ - public void undeployOperationPackage(String packageId) throws CatalogResourceException { - logger.info("undeploy operation package begin."); - - ServiceTemplate st = getServiceTemplateByCsarIdIgnoreError(packageId); - if (st == null) { - return; - } - - undeployOperationPackage(st.getOperations()); - - logger.info("undeploy operation package end."); - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/wrapper/ServiceTemplateWrapper.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/wrapper/ServiceTemplateWrapper.java deleted file mode 100644 index 56db0aee..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/wrapper/ServiceTemplateWrapper.java +++ /dev/null @@ -1,378 +0,0 @@ -/** - * 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.model.wrapper; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.openo.commontosca.catalog.common.ToolUtil; -import org.openo.commontosca.catalog.db.entity.NodeTemplateData; -import org.openo.commontosca.catalog.db.entity.PackageData; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; -import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.resource.TemplateManager; -import org.openo.commontosca.catalog.entity.EnumOperationalState; -import org.openo.commontosca.catalog.model.common.TemplateDataHelper; -import org.openo.commontosca.catalog.model.entity.InputParameter; -import org.openo.commontosca.catalog.model.entity.NfvTemplate; -import org.openo.commontosca.catalog.model.entity.NodeTemplate; -import org.openo.commontosca.catalog.model.entity.Parameters; -import org.openo.commontosca.catalog.model.entity.QueryRawDataCondition; -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.resources.CatalogBadRequestException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class ServiceTemplateWrapper { - private static ServiceTemplateWrapper instance; - private static final Logger logger = LoggerFactory.getLogger(ServiceTemplateWrapper.class); - - /** - * get service template wrapper instance. - * @return ServiceTemplateWrapper instance - */ - public static ServiceTemplateWrapper getInstance() { - if (instance == null) { - instance = new ServiceTemplateWrapper(); - } - return instance; - } - - /** - * get service template by id. - * @param serviceTemplateId service template id - * @return service template - * @throws CatalogResourceException e1 - */ - public ServiceTemplate getServiceTemplateById(String serviceTemplateId) - throws CatalogResourceException { - logger.info("getServiceTemplateById. serviceTemplateId = " + serviceTemplateId); - - List<ServiceTemplateData> stdList = - TemplateManager.getInstance().queryServiceTemplateById(serviceTemplateId); - if (stdList == null || stdList.isEmpty()) { - throw new CatalogResourceException("Can't find this servcie template"); - } - - return TemplateDataHelper.convert2ServiceTemplate(stdList.get(0)); - } - - - /** - * get service templates. - * @param status usage status - * @param deletionPending package's deletionPending - * @return service template list - * @throws CatalogResourceException e - */ - public ServiceTemplate[] getServiceTemplates(EnumOperationalState status, boolean deletionPending) - throws CatalogResourceException { - PackageData pd = new PackageData(); - if (status != null) { - pd.setOperationalState(status.toString()); - } - pd.setDeletionPending(String.valueOf(deletionPending)); - - List<ServiceTemplateData> stdList = - TemplateManager.getInstance().queryServiceTemplateByCsarPackageInfo(pd); - - return TemplateDataHelper.convert2ServiceTemplates(stdList); - } - - public ServiceTemplate[] getServiceTemplates() throws CatalogResourceException { - return TemplateDataHelper.convert2ServiceTemplates( - TemplateManager.getInstance().queryServiceTemplate(null, null, null)); - } - - - /** - * get nesting service template. - * @param nodeTypeIds nodeType id list - * @return service template list - * @throws CatalogResourceException e - */ - public ServiceTemplate[] getNestingServiceTemplate(String[] nodeTypeIds) - throws CatalogResourceException { - ServiceTemplate[] sts = new ServiceTemplate[nodeTypeIds.length]; - for (int i = 0; i < nodeTypeIds.length; i++) { - SubstitutionMapping stm = getSubstitutionMappingsByNodeTypeId(nodeTypeIds[i]); - if (stm == null) { - sts[i] = null; - continue; - } - sts[i] = getServiceTemplate(stm, nodeTypeIds[i]); - } - - return sts; - } - - private ServiceTemplate getServiceTemplate(SubstitutionMapping stm, String nodeTypeId) { - try { - return getServiceTemplateById(stm.getServiceTemplateId()); - } catch (CatalogResourceException e) { - logger.warn("Get Nesting ServiceTemplate Failed. NodeTypeIds = " + nodeTypeId, e); - return null; - } - } - - /** - * get substitution mappings by nodeTpe id. - * @param nodeTypeId nodeType id - * @return SubstitutionMapping - * @throws CatalogResourceException e - */ - private SubstitutionMapping getSubstitutionMappingsByNodeTypeId(String nodeTypeId) - throws CatalogResourceException { - List<ServiceTemplateMappingData> stmDataList = - TemplateManager.getInstance().queryServiceTemplateMapping(nodeTypeId, null); - if (stmDataList == null || stmDataList.isEmpty()) { - return null; - } - - return TemplateDataHelper.convert2SubstitutionMapping(stmDataList.get(0)); - } - - - /** - * get service template raw data. - * @param queryCondition query raw data condition - * @return ServiceTemplateRawData - * @throws CatalogResourceException e1 - * @throws CatalogBadRequestException e2 - */ - public ServiceTemplateRawData getServiceTemplateRawData(QueryRawDataCondition queryCondition) - throws CatalogResourceException, CatalogBadRequestException { - ServiceTemplateData std = getServiceTemplateDataByCsarId(queryCondition.getCsarId()); - return new ServiceTemplateRawData(std.getRowData()); - } - - /** - * get service template data by package id. - * @param csarId package id - * @return ServiceTemplateData - * @throws CatalogBadRequestException e1 - * @throws CatalogResourceException e2 - */ - private ServiceTemplateData getServiceTemplateDataByCsarId(String csarId) - throws CatalogBadRequestException, CatalogResourceException { - if (ToolUtil.isTrimedEmptyString(csarId)) { - throw new CatalogBadRequestException("CsarId is null."); - } - PackageData pd = new PackageData(); - pd.setCsarId(csarId); - - List<ServiceTemplateData> stdList = - TemplateManager.getInstance().queryServiceTemplateByCsarPackageInfo(pd); - - if (stdList == null || stdList.isEmpty()) { - throw new CatalogResourceException("Can't find this servcie template"); - } - - return stdList.get(0); - } - - /** - * get service template by package id. - * @param packageId package id - * @return service template data - * @throws CatalogBadRequestException e1 - * @throws CatalogResourceException e2 - */ - public ServiceTemplate getServiceTemplateByCsarId(String packageId) - throws CatalogBadRequestException, CatalogResourceException { - ServiceTemplateData std = getServiceTemplateDataByCsarId(packageId); - ServiceTemplate st = TemplateDataHelper.convert2ServiceTemplate(std); - return st; - } - - /** - * get service template parameters. - * @param serviceTemplateId service template id - * @return service template parameters - * @throws CatalogResourceException e - */ - public Parameters getServiceTemplateParameters(String serviceTemplateId) - throws CatalogResourceException { - ServiceTemplate st = getServiceTemplateById(serviceTemplateId); - return new Parameters(st.getInputs(), st.getOutputs()); - } - - /** - * get template operation. - * @param serviceTemplateId service template id - * @return service template operations - */ - public ServiceTemplateOperation[] getTemplateOperations(String serviceTemplateId) - throws CatalogResourceException { - ServiceTemplate st = getServiceTemplateById(serviceTemplateId); - - if (st.getOperations() == null) { - return new ServiceTemplateOperation[0]; - } - return st.getOperations(); - } - - /** - * get parameters by operation name. - * @param serviceTemplateId service template id - * @param operationName operation name - * @return InputParameter list - * @throws CatalogResourceException e - */ - public InputParameter[] getParametersByOperationName(String serviceTemplateId, - String operationName) throws CatalogResourceException { - if (ToolUtil.isTrimedEmptyString(operationName)) { - throw new CatalogResourceException("Operation Name is null."); - } - - ServiceTemplateOperation[] operations = getTemplateOperations(serviceTemplateId); - for (int i = 0; i < operations.length; i++) { - if (operationName.equals(operations[i].getName())) { - return operations[i].getInputs(); - } - } - - throw new CatalogResourceException("Can't find this operation."); - } - - - /** - * get nodeTemplate by id. - * @param serviceTemplateId service template id - * @param nodeTemplateId node template id - * @return NodeTemplate - * @throws CatalogResourceException e1 - */ - public NodeTemplate getNodeTemplateById(String serviceTemplateId, String nodeTemplateId) - throws CatalogResourceException { - List<NodeTemplateData> ntdList = - TemplateManager.getInstance().queryNodeTemplateById(serviceTemplateId, nodeTemplateId); - - if (ntdList == null || ntdList.isEmpty()) { - throw new CatalogResourceException("Can't find this node template."); - } - - return TemplateDataHelper.convert2NodeTemplate(ntdList.get(0)); - } - - /** - * get node templates. - * @param serviceTemplateId service template id - * @param types type list - * @return NodeTemplate list - * @throws CatalogResourceException e - */ - public NodeTemplate[] getNodeTemplates(String serviceTemplateId, String[] types) - throws CatalogResourceException { - List<NodeTemplateData> ntdList = - TemplateManager.getInstance().queryNodeTemplateBySeriviceTemplateId(serviceTemplateId); - if (ntdList == null || ntdList.isEmpty()) { - return new NodeTemplate[0]; - } - - if (ToolUtil.isTrimedEmptyArray(types)) { // return all node templates - return TemplateDataHelper.convert2NodeTemplates(ntdList); - } - - List<NodeTemplate> ntList = new ArrayList<>(); - for (String type : types) { - if (!ToolUtil.isTrimedEmptyString(type)) { - List<NodeTemplateData> typedNtdList = filterNodeTemplateDataListByType(ntdList, type); - ntList.addAll(Arrays.asList(TemplateDataHelper.convert2NodeTemplates(typedNtdList))); - } - } - return ntList.toArray(new NodeTemplate[0]); - } - - /** - * filter node template data list by type. - * @param ntdList nodeTemplate list - * @param type node type - * @return node template data list - */ - private List<NodeTemplateData> filterNodeTemplateDataListByType(List<NodeTemplateData> ntdList, - String type) { - List<NodeTemplateData> retList = new ArrayList<>(); - for (NodeTemplateData ntd : ntdList) { - if (type.equals(ntd.getType())) { - retList.add(ntd); - } - } - return retList; - } - - - /** - * get nfv template. - * @param serviceTemlateId service template id - * @return NfvTemplate - * @throws CatalogResourceException e - */ - public NfvTemplate getNfvTemplate(String serviceTemlateId) throws CatalogResourceException { - NodeTemplate[] nts = getNodeTemplates(serviceTemlateId, null); - - List<NodeTemplate> vduNodes = new ArrayList<>(); - List<NodeTemplate> networkNodes = new ArrayList<>(); - List<NodeTemplate> vnfcNodes = new ArrayList<>(); - List<NodeTemplate> vnfNodes = new ArrayList<>(); - for (NodeTemplate nt : nts) { - if (isVduNode(nt.getType())) { - vduNodes.add(nt); - continue; - } - - if (isNetworkNode(nt.getType())) { - networkNodes.add(nt); - continue; - } - - if (isVnfcNode(nt.getType())) { - vnfcNodes.add(nt); - continue; - } - - if (isVnfNode(nt.getType())) { - vnfNodes.add(nt); - continue; - } - } - - return new NfvTemplate(vduNodes, networkNodes, vnfcNodes, vnfNodes); - } - - private boolean isVnfNode(String type) { - return type.toUpperCase().indexOf(".VNF") > 0; - } - - private boolean isVnfcNode(String type) { - return type.toUpperCase().indexOf(".VNFC") > 0; - } - - private boolean isNetworkNode(String type) { - return type.toUpperCase().indexOf(".VL") > 0 || type.toUpperCase().indexOf(".VIRTUALLINK") > 0; - } - - private boolean isVduNode(String type) { - return type.toUpperCase().indexOf(".VDU") > 0; - } - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/CatalogBadRequestException.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/CatalogBadRequestException.java deleted file mode 100644 index 76c5e164..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/CatalogBadRequestException.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * 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.resources; - -import org.openo.commontosca.catalog.db.exception.ErrorCodeException; - -public class CatalogBadRequestException extends ErrorCodeException { - private static final long serialVersionUID = 5699508780537383310L; - - - public CatalogBadRequestException(int errcode) { - super(errcode, ""); - } - - - public CatalogBadRequestException(int errcode, Throwable cause) { - super(cause, errcode); - } - - - public CatalogBadRequestException(int errcode, String message, Throwable cause) { - super(cause, errcode, message); - } - - - public CatalogBadRequestException() { - super(9999999, null); - } - - - public CatalogBadRequestException(String message) { - super(9999999, message); - } - - - public CatalogBadRequestException(Throwable cause) { - super(cause, 9999999); - } - - - public CatalogBadRequestException(String message, Throwable cause) { - super(cause, 9999999, message); - } - - - public CatalogBadRequestException(Throwable source, int errId, String debugMessage, - String[] arguments) { - super(source, errId, debugMessage, arguments); - } - - public CatalogBadRequestException(Throwable source, int category, int code, String debugMessage, - String[] arguments) { - super(source, category, code, debugMessage, arguments); - } - - public int getErrcode() { - return super.getErrorCode(); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/PackageResource.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/PackageResource.java deleted file mode 100644 index d697c704..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/PackageResource.java +++ /dev/null @@ -1,237 +0,0 @@ -/** - * 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.resources; - -import com.codahale.metrics.annotation.Timed; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; - -import org.eclipse.jetty.http.HttpStatus; -import org.glassfish.jersey.media.multipart.FormDataContentDisposition; -import org.glassfish.jersey.media.multipart.FormDataParam; -import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse; -import org.openo.commontosca.catalog.entity.response.PackageMeta; -import org.openo.commontosca.catalog.entity.response.UploadPackageResponse; -import org.openo.commontosca.catalog.wrapper.PackageWrapper; - -import java.io.InputStream; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -/** - * csar package service. - * - * @author 10189609 - * - */ -@Path("/") -@Api(tags = {"Package Resource"}) -public class PackageResource { - - @Path("/csars") - @GET - @ApiOperation(value = "get csar package list by condition", response = PackageMeta.class, - responseContainer = "List") - @Produces(MediaType.APPLICATION_JSON) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", - response = String.class)}) - @Timed - public Response queryPackageListByCond( - @ApiParam(value = "csar name") @QueryParam("name") String name, @ApiParam( - value = "csar provider") @QueryParam("provider") String provider, @ApiParam( - value = "csar version") @QueryParam("version") String version, @ApiParam( - value = "delay to delete") @QueryParam("deletionPending") String deletionPending, - @ApiParam(value = "csar type") @QueryParam("type") String type) { - return PackageWrapper.getInstance().queryPackageListByCond(name, provider, version, - deletionPending, type); - } - - - @Path("/csars/{csarId}") - @GET - @ApiOperation(value = "get csar package list", response = PackageMeta.class, - responseContainer = "List") - @Produces(MediaType.APPLICATION_JSON) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", - response = String.class)}) - @Timed - public Response queryPackageById( - @ApiParam(value = "csar id") @PathParam("csarId") String csarId) { - return PackageWrapper.getInstance().queryPackageById(csarId); - } - - // @Path("/csars/ftp") - // @POST - // @ApiOperation(value = "upload csar package", response = UploadPackageResponse.class) - // @Consumes(MediaType.APPLICATION_JSON) - // @Produces(MediaType.APPLICATION_JSON) - // @ApiResponses(value = { - // @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = - // String.class), - // @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = - // "Unprocessable MicroServiceInfo Entity ", response = String.class), - // @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", - // response = String.class)}) - // @Timed - // public Response uploadPackageFromFtp(UploadPackageFromFtpRequest request) throws Exception { - // return PackageWrapper.getInstance().uploadPackageFromFtp(request); - // } - - @Path("/csars") - @POST - @ApiOperation(value = "upload csar package", response = UploadPackageResponse.class) - @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(MediaType.APPLICATION_JSON) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", - response = String.class)}) - @Timed - public Response uploadPackage( - @ApiParam(value = "file inputstream", - required = true) @FormDataParam("file") InputStream uploadedInputStream, - @ApiParam(value = "file detail", - required = false) @FormDataParam("file") FormDataContentDisposition fileDetail, - @ApiParam(value = "http header") @Context HttpHeaders head) throws Exception { - return PackageWrapper.getInstance().uploadPackage(uploadedInputStream, fileDetail, head); - } - - @Path("/csars/{csarId}") - @DELETE - @ApiOperation(value = "delete a package") - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", - response = String.class)}) - @Timed - public Response delPackage(@ApiParam(value = "csar Id") @PathParam("csarId") String csarId) { - return PackageWrapper.getInstance().delPackage(csarId); - } - - // @Path("/csars") - // @DELETE - // @ApiOperation(value = "delete a package by serviceTemplateId") - // @ApiResponses(value = { - // @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = - // String.class), - // @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = - // "Unprocessable MicroServiceInfo Entity ", response = String.class), - // @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", - // response = String.class)}) - // @Timed - // public Response delPackageByServiceTemplateId( - // @ApiParam(value = "serviceTemplateId") @QueryParam("serviceTemplateId") String - // serviceTemplateId) { - // return PackageWrapper.getInstance().delPackageByServiceTemplateId(serviceTemplateId); - // } - - @Path("/csars/{csarId}") - @PUT - @ApiOperation(value = "update csar package status") - @Produces(MediaType.APPLICATION_JSON) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", - response = String.class)}) - @Timed - public Response updatePackageStatus( - @ApiParam(value = "csar Id", required = true) @PathParam("csarId") String csarId, - @ApiParam(value = "csar operational status", - required = false) @QueryParam("operationalState") String operationalState, - @ApiParam(value = "csar usage status", - required = false) @QueryParam("usageState") String usageState, - @ApiParam(value = "csar onboard status", - required = false) @QueryParam("onBoardState") String onBoardState, - @ApiParam(value = "csar process status", - required = false) @QueryParam("processState") String processState, - @ApiParam(value = "csar deletionPending status", - required = false) @QueryParam("deletionPending") String deletionPending) { - return PackageWrapper.getInstance().updatePackageStatus(csarId, operationalState, usageState, - onBoardState, processState, deletionPending); - } - - @Path("/csars/{csarId}/files") - @GET - @ApiOperation(value = "get csar file uri by csarId", response = CsarFileUriResponse.class) - @Produces(MediaType.APPLICATION_JSON) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", - response = String.class)}) - @Timed - public Response getCsarFileUri( - @ApiParam(value = "csar Id", required = true) @PathParam("csarId") String csarId, - @ApiParam(value = "csar file path", - required = true) @QueryParam("relativePath") String relativePath) { - return PackageWrapper.getInstance().getCsarFileUri(csarId, relativePath); - } - - // @Path("/csars/{csarId}/plans") - // @GET - // @ApiOperation(value = "get plans of package by csarId", response = FileLink.class, - // responseContainer = "List") - // @Produces(MediaType.APPLICATION_JSON) - // @ApiResponses(value = { - // @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", response = - // String.class), - // @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = - // "Unprocessable MicroServiceInfo Entity ", response = String.class), - // @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "resource grant error", - // response = String.class)}) - // @Timed - // public Response getCsarPlanUri( - // @ApiParam(value = "csar Id", required = true) @PathParam("csarId") String csarId - // ) { - // return PackageWrapper.getInstance().getCsarPlansUri(csarId); - // } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/RestUtils.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/RestUtils.java deleted file mode 100644 index b5745b11..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/RestUtils.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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.resources; - -import org.openo.commontosca.catalog.common.CommonErrorResponse; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; - -import javax.ws.rs.BadRequestException; -import javax.ws.rs.InternalServerErrorException; -import javax.ws.rs.core.Response; - -public class RestUtils { - public static InternalServerErrorException newInternalServerErrorException( - CatalogResourceException e1) { - return new InternalServerErrorException(Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity(new CommonErrorResponse(e1.getErrcode() + "", e1.getMessage())).build(), e1); - } - - public static BadRequestException newBadRequestException(CatalogBadRequestException e1) { - return new BadRequestException(Response.status(Response.Status.BAD_REQUEST) - .entity(new CommonErrorResponse(e1.getErrcode() + "", e1.getMessage())).build(), e1); - } -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java deleted file mode 100644 index 1e0e2c66..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/resources/TemplateResource.java +++ /dev/null @@ -1,453 +0,0 @@ -/** - * 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.resources; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.eclipse.jetty.http.HttpStatus; -import org.openo.commontosca.catalog.common.CommonErrorResponse; -import org.openo.commontosca.catalog.common.ToolUtil; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.entity.EnumOperationalState; -import org.openo.commontosca.catalog.model.entity.InputParameter; -import org.openo.commontosca.catalog.model.entity.NodeTemplate; -import org.openo.commontosca.catalog.model.entity.Parameters; -import org.openo.commontosca.catalog.model.entity.QueryRawDataCondition; -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.parser.AbstractModelParser; -import org.openo.commontosca.catalog.model.parser.yaml.zte.ToscaYamlModelParser; -import org.openo.commontosca.catalog.model.service.ModelService; -import org.openo.commontosca.catalog.model.wrapper.ServiceTemplateWrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.codahale.metrics.annotation.Timed; - -/** - * model template service. - * - */ -@Path("/servicetemplates") -@Api(tags = {"Model Resource"}) -public class TemplateResource { - - private static final Logger logger = LoggerFactory.getLogger(TemplateResource.class); - - /** - * Query service template by service template id. - * @param servicetemplateid service template id - * @return Response - */ - @Path("/{servicetemplateid}") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Query service template by service template id", - response = ServiceTemplate.class) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error", - response = CommonErrorResponse.class)}) - @Timed - public Response getServiceTemplateById(@ApiParam( - value = "service template id") @PathParam("servicetemplateid") String servicetemplateid) { - try { - ServiceTemplate st = - ServiceTemplateWrapper.getInstance().getServiceTemplateById(servicetemplateid); - return Response.status(Response.Status.OK).entity(st).build(); - } catch (CatalogResourceException e1) { - logger.error("getServiceTemplateById failed.", e1); - throw RestUtils.newInternalServerErrorException(e1); - } - } - - - /** - * Query service template by filter conditions. - * @param status template status - * @param deletionPending delay to delete - * @return Response - */ - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Query service template by filter conditions", - response = ServiceTemplate.class, responseContainer = "List") - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error", - response = CommonErrorResponse.class)}) - @Timed - public Response getServiceTemplates( - @ApiParam(value = "template status") @QueryParam("status") EnumOperationalState status, - @ApiParam(value = "delay to delete") @QueryParam("deletionPending") boolean deletionPending) { - try { - ServiceTemplate[] sts = - ServiceTemplateWrapper.getInstance().getServiceTemplates(status, deletionPending); - return Response.status(Response.Status.OK).entity(sts).build(); - } catch (CatalogResourceException e1) { - logger.error("getServiceTemplates failed.", e1); - throw RestUtils.newInternalServerErrorException(e1); - } - - } - - /** - * Query nesting service template of a node type. - * @param nodeTypeIds node type ids - * @return Response - */ - @Path("/nesting") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Query nesting service template of a node type", - response = ServiceTemplate.class, responseContainer = "List") - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error", - response = CommonErrorResponse.class)}) - @Timed - public Response getNestingServiceTemplate(@ApiParam(value = "Node type ids splited by ','. Such as 'tosca.nodes.nfv.VDU,tosca.nodes.nfv.VL'.", - required = true) @QueryParam("nodeTypeIds") String nodeTypeIds) { - try { - if (ToolUtil.isTrimedEmptyString(nodeTypeIds)) { - throw new CatalogBadRequestException("nodeTypeIds is null."); - } - String[] tmpNodeTypeIds = nodeTypeIds.split(","); - ServiceTemplate[] sts = ServiceTemplateWrapper.getInstance() - .getNestingServiceTemplate(ToolUtil.trimedStringArray(tmpNodeTypeIds)); - return Response.status(Response.Status.OK).entity(sts).build(); - } catch (CatalogResourceException e1) { - logger.error("getNestingServiceTemplate failed.", e1); - throw RestUtils.newInternalServerErrorException(e1); - } catch (CatalogBadRequestException e2) { - logger.error("getNestingServiceTemplate failed.", e2); - throw RestUtils.newBadRequestException(e2); - } - } - - /** - * Query raw data of a service template by csar id. - * @param queryCondition query condition - * @return Response - */ - @Path("/queryingrawdata") - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Query raw data of a service template by csar id", - response = ServiceTemplateRawData.class) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error", - response = CommonErrorResponse.class)}) - @Timed - public Response getServiceTemplateRawData( - @ApiParam(value = "Query Service Template Raw Data Condition", - required = true) QueryRawDataCondition queryCondition) { - try { - ServiceTemplateRawData stRowData = - ServiceTemplateWrapper.getInstance().getServiceTemplateRawData(queryCondition); - return Response.status(Response.Status.OK).entity(stRowData).build(); - } catch (CatalogResourceException e1) { - logger.error("getServiceTemplateRawData failed.", e1); - throw RestUtils.newInternalServerErrorException(e1); - } catch (CatalogBadRequestException e2) { - logger.error("getServiceTemplateRawData failed.", e2); - throw RestUtils.newBadRequestException(e2); - } - } - - - /** - * Query operation list of service template. - * @param serviceTemplateId service template id - * @return Response - */ - @Path("/{serviceTemplateId}/operations") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Query operation list of service template", - response = ServiceTemplateOperation.class, responseContainer = "List") - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error", - response = CommonErrorResponse.class)}) - @Timed - public Response getServiceTemplateOperations(@ApiParam(value = "Service Template Id", - required = true) @PathParam("serviceTemplateId") String serviceTemplateId) { - try { - ServiceTemplateOperation[] operations = - ServiceTemplateWrapper.getInstance().getTemplateOperations(serviceTemplateId); - return Response.status(Response.Status.OK).entity(operations).build(); - } catch (CatalogResourceException e1) { - logger.error("getServiceTemplateOperations failed.", e1); - throw RestUtils.newInternalServerErrorException(e1); - } - - } - - /** - * Query input parameters of a specified operation. - * @param serviceTemplateId service template id - * @param operationName operation name - * @return Response - */ - @Path("/{serviceTemplateId}/operations/{operationName}/parameters") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Query input parameters of a specified operation", - response = InputParameter.class, responseContainer = "List") - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error", - response = CommonErrorResponse.class)}) - @Timed - public Response getParametersByOperationName( - @ApiParam(value = "Service Template Id", - required = true) @PathParam("serviceTemplateId") String serviceTemplateId, - @ApiParam(value = "Operation Name", - required = true) @PathParam("operationName") String operationName) { - try { - InputParameter[] inputs = ServiceTemplateWrapper.getInstance() - .getParametersByOperationName(serviceTemplateId, operationName); - return Response.status(Response.Status.OK).entity(inputs).build(); - } catch (CatalogResourceException e1) { - logger.error("getParametersByOperationId failed.", e1); - throw RestUtils.newInternalServerErrorException(e1); - } - - } - - /** - * Query input parameters of service template. - * @param servicetemplateid service template id - * @return Response - */ - @Path("/{servicetemplateid}/parameters") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Query input parameters of service template", response = Parameters.class) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error", - response = CommonErrorResponse.class)}) - @Timed - public Response getServiceTemplateParameters(@ApiParam(value = "service template id", - required = true) @PathParam("servicetemplateid") String servicetemplateid) { - try { - Parameters parameters = - ServiceTemplateWrapper.getInstance().getServiceTemplateParameters(servicetemplateid); - return Response.status(Response.Status.OK).entity(parameters).build(); - } catch (CatalogResourceException e1) { - logger.error("getServiceTemplateParameters failed.", e1); - throw RestUtils.newInternalServerErrorException(e1); - } - - } - - /** - * Query node template list of a specified service template. - * @param serviceTemplateId service template id - * @param types node type - * @return Response - */ - @Path("/{serviceTemplateId}/nodetemplates") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Query node template list of a specified service template", - response = NodeTemplate.class, responseContainer = "List") - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error", - response = CommonErrorResponse.class)}) - @Timed - public Response getNodeTemplatesByType( - @ApiParam(value = "Service Template Id", - required = true) @PathParam("serviceTemplateId") String serviceTemplateId, - @ApiParam(value = "The type of node template") @QueryParam("types") String types) { - try { - String[] tmpTypes = getSplitedTypes(types); - NodeTemplate[] nts = ServiceTemplateWrapper.getInstance().getNodeTemplates(serviceTemplateId, - ToolUtil.trimedStringArray(tmpTypes)); - return Response.status(Response.Status.OK).entity(nts).build(); - } catch (CatalogResourceException e1) { - logger.error("getNodeTemplateList failed.", e1); - throw RestUtils.newInternalServerErrorException(e1); - } - - } - - - private String[] getSplitedTypes(String types) { - if (ToolUtil.isTrimedEmptyString(types)) { - return new String[0]; - } - - return types.split(","); - } - - /** - * Query node template by node template id. - * @param serviceTemplateId service template id - * @param nodeTemplateId node template id - * @return Response - */ - @Path("/{serviceTemplateId}/nodetemplates/{nodeTemplateId}") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "Query node template by node template id", response = NodeTemplate.class) - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error", - response = CommonErrorResponse.class)}) - @Timed - public Response getNodeTemplateById( - @ApiParam(value = "Service Template Id", - required = true) @PathParam("serviceTemplateId") String serviceTemplateId, - @ApiParam(value = "Node Template Id", - required = true) @PathParam("nodeTemplateId") String nodeTemplateId) { - try { - NodeTemplate nt = ServiceTemplateWrapper.getInstance().getNodeTemplateById(serviceTemplateId, - nodeTemplateId); - return Response.status(Response.Status.OK).entity(nt).build(); - } catch (CatalogResourceException e1) { - logger.error("getNodeTemplateById failed.", e1); - throw RestUtils.newInternalServerErrorException(e1); - } - - } - - // /** - // * @param servicetemplateid - // * @return - // */ - // @Path("/{servicetemplateid}/nfvtemplate") - // @POST - // @Consumes(MediaType.APPLICATION_JSON) - // @Produces(MediaType.APPLICATION_JSON) - // @ApiOperation(value = - // "Query node template detail of a specified service template", response = - // NfvTemplate.class) - // @ApiResponses(value = { - // @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = - // "microservice not found", response = String.class), - // @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, message = - // "Unprocessable MicroServiceInfo Entity ", response = String.class), - // @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = - // "server internal error", response = CommonErrorResponse.class) }) - // @Timed - // public Response getNfvTemplate( - // @ApiParam(value = "service template id", required = true) - // @PathParam("servicetemplateid") String servicetemplateid) { - // try { - // NfvTemplate nfvTemplate = ServiceTemplateWrapper.getInstance() - // .getNfvTemplate(servicetemplateid); - // return Response.status(Response.Status.OK).entity(nfvTemplate) - // .build(); - // } catch (CatalogResourceException e) { - // logger.error("getNfvTemplate failed.", e); - // throw RestUtils.newInternalServerErrorException(e); - // } - // - // } - - /** - * test function. - * @return Response - */ - @Path("/test") - @GET - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation(value = "test", response = String.class, responseContainer = "List") - @ApiResponses(value = { - @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "microservice not found", - response = String.class), - @ApiResponse(code = HttpStatus.UNSUPPORTED_MEDIA_TYPE_415, - message = "Unprocessable MicroServiceInfo Entity ", response = String.class), - @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "server internal error", - response = CommonErrorResponse.class)}) - @Timed - public Response test() { - try { - AbstractModelParser parser1 = new ToscaYamlModelParser(); - parser1.parse("pk11111", "C:\\Users\\10090474\\Downloads\\OpenO.csar"); - -// AbstractModelParser parser = new AriaModelParser(); -// parser.parse("pk11111", "/home/b/common-tosca-aria/blueprints/tosca/node-cellar.yaml"); - - ModelService.getInstance().delete("pk11111"); - - String[] strs = {"111", "222", null, null, "555"}; - return Response.status(Response.Status.OK).entity(strs).build(); - } catch (CatalogResourceException e1) { - logger.error("test failed.", e1); - throw RestUtils.newInternalServerErrorException(e1); - } - } - - -} 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 deleted file mode 100644 index 1f1e245f..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapper.java +++ /dev/null @@ -1,484 +0,0 @@ -/** - * Copyright 2016-2017 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.wrapper; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; - -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.common.CommonConstant; -import org.openo.commontosca.catalog.common.HttpServerPathConfig; -import org.openo.commontosca.catalog.common.RestUtil; -import org.openo.commontosca.catalog.common.ToolUtil; -import org.openo.commontosca.catalog.db.entity.PackageData; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.resource.PackageManager; -import org.openo.commontosca.catalog.entity.request.PackageBasicInfo; -import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse; -import org.openo.commontosca.catalog.entity.response.PackageMeta; -import org.openo.commontosca.catalog.entity.response.UploadPackageResponse; -import org.openo.commontosca.catalog.filemanage.FileManagerFactory; -import org.openo.commontosca.catalog.model.parser.ModelParserFactory; -import org.openo.commontosca.catalog.model.service.ModelService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PackageWrapper { - private static PackageWrapper packageWrapper; - private static final Logger LOG = LoggerFactory.getLogger(PackageWrapper.class); - - /** - * get PackageWrapper instance. - * @return package wrapper instance - */ - public static PackageWrapper getInstance() { - if (packageWrapper == null) { - packageWrapper = new PackageWrapper(); - } - return packageWrapper; - } - - /** - * query package by id. - * @param csarId package id - * @return Response - */ - public Response queryPackageById(String csarId) { - PackageData dbResult = new PackageData(); - PackageMeta result = new PackageMeta(); - dbResult = PackageWrapperUtil.getPackageInfoById(csarId); - result = PackageWrapperUtil.packageData2PackageMeta(dbResult); - return Response.ok(result).build(); - } - - /** - * upload package. - * @param uploadedInputStream inputStream - * @param fileDetail package detail - * @param head http header - * @return Response - * @throws Exception e - */ - public Response uploadPackage(InputStream uploadedInputStream, - FormDataContentDisposition fileDetail, HttpHeaders head) throws Exception { - int fileSize = 0; - if (uploadedInputStream == null) { - LOG.info("the uploadStream is null"); - return Response.serverError().build(); - } - if (fileDetail == null) { - LOG.info("the fileDetail is null"); - return Response.serverError().build(); - } - LOG.info("the fileDetail = " + ToolUtil.objectToString(fileDetail)); - String contentRange = null; - String fileName = ""; - fileName = ToolUtil.processFileName(fileDetail.getFileName()); - String tempDirName = null; - tempDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName); - if (head != null) { - contentRange = head.getHeaderString(CommonConstant.HTTP_HEADER_CONTENT_RANGE); - } - LOG.info("store package chunk file, fileName:" + fileName + ",contentRange:" + contentRange); - if (ToolUtil.isEmptyString(contentRange)) { - fileSize = uploadedInputStream.available(); - contentRange = "0-" + fileSize + "/" + fileSize; - } - String fileLocation = - ToolUtil.storeChunkFileInLocal(tempDirName, fileName, uploadedInputStream); - LOG.info("the fileLocation when upload package is :" + fileLocation); - uploadedInputStream.close(); - - Boolean isEnd = PackageWrapperUtil.isUploadEnd(contentRange, fileName); - PackageData packateDbData = new PackageData(); - UploadPackageResponse result = new UploadPackageResponse(); - if (isEnd) { - PackageBasicInfo basicInfo = new PackageBasicInfo(); - basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation); - if (null == basicInfo.getType() || null == basicInfo.getProvider() - || null == basicInfo.getVersion()) { - LOG.error( - "Package basicInfo is incorrect ! basicIonfo = " + ToolUtil.objectToString(basicInfo)); - return Response.serverError().build(); - } - String path = - basicInfo.getType().toString() + File.separator + basicInfo.getProvider() + File.separator - + fileName.replace(".csar", "") + File.separator + basicInfo.getVersion(); - LOG.info("dest path is : " + path); - PackageMeta packageMeta = new PackageMeta(); - packageMeta = PackageWrapperUtil.getPackageMeta(fileName, fileLocation, basicInfo); - String dowloadUri = File.separator + path + File.separator; - packageMeta.setDownloadUri(dowloadUri); - LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta)); - - String serviceTemplateId = null; - PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta); - String destPath = File.separator + path; - boolean uploadResult = FileManagerFactory.createFileManager().upload(tempDirName, destPath); - if (uploadResult == true) { - List<PackageData> existPackageDatas = - PackageManager.getInstance().queryPackage(packageData.getName(), - packageData.getProvider(), packageData.getVersion(), null, packageData.getType()); - if (null != existPackageDatas && existPackageDatas.size() > 0 - && existPackageDatas.get(0).getOnBoardState().equals("onBoarded")) { - LOG.error("Package onboarded. Can not be reupload! onBoardState = " - + existPackageDatas.get(0).getOnBoardState()); - return Response.serverError().build(); - } - packateDbData = PackageManager.getInstance().addPackage(packageData); - LOG.info("Store package data to database succed ! packateDbData = " - + ToolUtil.objectToString(packateDbData)); - try { - //undeploy operation package of the old csar. - if (null != existPackageDatas && existPackageDatas.size() > 0) { - LOG.info("undeploy operation package of the old csar package."); - for (int i = 0; i < existPackageDatas.size(); i++) { - ModelService.getInstance().undeployOperationPackage(existPackageDatas.get(i).getCsarId()); - } - } - - String tempCsarPath = tempDirName + File.separator + fileName; - serviceTemplateId = ModelParserFactory.getInstance().parse(packateDbData.getCsarId(), - tempCsarPath, PackageWrapperUtil.getPackageFormat(packateDbData.getFormat())); - LOG.info("Package parse success ! serviceTemplateId = " + serviceTemplateId); - } catch (Exception e1) { - LOG.error("Parse package error ! Delete the package data from database"); - //String packagePath = PackageWrapperUtil.getPackagePath(packageData.getCsarId()); - //FileManagerFactory.createFileManager().delete(packagePath); - //if (tempDirName != null) { - //ToolUtil.deleteDir(new File(tempDirName)); - //} - PackageManager.getInstance().deletePackage(packateDbData.getCsarId()); - throw new Exception(e1); - } - - if (null != packateDbData && null == serviceTemplateId) { - LOG.info("Service template Id is null !"); - PackageManager.getInstance().deletePackage(packateDbData.getCsarId()); - } - //delete the redundant package data and template data while reupload the same package success. - if (null != existPackageDatas && existPackageDatas.size() > 0) { - LOG.warn("The package already exist ! Begin to delete the orgin data and reupload !"); - for (int i = 0; i < existPackageDatas.size(); i++) { - this.delPackageTemplateData(existPackageDatas.get(i).getCsarId()); - } - } - LOG.info("upload package file end, fileName:" + fileName); - result.setCsarId(packateDbData.getCsarId()); - if (tempDirName != null) { - ToolUtil.deleteDir(new File(tempDirName)); - } - } - } - return Response.ok(result).build(); - } - - - private void delPackageTemplateData(String csarId) { - String packagePath = PackageWrapperUtil.getPackagePath(csarId); - if (packagePath == null) { - LOG.error("package path is null! "); - return; - } - // delete template data from db - try { - ModelService.getInstance().deleteServiceTemplateData(csarId); - } catch (CatalogResourceException e2) { - LOG.error("delete template data from db error! csarId = " + csarId, e2); - return; - } - //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); - return; - } - } - - /** - * delete package by package id. - * @param csarId package id - * @return Response - */ - public Response delPackage(String csarId) { - LOG.info("delete package info.csarId:" + csarId); - if (ToolUtil.isEmptyString(csarId)) { - LOG.error("delete package fail, csarid is null"); - return Response.serverError().build(); - } - try { - DelCsarThread thread = new DelCsarThread(csarId, false); - PackageData packageData = new PackageData(); - packageData.setProcessState(CommonConstant.PACKAGE_STATUS_DELETING); - PackageManager.getInstance().updatePackage(packageData, csarId); - new Thread(thread).start(); - return Response.noContent().build(); - } catch (Exception e1) { - LOG.error("delete fail." + e1.getMessage()); - PackageData packageData = new PackageData(); - packageData.setProcessState(CommonConstant.PACKAGE_STATUS_DELETE_FAIL); - try { - PackageManager.getInstance().updatePackage(packageData, csarId); - } catch (CatalogResourceException e2) { - LOG.error("Update package data failed." + e2.getMessage(), e2); - } - return RestUtil.getRestException(e1.getMessage()); - } - } - - 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; - - public DelCsarThread(String csarid, boolean isInstanceTemplate) { - this.csarid = csarid; - this.isInstanceTemplate = isInstanceTemplate; - } - - @Override - public void run() { - try { - if (!ToolUtil.isEmptyString(csarid)) { - delCsarData(csarid); - } - } catch (Exception e1) { - LOG.error("del instance csar fail. " + e1.getMessage(), e1); - updatePackageStatus(csarid, null, null, null, CommonConstant.PACKAGE_STATUS_DELETE_FAIL, - null); - publishDelFinishCometdMessage(csarid, "false"); - } - } - - private void delCsarData(String csarId) { - updatePackageStatus(csarId, null, null, null, CommonConstant.PACKAGE_STATUS_DELETING, null); - String packagePath = PackageWrapperUtil.getPackagePath(csarId); - if (packagePath == null) { - LOG.error("package path is null! "); - return; - } - boolean delFileFromHttp = FileManagerFactory.createFileManager().delete(packagePath); - // delete template data from db - try { - ModelService.getInstance().delete(csarId); - } catch (CatalogResourceException e2) { - LOG.error("delete template data from db error! csarId = " + csarId, e2); - publishDelFinishCometdMessage(csarId, "Delete template data failed! " + e2.getMessage()); - return; - } - //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, "Delete package data failed! " + e1.getMessage()); - return; - } - 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 e1) { - LOG.error("publish delfinish cometdmsg fail." + e1.getMessage(), e1); - } - } - } - - /** - * update package status. - * @param csarId package id - * @param operationalState package operational state - * @param usageState package usage state - * @param onBoardState package onboard state - * @param processState package process state - * @param deletionPending package deletionPending status - * @return Response - */ - public Response updatePackageStatus(String csarId, String operationalState, String usageState, - String onBoardState, String processState, String deletionPending) { - LOG.info("update package status info.csarId:" + csarId + " operationalState:" + operationalState - + "usageState:" + usageState + "onBoardState:" + onBoardState + "processState:" - + processState + "deletionPending" + deletionPending); - if (ToolUtil.isEmptyString(csarId)) { - LOG.error("update csar status fail, csarid is null"); - return Response.serverError().build(); - } - try { - // UpdatePackageResponse result = new UpdatePackageResponse(); - PackageData packageInfo = new PackageData(); - if (operationalState != null) { - packageInfo.setOperationalState(operationalState); - } - if (usageState != null) { - packageInfo.setUsageState(usageState); - } - if (onBoardState != null) { - packageInfo.setOnBoardState(onBoardState); - } - if (processState != null) { - packageInfo.setProcessState(processState); - } - if (deletionPending != null) { - packageInfo.setDeletionPending(deletionPending); - } - SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String currentTime = sdf1.format(new Date()); - packageInfo.setModifyTime(currentTime); - PackageManager.getInstance().updatePackage(packageInfo, csarId); - // ArrayList<PackageData> pacackgeList = PackageWrapperUtil.getPackageInfoById(csarId); - // String finalUsageState = pacackgeList.get(0).getUsageState(); - // result.setUsageState(finalUsageState); - return Response.ok().build(); - } catch (CatalogResourceException e1) { - LOG.error("update package status by csarId from db error ! " + e1.getMessage()); - return RestUtil.getRestException(e1.getMessage()); - } - } - - /** - * download package by package id. - * @param csarId package id - * @return Response - */ - public Response downloadCsarPackagesById(String csarId) { - PackageData packageData = PackageWrapperUtil.getPackageInfoById(csarId); - String packageName = null; - packageName = packageData.getName(); - String path = ToolUtil.getCatalogueCsarPath() + File.separator + packageName; - File csarFile = new File(path); - if (!csarFile.exists()) { - return Response.status(Status.NOT_FOUND).build(); - } - - try { - InputStream fis = new BufferedInputStream(new FileInputStream(path)); - return Response.ok(fis) - .header("Content-Disposition", "attachment; filename=\"" + csarFile.getName() + "\"") - .build(); - } catch (Exception e1) { - LOG.error("download vnf package fail.", e1); - return RestUtil.getRestException(e1.getMessage()); - } - } - - /** - * query package list by condition. - * @param name package name - * @param provider package provider - * @param version package version - * @param deletionPending package deletionPending - * @param type package type - * @return Response - */ - public Response queryPackageListByCond(String name, String provider, String version, - String deletionPending, String type) { - ArrayList<PackageData> dbresult = new ArrayList<PackageData>(); - ArrayList<PackageMeta> result = new ArrayList<PackageMeta>(); - LOG.info("query package info.name:" + name + " provider:" + provider + " version" + version - + " deletionPending" + deletionPending + " type:" + type); - try { - dbresult = - PackageManager.getInstance().queryPackage(name, provider, version, deletionPending, type); - result = PackageWrapperUtil.packageDataList2PackageMetaList(dbresult); - return Response.ok(result).build(); - } catch (CatalogResourceException e1) { - LOG.error("query package by csarId from db error ! " + e1.getMessage()); - return RestUtil.getRestException(e1.getMessage()); - } - } - - /** - * get package file uri. - * @param csarId package id - * @param relativePath file relative path - * @return Response - */ - public Response getCsarFileUri(String csarId, String relativePath) { - try { - CsarFileUriResponse result = getCsarFileDownloadUri(csarId, relativePath); - return Response.ok(result).build(); - } catch (CatalogResourceException e1) { - LOG.error("Query CSAR package by ID failed ! csarId = " + csarId); - } - - return Response.serverError().build(); - } - - /** - * get package file download uri. - * @param csarId package id - * @param relativePath package file relative path - * @return CsarFileUriResponse - * @throws CatalogResourceException e - */ - public CsarFileUriResponse getCsarFileDownloadUri(String csarId, String relativePath) - throws CatalogResourceException { - CsarFileUriResponse result = new CsarFileUriResponse(); - String downloadUrl = null; - String downloadUri = null; - String localPath = null; - ArrayList<PackageData> packageList = PackageManager.getInstance().queryPackageByCsarId(csarId); - if (packageList != null && packageList.size() != 0) { - String packageName = packageList.get(0).getName(); - String relativeUri = packageList.get(0).getDownloadUri() + packageName; - downloadUri = relativeUri + relativePath; - downloadUrl = PackageWrapperUtil.getUrl(downloadUri); - String httpUri = HttpServerPathConfig.getHttpServerPath() + downloadUri; - localPath = PackageWrapperUtil.getLocalPath(httpUri); - } - result.setDownloadUri(downloadUrl); - result.setLocalPath(localPath); - return result; - } - - -} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapperUtil.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapperUtil.java deleted file mode 100644 index abb890c2..00000000 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/wrapper/PackageWrapperUtil.java +++ /dev/null @@ -1,456 +0,0 @@ -/** - * Copyright 2016-2017 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.wrapper; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; - -import org.openo.commontosca.catalog.common.CommonConstant; -import org.openo.commontosca.catalog.common.FileUtil; -import org.openo.commontosca.catalog.common.HttpServerAddrConfig; -import org.openo.commontosca.catalog.common.MsbAddrConfig; -import org.openo.commontosca.catalog.common.ToolUtil; -import org.openo.commontosca.catalog.db.entity.PackageData; -import org.openo.commontosca.catalog.db.exception.CatalogResourceException; -import org.openo.commontosca.catalog.db.resource.PackageManager; -import org.openo.commontosca.catalog.entity.CsarPackage; -import org.openo.commontosca.catalog.entity.EnumOnboardState; -import org.openo.commontosca.catalog.entity.EnumOperationalState; -import org.openo.commontosca.catalog.entity.EnumProcessState; -import org.openo.commontosca.catalog.entity.EnumType; -import org.openo.commontosca.catalog.entity.EnumUsageState; -import org.openo.commontosca.catalog.entity.request.PackageBasicInfo; -import org.openo.commontosca.catalog.entity.response.PackageMeta; -import org.openo.commontosca.catalog.ftp.Ftp; -import org.openo.commontosca.catalog.ftp.FtpUtil; -import org.openo.commontosca.catalog.model.entity.ServiceTemplate; -import org.openo.commontosca.catalog.model.externalservice.entity.lifecycle.InstanceEntity; -import org.openo.commontosca.catalog.model.externalservice.lifecycle.LifeCycleServiceConsumer; -import org.openo.commontosca.catalog.model.parser.EnumPackageFormat; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; - -import javax.ws.rs.NotFoundException; - -public class PackageWrapperUtil { - private static final Logger LOG = LoggerFactory.getLogger(PackageWrapperUtil.class); - - - /** - * change json to object list. - * @param packageJson json - * @return package list - */ - public static List<CsarPackage> formJson2Packages(String packageJson) { - List<CsarPackage> packageList = - new Gson().fromJson(packageJson, new TypeToken<List<CsarPackage>>() {}.getType()); - if (null == packageList || packageList.size() == 0) { - throw new NotFoundException("Package do not exist"); - } - return packageList; - } - - public static long getPacakgeSize(String fileLocation) { - File file = new File(fileLocation); - return file.length(); - } - - /** - * change package metadata to fix database. - * @param meta package metadata - * @return package data in database - */ - public static PackageData getPackageData(PackageMeta meta) { - PackageData packageData = new PackageData(); - packageData.setCreateTime(meta.getCreateTime()); - packageData.setDeletionPending(String.valueOf(meta.isDeletionPending())); - packageData.setDownloadUri(meta.getDownloadUri()); - packageData.setFormat(meta.getFormat()); - packageData.setModifyTime(meta.getModifyTime()); - packageData.setName(meta.getName()); - packageData.setCsarId(meta.getCsarId()); - packageData.setOperationalState(meta.getOperationalState().toString()); - packageData.setProvider(meta.getProvider()); - String fileSize = meta.getSize(); - packageData.setSize(fileSize); - packageData.setType(meta.getType()); - packageData.setUsageState(meta.getUsageState().toString()); - packageData.setVersion(meta.getVersion()); - packageData.setOnBoardState(meta.getOnBoardState()); - packageData.setProcessState(meta.getProcessState().toString()); - return packageData; - } - - /** - * judge wether is the end of upload package. - * @param contentRange package sise range - * @param csarName package name - * @return boolean - */ - public static boolean isUploadEnd(String contentRange, String csarName) { - String range = contentRange; - range = range.replace("bytes", "").trim(); - range = range.substring(0, range.indexOf("/")); - String size = - contentRange.substring(contentRange.indexOf("/") + 1, contentRange.length()).trim(); - int fileSize = Integer.parseInt(size); - String[] ranges = range.split("-"); - int startPosition = Integer.parseInt(ranges[0]); - if (startPosition == 0) { - // delPackageBySync(csarName); - } - // index start from 0 - int endPosition = Integer.parseInt(ranges[1]) + 1; - if (endPosition >= fileSize) { - return true; - } - return false; - } - - /** - * get package detail by package id. - * @param csarId package id - * @return package detail - */ - public static PackageData getPackageInfoById(String csarId) { - PackageData result = new PackageData(); - ArrayList<PackageData> packageDataList = new ArrayList<PackageData>(); - try { - packageDataList = PackageManager.getInstance().queryPackageByCsarId(csarId); - if (packageDataList != null && packageDataList.size() > 0) { - result = PackageManager.getInstance().queryPackageByCsarId(csarId).get(0); - } - } catch (CatalogResourceException e1) { - LOG.error("query package by csarId from db error ! " + e1.getMessage()); - } - return result; - } - - /** - * get package metadata from basic info. - * @param fileName package name - * @param fileLocation the location of package - * @param basic basic infomation of package. include version, type and provider - * @return package metadata - */ - public static PackageMeta getPackageMeta(String fileName, String fileLocation, - PackageBasicInfo basic) { - PackageMeta packageMeta = new PackageMeta(); - long size = getPacakgeSize(fileLocation); - packageMeta.setFormat(basic.getFormat()); - String packageId = ToolUtil.generateId(); - packageMeta.setName(fileName.replace(CommonConstant.CSAR_SUFFIX, "")); - packageMeta.setCsarId(packageId); - packageMeta.setType(basic.getType().toString()); - packageMeta.setVersion(basic.getVersion()); - packageMeta.setProvider(basic.getProvider()); - packageMeta.setDeletionPending(false); - String sizeStr = ToolUtil.getFormatFileSize(size); - packageMeta.setSize(sizeStr); - SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String currentTime = sdf1.format(new Date()); - packageMeta.setCreateTime(currentTime); - packageMeta.setModifyTime(currentTime); - packageMeta.setOperationalState(EnumOperationalState.Disabled); - packageMeta.setUsageState(EnumUsageState.NotInUse); - packageMeta.setOnBoardState(EnumOnboardState.nonOnBoarded.getValue()); - packageMeta.setProcessState(EnumProcessState.normal); - return packageMeta; - } - - /** - * get downloadUri from package metadata. - * @param csarId package id - * @return download uri - */ - public static String getPackagePath(String csarId) { - ArrayList<PackageData> packageList = new ArrayList<PackageData>(); - String downloadUri = null; - try { - packageList = PackageManager.getInstance().queryPackageByCsarId(csarId); - downloadUri = packageList.get(0).getDownloadUri(); - } catch (CatalogResourceException e1) { - LOG.error("Query CSAR package by ID failed ! csarId = " + csarId); - } - return downloadUri; - } - - - /** - * convert instance to hashset. - * @param instancelist instance list - * @return HashSet - */ - public static HashSet<String> instanceConvertToHashSet(ArrayList<InstanceEntity> instancelist) { - HashSet<String> result = new HashSet<String>(); - if (instancelist != null) { - for (InstanceEntity instance : instancelist) { - result.add(instance.getServiceTemplateId()); - } - } - return result; - } - - /** - * get ftp detail information. - * @param ftpUrl ftp url - * @return ftp detail - */ - public static Ftp getFtpDetail(String ftpUrl) { - Ftp ftp = new Ftp(); - int index1 = ftpUrl.indexOf("ftp://"); - int index2 = ftpUrl.indexOf("@"); - String userPassSubString = ftpUrl.substring(index1, index2); - int index3 = userPassSubString.indexOf(":"); - String userName = userPassSubString.substring(0, index3); - String pass = userPassSubString.substring(index3 + 1); - String subString1 = ftpUrl.substring(index2 + 1); - int index4 = subString1.indexOf("/"); - String ipPortSubString = subString1.substring(0, index4); - int index5 = ipPortSubString.indexOf(":"); - String ip = ipPortSubString.substring(0, index5); - String port = ipPortSubString.substring(index5 + 1); - int index6 = ftpUrl.lastIndexOf("/"); - String path = ftpUrl.substring(0, index6); - ftp.setIpAddr(ip); - ftp.setPath(path); - ftp.setPort(Integer.valueOf(port)); - ftp.setPwd(pass); - ftp.setUserName(userName); - return ftp; - } - - /** - * get package name from ftpUrl. - * @param ftpUrl ftp url - * @return package name - */ - public static String getPackageName(String ftpUrl) { - int index = ftpUrl.lastIndexOf("/"); - String packageName = ftpUrl.substring(index); - return packageName; - } - - /** - * download package from ftp. - * @param ftpUrl ftp url - * @param tempDirName temp directory - */ - public static void downPackageFromFtp(String ftpUrl, String tempDirName) { - Ftp ftp = new Ftp(); - ftp = PackageWrapperUtil.getFtpDetail(ftpUrl); - String remoteBaseDir = ftp.getPath(); - try { - FtpUtil.startDown(ftp, tempDirName, remoteBaseDir); - } catch (Exception e1) { - LOG.error("Down package from ftp failed !"); - } - } - - /** - * translate package data from database to package metadata. - * @param dbResult data from database - * @return package metadata list - */ - public static ArrayList<PackageMeta> packageDataList2PackageMetaList( - ArrayList<PackageData> dbResult) { - ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>(); - PackageMeta meta = new PackageMeta(); - if (dbResult.size() > 0) { - for (int i = 0; i < dbResult.size(); i++) { - PackageData data = dbResult.get(i); - meta = packageData2PackageMeta(data); - metas.add(meta); - } - } - return metas; - } - - /** - * get onboarded enum value. - * @param value onboard value - * @return enum - */ - public static EnumOnboardState getEnumByValue(String value) { - if (value == "non-onBoarded") { - return EnumOnboardState.nonOnBoarded; - } else { - return EnumOnboardState.onBoarded; - } - } - - public static PackageMeta packageData2PackageMeta(PackageData packageData) { - PackageMeta meta = new PackageMeta(); - meta.setCsarId(packageData.getCsarId()); - meta.setCreateTime(packageData.getCreateTime()); - meta.setDeletionPending(Boolean.valueOf(packageData.getDeletionPending())); - String packageUri = - packageData.getDownloadUri() + packageData.getName() + CommonConstant.CSAR_SUFFIX; - String packageUrl = getUrl(packageUri); - meta.setDownloadUri(packageUrl); - meta.setFormat(packageData.getFormat()); - meta.setModifyTime(packageData.getModifyTime()); - meta.setName(packageData.getName()); - meta.setOperationalState(EnumOperationalState.valueOf(packageData.getOperationalState())); - meta.setProvider(packageData.getProvider()); - meta.setSize(packageData.getSize()); - meta.setType(packageData.getType()); - meta.setUsageState(EnumUsageState.valueOf(packageData.getUsageState())); - meta.setVersion(packageData.getVersion()); - meta.setOnBoardState(packageData.getOnBoardState()); - String processState = packageData.getProcessState(); - if (processState.equals("deletefail")) { - processState = "deleteFailed"; - } - meta.setProcessState(EnumProcessState.valueOf(processState)); - return meta; - } - - /** - * add msb address as prefix to uri. - * @param uri uri - * @return url - */ - public static String getUrl(String uri) { - String url = null; -// if ((MsbAddrConfig.getMsbAddress().endsWith("/")) && uri.startsWith("/")) { -// url = MsbAddrConfig.getMsbAddress() + uri.substring(1); -// } -// url = MsbAddrConfig.getMsbAddress() + uri; - if ((getDownloadUriHead().endsWith("/")) && uri.startsWith("/")) { - url = getDownloadUriHead() + uri.substring(1); - } - url = getDownloadUriHead() + uri; - String urlresult = url.replace("\\", "/"); - return urlresult; - } - - public static String getDownloadUriHead() { - return MsbAddrConfig.getMsbAddress() + "/files/catalog-http"; - } - - /** - * get local path. - * @param uri uri - * @return local path - */ - public static String getLocalPath(String uri) { - File srcDir = new File(uri); - String localPath = srcDir.getAbsolutePath(); - return localPath.replace("\\", "/"); - } - - /** - * get package basic information. - * @param fileLocation package location - * @return package basic information - */ - public static PackageBasicInfo getPacageBasicInfo(String fileLocation) { - PackageBasicInfo basicInfo = new PackageBasicInfo(); - String unzipDir = ToolUtil.getUnzipDir(fileLocation); - boolean isXmlCsar = false; - try { - String tempfolder = unzipDir; - ArrayList<String> unzipFiles = FileUtil.unzip(fileLocation, tempfolder); - if (unzipFiles.isEmpty()) { - isXmlCsar = true; - } - for (String unzipFile : unzipFiles) { - if (unzipFile.endsWith(CommonConstant.CSAR_META)) { - basicInfo = readCsarMeta(unzipFile); - } - if (ToolUtil.isYamlFile(new File(unzipFile))) { - isXmlCsar = false; - } - } - } catch (IOException e1) { - LOG.error("judge package type error ! " + e1.getMessage()); - } - if (isXmlCsar) { - basicInfo.setFormat(CommonConstant.PACKAGE_XML_FORMAT); - } else { - basicInfo.setFormat(CommonConstant.PACKAGE_YAML_FORMAT); - } - return basicInfo; - } - - private static PackageBasicInfo readCsarMeta(String unzipFile) { - PackageBasicInfo basicInfo = new PackageBasicInfo(); - File file = new File(unzipFile); - BufferedReader reader = null; - try { - reader = new BufferedReader(new FileReader(file)); - String tempString = null; - while ((tempString = reader.readLine()) != null) { - if (!tempString.equals("")) { - int count1 = tempString.indexOf(":"); - String meta = tempString.substring(0, count1).trim(); - if (meta.equalsIgnoreCase(CommonConstant.CSAR_TYPE_META)) { - int count = tempString.indexOf(":") + 1; - basicInfo.setType(EnumType.valueOf(tempString.substring(count).trim())); - } - if (meta.equalsIgnoreCase(CommonConstant.CSAR_PROVIDER_META)) { - int count = tempString.indexOf(":") + 1; - basicInfo.setProvider(tempString.substring(count).trim()); - } - if (meta.equalsIgnoreCase(CommonConstant.CSAR_VERSION_META)) { - int count = tempString.indexOf(":") + 1; - basicInfo.setVersion(tempString.substring(count).trim()); - } - } - } - reader.close(); - } catch (IOException e2) { - e2.printStackTrace(); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e1) { - LOG.error("close reader failed ! " + e1.getMessage()); - } - } - } - return basicInfo; - } - - /** - * get package format enum. - * @param format package format - * @return package format enum - */ - public static EnumPackageFormat getPackageFormat(String format) { - if (format.equals("xml")) { - return EnumPackageFormat.TOSCA_XML; - } else if (format.equals("yml") || format.equals("yaml")) { - return EnumPackageFormat.TOSCA_YAML; - } else { - return null; - } - } -} |