-<!--\r
-\r
- Copyright 2016 [ZTE] and others.\r
-\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-\r
--->\r
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
- <parent>\r
- <groupId>org.openo.common-tosca.catalog</groupId>\r
- <artifactId>catalog-core-parent</artifactId>\r
- <version>1.0.0-SNAPSHOT</version>\r
- </parent>\r
-\r
- <modelVersion>4.0.0</modelVersion>\r
- <artifactId>catalog-mgr</artifactId>\r
- <name>openo/commontosca/catalog/catalog-mgr</name>\r
- <packaging>jar</packaging>\r
- <properties>\r
- <httpclient.version>4.4.1</httpclient.version>\r
- </properties>\r
-\r
- <build>\r
- <plugins>\r
- <plugin>\r
- <groupId>org.eclipse.m2e</groupId>\r
- <artifactId>lifecycle-mapping</artifactId> \r
- <configuration>\r
- <lifecycleMappingMetadata>\r
- <pluginExecutions>\r
- <pluginExecution>\r
- <pluginExecutionFilter>\r
- <groupId>org.apache.maven.plugins</groupId>\r
- <artifactId>maven-dependency-plugin</artifactId>\r
- <versionRange>[2.0,)</versionRange>\r
- <goals>\r
- <goal>copy-dependencies</goal>\r
- </goals>\r
- </pluginExecutionFilter>\r
- <action>\r
- <ignore />\r
- </action>\r
- </pluginExecution>\r
- </pluginExecutions>\r
- </lifecycleMappingMetadata>\r
- </configuration>\r
- </plugin>\r
- <plugin>\r
- <groupId>org.apache.maven.plugins</groupId>\r
- <artifactId>maven-jar-plugin</artifactId>\r
- <configuration>\r
- <archive>\r
- <manifest>\r
- <addDefaultImplementationEntries>true</addDefaultImplementationEntries>\r
- </manifest>\r
- </archive>\r
- </configuration>\r
- </plugin>\r
- <plugin>\r
- <groupId>org.apache.maven.plugins</groupId>\r
- <artifactId>maven-shade-plugin</artifactId>\r
- <configuration>\r
- <createDependencyReducedPom>true</createDependencyReducedPom>\r
- <filters>\r
- <filter>\r
- <artifact>*:*</artifact>\r
- <excludes>\r
- <exclude>META-INF/*.SF</exclude>\r
- <exclude>META-INF/*.DSA</exclude>\r
- <exclude>META-INF/*.RSA</exclude>\r
- </excludes>\r
- </filter>\r
- </filters>\r
- </configuration>\r
- <executions>\r
- <execution>\r
- <phase>package</phase>\r
- <goals>\r
- <goal>shade</goal>\r
- </goals>\r
- <configuration>\r
- <transformers>\r
- <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>\r
- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">\r
- <mainClass>org.openo.commontosca.catalog.catalogApp</mainClass>\r
- </transformer>\r
- </transformers>\r
- </configuration>\r
- </execution>\r
- </executions>\r
- </plugin>\r
- <plugin>\r
- <groupId>org.apache.maven.plugins</groupId>\r
- <artifactId>maven-dependency-plugin</artifactId>\r
- <executions>\r
- <execution>\r
- <id>copy-dependencies</id>\r
- <phase>package</phase>\r
- <goals>\r
- <goal>copy-dependencies</goal>\r
- </goals>\r
- <configuration>\r
- <artifactItems>\r
- <artifactItem>\r
- <groupId>io.dropwizard</groupId>\r
- <artifactId>dropwizard-core</artifactId>\r
- <version>${dropwizard.version}</version>\r
- <overWrite>true</overWrite>\r
- </artifactItem>\r
- </artifactItems>\r
- </configuration>\r
- </execution>\r
- </executions>\r
- </plugin>\r
- </plugins>\r
- </build>\r
-\r
- <dependencies>\r
- <!-- dropwizard -->\r
- <dependency>\r
- <groupId>io.dropwizard</groupId>\r
- <artifactId>dropwizard-core</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>io.dropwizard</groupId>\r
- <artifactId>dropwizard-assets</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>io.dropwizard</groupId>\r
- <artifactId>dropwizard-hibernate</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>io.dropwizard</groupId>\r
- <artifactId>dropwizard-migrations</artifactId>\r
- </dependency>\r
- <!-- swagger -->\r
- <dependency>\r
- <groupId>io.swagger</groupId>\r
- <artifactId>swagger-jersey2-jaxrs</artifactId>\r
- </dependency>\r
- <!-- lombok -->\r
- <dependency>\r
- <groupId>org.projectlombok</groupId>\r
- <artifactId>lombok</artifactId>\r
- </dependency>\r
- <!-- jersey -->\r
- <dependency>\r
- <groupId>org.glassfish.jersey.core</groupId>\r
- <artifactId>jersey-server</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.glassfish.jersey.media</groupId>\r
- <artifactId>jersey-media-multipart</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.glassfish.jersey.containers</groupId>\r
- <artifactId>jersey-container-servlet-core</artifactId>\r
- </dependency>\r
- <!-- consumer -->\r
- <dependency>\r
- <groupId>com.eclipsesource.jaxrs</groupId>\r
- <artifactId>consumer</artifactId>\r
- <exclusions>\r
- <exclusion>\r
- <groupId>com.eclipsesource.jaxrs</groupId>\r
- <artifactId>jersey-all</artifactId>\r
- </exclusion>\r
- </exclusions>\r
- </dependency>\r
- <!-- jackson -->\r
- <dependency>\r
- <groupId>com.fasterxml.jackson.dataformat</groupId>\r
- <artifactId>jackson-dataformat-xml</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>com.fasterxml.jackson.core</groupId>\r
- <artifactId>jackson-annotations</artifactId>\r
- </dependency>\r
- <!-- gson -->\r
- <dependency>\r
- <groupId>com.google.code.gson</groupId>\r
- <artifactId>gson</artifactId>\r
- </dependency>\r
- <!-- dom4j -->\r
- <dependency>\r
- <groupId>dom4j</groupId>\r
- <artifactId>dom4j</artifactId>\r
- </dependency>\r
- <!-- cometd -->\r
- <dependency>\r
- <groupId>org.cometd.java</groupId>\r
- <artifactId>bayeux-api</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.cometd.java</groupId>\r
- <artifactId>cometd-java-annotations</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.cometd.java</groupId>\r
- <artifactId>cometd-java-client</artifactId>\r
- <version>${cometd.version}</version>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.cometd.java</groupId>\r
- <artifactId>cometd-java-common</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.cometd.java</groupId>\r
- <artifactId>cometd-java-oort</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.cometd.java</groupId>\r
- <artifactId>cometd-java-server</artifactId>\r
- </dependency>\r
- <!-- ftp -->\r
- <dependency>\r
- <groupId>commons-net</groupId>\r
- <artifactId>commons-net</artifactId>\r
- </dependency>\r
- <!-- mysql -->\r
- <dependency>\r
- <groupId>mysql</groupId>\r
- <artifactId>mysql-connector-java</artifactId>\r
- </dependency>\r
- <!-- http server -->\r
- <dependency>\r
- <groupId>commons-fileupload</groupId>\r
- <artifactId>commons-fileupload</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>commons-io</groupId>\r
- <artifactId>commons-io</artifactId>\r
- </dependency>\r
- <!-- UT -->\r
- <dependency>\r
- <groupId>io.dropwizard</groupId>\r
- <artifactId>dropwizard-testing</artifactId>\r
- <scope>test</scope>\r
- </dependency>\r
- <dependency> \r
- <groupId>junit</groupId> \r
- <artifactId>junit</artifactId> \r
- <scope>test</scope>\r
- </dependency> \r
- <dependency> \r
- <groupId>org.powermock</groupId> \r
- <artifactId>powermock-module-junit4</artifactId> \r
- <scope>test</scope>\r
- </dependency> \r
- <dependency> \r
- <groupId>org.powermock</groupId> \r
- <artifactId>powermock-api-mockito</artifactId> \r
- <scope>test</scope>\r
- </dependency> \r
- <dependency>\r
- <groupId>org.mockito</groupId>\r
- <artifactId>mockito-all</artifactId>\r
- <scope>test</scope>\r
- </dependency>\r
- <dependency>\r
- <groupId>com.h2database</groupId>\r
- <artifactId>h2</artifactId>\r
- <scope>test</scope>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.apache.ant</groupId>\r
- <artifactId>ant</artifactId>\r
- <scope>test</scope>\r
- </dependency>\r
- <!-- UT end -->\r
- <!-- httpclient-->\r
- <dependency>\r
- <groupId>org.apache.httpcomponents</groupId>\r
- <artifactId>httpclient</artifactId>\r
- <version>${httpclient.version}</version>\r
- <exclusions>\r
- <!-- provided by jcl-over-slf4j to enable logging via logback -->\r
- <exclusion>\r
- <groupId>commons-logging</groupId>\r
- <artifactId>commons-logging</artifactId>\r
- </exclusion>\r
- </exclusions>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.apache.httpcomponents</groupId>\r
- <artifactId>httpcore</artifactId>\r
- <version>${httpclient.version}</version>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.apache.httpcomponents</groupId>\r
- <artifactId>httpmime</artifactId>\r
- <version>${httpclient.version}</version>\r
- </dependency>\r
- </dependencies>\r
-</project>\r
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.openo.common-tosca.catalog</groupId>
+ <artifactId>catalog-core-parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>catalog-mgr</artifactId>
+ <name>openo/commontosca/catalog/catalog-mgr</name>
+ <packaging>jar</packaging>
+ <properties>
+ <httpclient.version>4.4.1</httpclient.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <versionRange>[2.0,)</versionRange>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore />
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <configuration>
+ <createDependencyReducedPom>true</createDependencyReducedPom>
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <mainClass>org.openo.commontosca.catalog.catalogApp</mainClass>
+ </transformer>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-core</artifactId>
+ <version>${dropwizard.version}</version>
+ <overWrite>true</overWrite>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <!-- dropwizard -->
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-assets</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-hibernate</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-migrations</artifactId>
+ </dependency>
+ <!-- swagger -->
+ <dependency>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-jersey2-jaxrs</artifactId>
+ </dependency>
+ <!-- lombok -->
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ </dependency>
+ <!-- jersey -->
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ </dependency>
+ <!-- consumer -->
+ <dependency>
+ <groupId>com.eclipsesource.jaxrs</groupId>
+ <artifactId>consumer</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>com.eclipsesource.jaxrs</groupId>
+ <artifactId>jersey-all</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <!-- jackson -->
+ <dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-xml</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ </dependency>
+ <!-- gson -->
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+ <!-- dom4j -->
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ </dependency>
+ <!-- cometd -->
+ <dependency>
+ <groupId>org.cometd.java</groupId>
+ <artifactId>bayeux-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.cometd.java</groupId>
+ <artifactId>cometd-java-annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.cometd.java</groupId>
+ <artifactId>cometd-java-client</artifactId>
+ <version>${cometd.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.cometd.java</groupId>
+ <artifactId>cometd-java-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.cometd.java</groupId>
+ <artifactId>cometd-java-oort</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.cometd.java</groupId>
+ <artifactId>cometd-java-server</artifactId>
+ </dependency>
+ <!-- ftp -->
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ </dependency>
+ <!-- mysql -->
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
+ <!-- http server -->
+ <dependency>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+ <!-- UT -->
+ <dependency>
+ <groupId>io.dropwizard</groupId>
+ <artifactId>dropwizard-testing</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- UT end -->
+ <!-- httpclient-->
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${httpclient.version}</version>
+ <exclusions>
+ <!-- provided by jcl-over-slf4j to enable logging via logback -->
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpcore</artifactId>
+ <version>${httpclient.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpmime</artifactId>
+ <version>${httpclient.version}</version>
+ </dependency>
+ </dependencies>
+</project>
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog;\r
-\r
-import com.fasterxml.jackson.annotation.JsonInclude;\r
-\r
-import io.dropwizard.Application;\r
-import io.dropwizard.assets.AssetsBundle;\r
-import io.dropwizard.db.DataSourceFactory;\r
-import io.dropwizard.hibernate.HibernateBundle;\r
-import io.dropwizard.migrations.MigrationsBundle;\r
-import io.dropwizard.server.SimpleServerFactory;\r
-import io.dropwizard.setup.Bootstrap;\r
-import io.dropwizard.setup.Environment;\r
-import io.swagger.jaxrs.config.BeanConfig;\r
-import io.swagger.jaxrs.listing.ApiListingResource;\r
-\r
-import org.eclipse.jetty.servlets.CrossOriginFilter;\r
-import org.glassfish.jersey.media.multipart.MultiPartFeature;\r
-import org.openo.commontosca.catalog.common.Config;\r
-import org.openo.commontosca.catalog.common.HttpServerAddrConfig;\r
-import org.openo.commontosca.catalog.common.HttpServerPathConfig;\r
-import org.openo.commontosca.catalog.common.MsbAddrConfig;\r
-import org.openo.commontosca.catalog.common.ServiceRegistrer;\r
-import org.openo.commontosca.catalog.db.dao.DaoManager;\r
-import org.openo.commontosca.catalog.db.entity.NodeTemplateData;\r
-import org.openo.commontosca.catalog.db.entity.PackageData;\r
-import org.openo.commontosca.catalog.db.entity.ServiceTemplateData;\r
-import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData;\r
-import org.openo.commontosca.catalog.health.ConsoleHealthCheck;\r
-import org.openo.commontosca.catalog.resources.PackageResource;\r
-import org.openo.commontosca.catalog.resources.TemplateResource;\r
-\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.util.EnumSet;\r
-import javax.servlet.DispatcherType;\r
-\r
-\r
-public class CatalogApp extends Application<CatalogAppConfiguration> {\r
-\r
- private static final Logger LOGGER = LoggerFactory.getLogger(CatalogApp.class);\r
-\r
- public static void main(String[] args) throws Exception {\r
- new CatalogApp().run(args);\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return "OPENO-Catalog";\r
- }\r
-\r
- private final HibernateBundle<CatalogAppConfiguration> bundle =\r
- new HibernateBundle<CatalogAppConfiguration>(ServiceTemplateData.class, PackageData.class,\r
- NodeTemplateData.class, ServiceTemplateMappingData.class) {\r
- @Override\r
- public DataSourceFactory getDataSourceFactory(CatalogAppConfiguration configuration) {\r
- return configuration.getDataSourceFactory();\r
- }\r
- };\r
-\r
- @Override\r
- public void initialize(Bootstrap<CatalogAppConfiguration> bootstrap) {\r
- bootstrap.addBundle(new AssetsBundle("/api-doc", "/api-doc", "index.html", "api-doc"));\r
- initDb(bootstrap);\r
- }\r
-\r
- private void initDao() {\r
- DaoManager.getInstance().setSessionFactory(bundle.getSessionFactory());\r
- }\r
-\r
- private void initDb(Bootstrap<CatalogAppConfiguration> bootstrap) {\r
- bootstrap.addBundle(bundle);\r
- bootstrap.addBundle(new MigrationsBundle<CatalogAppConfiguration>() {\r
- @Override\r
- public DataSourceFactory getDataSourceFactory(CatalogAppConfiguration configuration) {\r
- return configuration.getDataSourceFactory();\r
- }\r
- });\r
- }\r
-\r
- @Override\r
- public void run(CatalogAppConfiguration configuration, Environment environment) {\r
- LOGGER.info("Start to initialize catalogue.");\r
- MsbAddrConfig.setMsbAddress(configuration.getMsbServerAddr());\r
- HttpServerAddrConfig.setHttpServerAddress(configuration.getHttpServerAddr());\r
- HttpServerPathConfig.setHttpServerPath(configuration.getHttpServerPath());\r
- initDao();\r
- final ConsoleHealthCheck healthCheck = new ConsoleHealthCheck(configuration.getTemplate());\r
- environment.healthChecks().register("template", healthCheck);\r
-\r
- environment.jersey().register(new PackageResource());\r
- environment.jersey().register(new TemplateResource());\r
- // environment.jersey().register(new VNFHostImageResource());\r
- // environment.jersey().register(new VNFSoftwareVersionResource());\r
-\r
- // register rest interface\r
- environment.jersey().packages("org.openo.commontosca.catalog.resources");\r
- // upload file by inputstream need to register MultiPartFeature\r
- environment.jersey().register(MultiPartFeature.class);\r
-\r
- initSwaggerConfig(environment, configuration);\r
-// initCometd(environment);\r
- Config.setConfigration(configuration);\r
- initService();\r
- LOGGER.info("Initialize catalogue finished.");\r
- }\r
-\r
- /**\r
- * initialize swagger configuration.\r
- * \r
- * @param environment environment information\r
- * @param configuration catalogue configuration\r
- */\r
- private void initSwaggerConfig(Environment environment, CatalogAppConfiguration configuration) {\r
- environment.jersey().register(new ApiListingResource());\r
- environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);\r
-\r
- BeanConfig config = new BeanConfig();\r
- config.setTitle("Open-o Catalog Service rest API");\r
- config.setVersion("1.0.0");\r
- config.setResourcePackage("org.openo.commontosca.catalog.resources");\r
- // set rest api basepath in swagger\r
- SimpleServerFactory simpleServerFactory =\r
- (SimpleServerFactory) configuration.getServerFactory();\r
- String basePath = simpleServerFactory.getApplicationContextPath();\r
- String rootPath = simpleServerFactory.getJerseyRootPath();\r
- rootPath = rootPath.substring(0, rootPath.indexOf("/*"));\r
- basePath =\r
- basePath.equals("/") ? rootPath : (new StringBuilder()).append(basePath).append(rootPath)\r
- .toString();\r
- config.setBasePath(basePath);\r
- config.setScan(true);\r
- }\r
-\r
- private void initService() {\r
- Thread registerCatalogService = new Thread(new ServiceRegistrer());\r
- registerCatalogService.setName("register catalog service to Microservice Bus");\r
- registerCatalogService.start();\r
- }\r
-\r
- /**\r
- * initialize cometd server.\r
- * \r
- * @param environment environment information\r
- */\r
-// private void initCometd(Environment environment) {\r
-// // add filter\r
-// environment.getApplicationContext().addFilter(CrossOriginFilter.class,\r
-// "/api/nsoccataloguenotification/v1/*",\r
-// EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));\r
-// // add servlet\r
-// environment.getApplicationContext()\r
-// .addServlet("org.cometd.server.CometDServlet", "/api/nsoccataloguenotification/v1/*")\r
-// .setInitOrder(1);\r
-// // add servlet\r
-// environment.getApplicationContext()\r
-// .addServlet("CometdServlet", "/api/nsoccataloguenotification/v1").setInitOrder(2);\r
-// }\r
-}\r
+/**
+ * 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;
+
+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.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.health.ConsoleHealthCheck;
+import org.openo.commontosca.catalog.resources.PackageResource;
+import org.openo.commontosca.catalog.resources.TemplateResource;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+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 HibernateBundle<CatalogAppConfiguration> bundle =
+ new HibernateBundle<CatalogAppConfiguration>(ServiceTemplateData.class, PackageData.class,
+ NodeTemplateData.class, ServiceTemplateMappingData.class) {
+ @Override
+ public DataSourceFactory getDataSourceFactory(CatalogAppConfiguration configuration) {
+ return configuration.getDataSourceFactory();
+ }
+ };
+
+ @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,
+// "/api/nsoccataloguenotification/v1/*",
+// EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));
+// // add servlet
+// environment.getApplicationContext()
+// .addServlet("org.cometd.server.CometDServlet", "/api/nsoccataloguenotification/v1/*")
+// .setInitOrder(1);
+// // add servlet
+// environment.getApplicationContext()
+// .addServlet("CometdServlet", "/api/nsoccataloguenotification/v1").setInitOrder(2);
+// }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog;\r
-\r
-import com.fasterxml.jackson.annotation.JsonProperty;\r
-import io.dropwizard.Configuration;\r
-import io.dropwizard.db.DataSourceFactory;\r
-import org.hibernate.validator.constraints.NotEmpty;\r
-\r
-import javax.validation.Valid;\r
-import javax.validation.constraints.NotNull;\r
-\r
-\r
-\r
-\r
-public class CatalogAppConfiguration extends Configuration {\r
- @NotEmpty\r
- private String template;\r
-\r
- @NotEmpty\r
- private String defaultName = "OPENO-Catalog";\r
-\r
- @NotEmpty\r
- private String msbServerAddr;\r
-\r
- @NotEmpty\r
- private String httpServerAddr;\r
-\r
- @NotEmpty\r
- private String opentoscaServerAddr;\r
-\r
- @NotEmpty\r
- private String yamlParseAddr;\r
-\r
- @NotEmpty\r
- private String wso2HostIp;\r
-\r
- @NotEmpty\r
- private String wso2HostPort;\r
-\r
- @NotEmpty\r
- private String cataloguePath;\r
- @NotEmpty\r
- private String httpServerPath;\r
- @NotEmpty\r
- private String ldapServerIp;\r
-\r
- @NotEmpty\r
- private String ldapServerPort;\r
-\r
- @NotEmpty\r
- private String ldapLogindn;\r
-\r
- @NotEmpty\r
- private String ldapPassword;\r
-\r
- @NotEmpty\r
- private String ldapVersion;\r
- @Valid\r
- @NotNull\r
- private DataSourceFactory database = new DataSourceFactory();\r
-\r
- @JsonProperty("database")\r
- public DataSourceFactory getDataSourceFactory() {\r
- return database;\r
- }\r
-\r
- @JsonProperty("database")\r
- public void setDataSourceFactory(DataSourceFactory dataSourceFactory) {\r
- this.database = dataSourceFactory;\r
- }\r
-\r
- @JsonProperty\r
- public String getTemplate() {\r
- return template;\r
- }\r
-\r
- @JsonProperty\r
- public void setTemplate(String template) {\r
- this.template = template;\r
- }\r
-\r
- @JsonProperty\r
- public String getDefaultName() {\r
- return defaultName;\r
- }\r
-\r
- @JsonProperty\r
- public void setDefaultName(String name) {\r
- this.defaultName = name;\r
- }\r
-\r
- @JsonProperty\r
- public String getMsbServerAddr() {\r
- return msbServerAddr;\r
- }\r
-\r
- @JsonProperty\r
- public void setMsbServerAddr(String msbServerAddr) {\r
- this.msbServerAddr = msbServerAddr;\r
- }\r
-\r
- @JsonProperty\r
- public String getHttpServerAddr() {\r
- return httpServerAddr;\r
- }\r
-\r
- @JsonProperty\r
- public void setHttpServerAddr(String httpServerAddr) {\r
- this.httpServerAddr = httpServerAddr;\r
- }\r
-\r
- @JsonProperty\r
- public String getOpentoscaServerAddr() {\r
- return opentoscaServerAddr;\r
- }\r
-\r
- @JsonProperty\r
- public void setOpentoscaServerAddr(String opentoscaServerAddr) {\r
- this.opentoscaServerAddr = opentoscaServerAddr;\r
- }\r
-\r
- @JsonProperty\r
- public String getYamlParseAddr() {\r
- return yamlParseAddr;\r
- }\r
-\r
- @JsonProperty\r
- public void setYamlParseAddr(String yamlParseAddr) {\r
- this.yamlParseAddr = yamlParseAddr;\r
- }\r
-\r
- @JsonProperty\r
- public String getWso2HostIp() {\r
- return wso2HostIp;\r
- }\r
-\r
- @JsonProperty\r
- public void setWso2HostIp(String wso2HostIp) {\r
- this.wso2HostIp = wso2HostIp;\r
- }\r
-\r
- @JsonProperty\r
- public String getWso2HostPort() {\r
- return wso2HostPort;\r
- }\r
-\r
- @JsonProperty\r
- public void setWso2HostPort(String wso2HostPort) {\r
- this.wso2HostPort = wso2HostPort;\r
- }\r
-\r
- public String getWso2BaseUrl() {\r
- return "http://" + this.wso2HostIp + ":" + this.wso2HostPort;\r
- }\r
-\r
- @JsonProperty\r
- public String getCataloguePath() {\r
- return cataloguePath;\r
- }\r
-\r
- @JsonProperty\r
- public void setCataloguePath(String cataloguePath) {\r
- this.cataloguePath = cataloguePath;\r
- }\r
-\r
- @JsonProperty\r
- public String getLdapServerIp() {\r
- return ldapServerIp;\r
- }\r
-\r
- @JsonProperty\r
- public void setLdapServerIp(String ldapServerIp) {\r
- this.ldapServerIp = ldapServerIp;\r
- }\r
-\r
- @JsonProperty\r
- public String getLdapServerPort() {\r
- return ldapServerPort;\r
- }\r
-\r
- @JsonProperty\r
- public void setLdapServerPort(String ldapServerPort) {\r
- this.ldapServerPort = ldapServerPort;\r
- }\r
-\r
- @JsonProperty\r
- public String getLdapLogindn() {\r
- return ldapLogindn;\r
- }\r
-\r
- @JsonProperty\r
- public void setLdapLogindn(String ldapLogindn) {\r
- this.ldapLogindn = ldapLogindn;\r
- }\r
-\r
- @JsonProperty\r
- public String getLdapPassword() {\r
- return ldapPassword;\r
- }\r
-\r
- @JsonProperty\r
- public void setLdapPassword(String ldapPassword) {\r
- this.ldapPassword = ldapPassword;\r
- }\r
-\r
- @JsonProperty\r
- public String getLdapVersion() {\r
- return ldapVersion;\r
- }\r
-\r
- @JsonProperty\r
- public void setLdapVersion(String ldapVersion) {\r
- this.ldapVersion = ldapVersion;\r
- }\r
-\r
- @JsonProperty\r
- public String getHttpServerPath() {\r
- return httpServerPath;\r
- }\r
-\r
- @JsonProperty\r
- public void setHttpServerPath(String httpServerPath) {\r
- this.httpServerPath = httpServerPath;\r
- }\r
-\r
-}\r
+/**
+ * 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;
+
+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 opentoscaServerAddr;
+
+ @NotEmpty
+ private String yamlParseAddr;
+
+ @NotEmpty
+ private String wso2HostIp;
+
+ @NotEmpty
+ private String wso2HostPort;
+
+ @NotEmpty
+ private String cataloguePath;
+ @NotEmpty
+ private String httpServerPath;
+ @NotEmpty
+ private String ldapServerIp;
+
+ @NotEmpty
+ private String ldapServerPort;
+
+ @NotEmpty
+ private String ldapLogindn;
+
+ @NotEmpty
+ private String ldapPassword;
+
+ @NotEmpty
+ private String ldapVersion;
+ @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;
+ }
+
+ @JsonProperty
+ public String getOpentoscaServerAddr() {
+ return opentoscaServerAddr;
+ }
+
+ @JsonProperty
+ public void setOpentoscaServerAddr(String opentoscaServerAddr) {
+ this.opentoscaServerAddr = opentoscaServerAddr;
+ }
+
+ @JsonProperty
+ public String getYamlParseAddr() {
+ return yamlParseAddr;
+ }
+
+ @JsonProperty
+ public void setYamlParseAddr(String yamlParseAddr) {
+ this.yamlParseAddr = yamlParseAddr;
+ }
+
+ @JsonProperty
+ public String getWso2HostIp() {
+ return wso2HostIp;
+ }
+
+ @JsonProperty
+ public void setWso2HostIp(String wso2HostIp) {
+ this.wso2HostIp = wso2HostIp;
+ }
+
+ @JsonProperty
+ public String getWso2HostPort() {
+ return wso2HostPort;
+ }
+
+ @JsonProperty
+ public void setWso2HostPort(String wso2HostPort) {
+ this.wso2HostPort = wso2HostPort;
+ }
+
+ public String getWso2BaseUrl() {
+ return "http://" + this.wso2HostIp + ":" + this.wso2HostPort;
+ }
+
+ @JsonProperty
+ public String getCataloguePath() {
+ return cataloguePath;
+ }
+
+ @JsonProperty
+ public void setCataloguePath(String cataloguePath) {
+ this.cataloguePath = cataloguePath;
+ }
+
+ @JsonProperty
+ public String getLdapServerIp() {
+ return ldapServerIp;
+ }
+
+ @JsonProperty
+ public void setLdapServerIp(String ldapServerIp) {
+ this.ldapServerIp = ldapServerIp;
+ }
+
+ @JsonProperty
+ public String getLdapServerPort() {
+ return ldapServerPort;
+ }
+
+ @JsonProperty
+ public void setLdapServerPort(String ldapServerPort) {
+ this.ldapServerPort = ldapServerPort;
+ }
+
+ @JsonProperty
+ public String getLdapLogindn() {
+ return ldapLogindn;
+ }
+
+ @JsonProperty
+ public void setLdapLogindn(String ldapLogindn) {
+ this.ldapLogindn = ldapLogindn;
+ }
+
+ @JsonProperty
+ public String getLdapPassword() {
+ return ldapPassword;
+ }
+
+ @JsonProperty
+ public void setLdapPassword(String ldapPassword) {
+ this.ldapPassword = ldapPassword;
+ }
+
+ @JsonProperty
+ public String getLdapVersion() {
+ return ldapVersion;
+ }
+
+ @JsonProperty
+ public void setLdapVersion(String ldapVersion) {
+ this.ldapVersion = ldapVersion;
+ }
+
+ @JsonProperty
+ public String getHttpServerPath() {
+ return httpServerPath;
+ }
+
+ @JsonProperty
+ public void setHttpServerPath(String httpServerPath) {
+ this.httpServerPath = httpServerPath;
+ }
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.common;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-public class CommonErrorResponse {\r
-\r
- private String code;\r
-\r
- private String message;\r
-\r
-\r
- public static Object failure(String message) {\r
- return message;\r
- }\r
-\r
- public CommonErrorResponse(String message) {\r
- super();\r
- this.message = message;\r
- }\r
-\r
-}\r
+/**
+ * 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.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;
+ }
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.common;\r
-\r
-import org.openo.commontosca.catalog.CatalogAppConfiguration;\r
-\r
-\r
-public class Config {\r
- private static CatalogAppConfiguration configration;\r
-\r
- public static CatalogAppConfiguration getConfigration() {\r
- return configration;\r
- }\r
-\r
- public static void setConfigration(CatalogAppConfiguration config) {\r
- configration = config;\r
- }\r
-}\r
+/**
+ * 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.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;
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.common;\r
-\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.io.BufferedOutputStream;\r
-import java.io.File;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.OutputStream;\r
-import java.util.ArrayList;\r
-import java.util.Enumeration;\r
-import java.util.zip.ZipEntry;\r
-import java.util.zip.ZipFile;\r
-\r
-\r
-public final class FileUtil {\r
-\r
- public static final Logger LOG = LoggerFactory.getLogger(FileUtil.class);\r
-\r
- private static final int BUFFER_SIZE = 2 * 1024 * 1024;\r
-\r
- private static final int TRY_COUNT = 3;\r
-\r
- private FileUtil() {\r
-\r
- }\r
-\r
-\r
- /**\r
- * create dir.\r
- * @param dir dir to create\r
- * @return boolean\r
- */\r
- public static boolean createDirectory(String dir) {\r
- File folder = new File(dir);\r
- int tryCount = 0;\r
- while (tryCount < TRY_COUNT) {\r
- tryCount++;\r
- if (!folder.exists() && !folder.mkdirs()) {\r
- continue;\r
- } else {\r
- return true;\r
- }\r
- }\r
-\r
- return folder.exists();\r
- }\r
-\r
- /**\r
- * delete file.\r
- * @param file the file to delete\r
- * @return boolean\r
- */\r
- public static boolean deleteFile(File file) {\r
- String hintInfo = file.isDirectory() ? "dir " : "file ";\r
- boolean isFileDeleted = file.delete();\r
- boolean isFileExist = file.exists();\r
- if (!isFileExist) {\r
- if (isFileDeleted) {\r
- LOG.info("delete " + hintInfo + file.getAbsolutePath());\r
- } else {\r
- isFileDeleted = true;\r
- LOG.info("file not exist. no need delete " + hintInfo + file.getAbsolutePath());\r
- }\r
- } else {\r
- LOG.info("fail to delete " + hintInfo + file.getAbsolutePath());\r
- }\r
- return isFileDeleted;\r
- }\r
-\r
-\r
- /**\r
- * unzip zip file.\r
- * @param zipFileName file name to zip\r
- * @param extPlace extPlace\r
- * @return unzip file name\r
- * @throws IOException e1\r
- */\r
- public static ArrayList<String> unzip(String zipFileName, String extPlace) throws IOException {\r
- ZipFile zipFile = null;\r
- ArrayList<String> unzipFileNams = new ArrayList<String>();\r
-\r
- try {\r
- zipFile = new ZipFile(zipFileName);\r
- Enumeration<?> fileEn = zipFile.entries();\r
- byte[] buffer = new byte[BUFFER_SIZE];\r
-\r
- while (fileEn.hasMoreElements()) {\r
- InputStream input = null;\r
- BufferedOutputStream bos = null;\r
- try {\r
- ZipEntry entry = (ZipEntry) fileEn.nextElement();\r
- if (entry.isDirectory()) {\r
- continue;\r
- }\r
-\r
- input = zipFile.getInputStream(entry);\r
- File file = new File(extPlace, entry.getName());\r
- if (!file.getParentFile().exists()) {\r
- createDirectory(file.getParentFile().getAbsolutePath());\r
- }\r
-\r
- bos = new BufferedOutputStream(new FileOutputStream(file));\r
- while (true) {\r
- int length = input.read(buffer);\r
- if (length == -1) {\r
- break;\r
- }\r
- bos.write(buffer, 0, length);\r
- }\r
- unzipFileNams.add(file.getAbsolutePath());\r
- } finally {\r
- closeOutputStream(bos);\r
- closeInputStream(input);\r
- }\r
- }\r
- } finally {\r
- closeZipFile(zipFile);\r
- }\r
- return unzipFileNams;\r
- }\r
-\r
- /**\r
- * close InputStream.\r
- * \r
- * @param inputStream the inputstream to close\r
- */\r
- private static void closeInputStream(InputStream inputStream) {\r
- try {\r
- if (inputStream != null) {\r
- inputStream.close();\r
- }\r
- } catch (Exception e1) {\r
- LOG.info("close InputStream error!");\r
- }\r
- }\r
-\r
- /**\r
- * close OutputStream.\r
- * \r
- * @param outputStream the output stream to close\r
- */\r
- private static void closeOutputStream(OutputStream outputStream) {\r
- try {\r
- if (outputStream != null) {\r
- outputStream.close();\r
- }\r
- } catch (Exception e1) {\r
- LOG.info("close OutputStream error!");\r
- }\r
- }\r
-\r
- /**\r
- * close zipFile.\r
- * \r
- * @param zipFile the zipFile to close\r
- */\r
- private static void closeZipFile(ZipFile zipFile) {\r
- try {\r
- if (zipFile != null) {\r
- zipFile.close();\r
- zipFile = null;\r
- }\r
- } catch (IOException e1) {\r
- LOG.info("close ZipFile error!");\r
- }\r
- }\r
-}\r
+/**
+ * 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.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!");
+ }
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.common;\r
-\r
-\r
-public class HttpServerAddrConfig {\r
-\r
- protected static String httpServerAddress;\r
-\r
- public static String getHttpServerAddress() {\r
- return httpServerAddress;\r
- }\r
-\r
- public static void setHttpServerAddress(String httpServerAddress) {\r
- HttpServerAddrConfig.httpServerAddress = httpServerAddress;\r
- }\r
-\r
-}\r
+/**
+ * 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.common;
+
+
+public class HttpServerAddrConfig {
+
+ protected static String httpServerAddress;
+
+ public static String getHttpServerAddress() {
+ return httpServerAddress;
+ }
+
+ public static void setHttpServerAddress(String httpServerAddress) {
+ HttpServerAddrConfig.httpServerAddress = httpServerAddress;
+ }
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.common;\r
-\r
-\r
-public class HttpServerPathConfig {\r
- protected static String httpServerPath;\r
-\r
- public static String getHttpServerPath() {\r
- return httpServerPath;\r
- }\r
-\r
- public static void setHttpServerPath(String httpServerPath) {\r
- HttpServerPathConfig.httpServerPath = httpServerPath;\r
- }\r
-}\r
+/**
+ * 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.common;
+
+
+public class HttpServerPathConfig {
+ protected static String httpServerPath;
+
+ public static String getHttpServerPath() {
+ return httpServerPath;
+ }
+
+ public static void setHttpServerPath(String httpServerPath) {
+ HttpServerPathConfig.httpServerPath = httpServerPath;
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.common;\r
-\r
-public class MsbAddrConfig {\r
-\r
- protected static String msbAddress;\r
-\r
- public static String getMsbAddress() {\r
- return msbAddress;\r
- }\r
-\r
- public static void setMsbAddress(String msbAddress) {\r
- MsbAddrConfig.msbAddress = msbAddress;\r
- }\r
-\r
-}\r
+/**
+ * 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.common;
+
+public class MsbAddrConfig {
+
+ protected static String msbAddress;
+
+ public static String getMsbAddress() {
+ return msbAddress;
+ }
+
+ public static void setMsbAddress(String msbAddress) {
+ MsbAddrConfig.msbAddress = msbAddress;
+ }
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.common;\r
-\r
-/**\r
- * micro-service bus utility class.\r
- * \r
- */\r
-public class MsbUtil {\r
-\r
- public static String getRocBaseUrl() {\r
- return Config.getConfigration().getMsbServerAddr() + getRocApiRootDomain();\r
- }\r
-\r
- private static String getRocApiRootDomain() {\r
- return "/api/roc/v1";\r
- }\r
-\r
- public static String getNsocLifecycleBaseUrl() {\r
- return Config.getConfigration().getMsbServerAddr() + getNsocLifeCycleRootDomain();\r
- }\r
-\r
- private static String getNsocLifeCycleRootDomain() {\r
- return "/api/nsoc/v1";\r
- }\r
-\r
- public static String getVimBaseUrl() {\r
- return Config.getConfigration().getMsbServerAddr() + getVimRootDomain();\r
- }\r
-\r
- private static String getVimRootDomain() {\r
- return "/api/vim/v1";\r
- }\r
-\r
- public static String getPackageUrl() {\r
- return Config.getConfigration().getMsbServerAddr() + "/api/nsoc/v1/csar/";\r
- }\r
-\r
- public static String getYamlParseBaseUrl() {\r
- return Config.getConfigration().getYamlParseAddr() + "/api/yamlparser/v1";\r
- }\r
-}\r
+/**
+ * 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.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().getYamlParseAddr() + "/api/yamlparser/v1";
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.common;\r
-\r
-import javax.ws.rs.core.Response;\r
-\r
-\r
-public class RestUtil {\r
-\r
- /**\r
- * get rest exception.\r
- * @param errorMsg error message\r
- * @return Response\r
- */\r
- public static Response getRestException(String errorMsg) {\r
- String code = "001";\r
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR)\r
- .entity(new CommonErrorResponse(code, errorMsg)).build();\r
- }\r
-\r
-}\r
+/**
+ * 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.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();
+ }
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.common;\r
-\r
-import org.openo.commontosca.catalog.externalservice.msb.MicroserviceBusConsumer;\r
-import org.openo.commontosca.catalog.externalservice.msb.ServiceRegisterEntity;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-\r
-public class ServiceRegistrer implements Runnable {\r
- private final ArrayList<ServiceRegisterEntity> serviceEntityList =\r
- new ArrayList<ServiceRegisterEntity>();\r
- private static final Logger LOG = LoggerFactory.getLogger(ServiceRegistrer.class);\r
-\r
- public ServiceRegistrer() {\r
- initServiceEntity();\r
- }\r
-\r
- @Override\r
- public void run() {\r
- LOG.info("start microservice register");\r
- boolean flag = false;\r
- ServiceRegisterEntity entity = new ServiceRegisterEntity();\r
- int retry = 0;\r
- while (retry < 1000 && serviceEntityList.size() > 0) {\r
- Iterator<ServiceRegisterEntity> it = serviceEntityList.iterator();\r
- while (it.hasNext()) {\r
- entity = it.next();\r
- LOG.info("start" + entity.getServiceName() + " catalog microservice register.retry:"\r
- + retry);\r
- flag = MicroserviceBusConsumer.registerService(entity);\r
- if (flag == false) {\r
- LOG.warn(entity.getServiceName()\r
- + " microservice register failed, sleep 30S and try again.");\r
- threadSleep(30000);\r
- } else {\r
- LOG.info(entity.getServiceName() + " microservice register success!");\r
- it.remove();\r
- }\r
- }\r
- retry++;\r
-\r
- }\r
- LOG.info("catalog microservice register end.");\r
-\r
- }\r
-\r
- /**\r
- * sleep thread.\r
- * @param second sleep second\r
- */\r
- private void threadSleep(int seconds) {\r
- LOG.info("start sleep ....");\r
- try {\r
- Thread.sleep(seconds);\r
- } catch (InterruptedException e1) {\r
- LOG.error("thread sleep error.errorMsg:" + e1.getMessage());\r
- }\r
- LOG.info("sleep end .");\r
- }\r
-\r
- private void initServiceEntity() {\r
- ServiceRegisterEntity catalogEntity = new ServiceRegisterEntity();\r
- catalogEntity.setServiceName("catalog");\r
- catalogEntity.setProtocol("REST");\r
- catalogEntity.setVersion("v1");\r
- catalogEntity.setUrl("/openoapi/catalog/v1");\r
- catalogEntity.setSingleNode(null, "8200", 0);\r
- catalogEntity.setVisualRange("1");\r
- serviceEntityList.add(catalogEntity);\r
- ServiceRegisterEntity httpServiceEntity = new ServiceRegisterEntity();\r
- httpServiceEntity.setServiceName("/files/catalog-http");\r
- httpServiceEntity.setProtocol("REST");\r
- httpServiceEntity.setVersion("v1");\r
- httpServiceEntity.setUrl("/");\r
- httpServiceEntity.setSingleNode(null, "8201", 0);\r
- httpServiceEntity.setVisualRange("1");\r
- serviceEntityList.add(httpServiceEntity);\r
- }\r
-}\r
+/**
+ * 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.common;
+
+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(null, "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(null, "8201", 0);
+ httpServiceEntity.setVisualRange("1");
+ serviceEntityList.add(httpServiceEntity);
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.common;\r
-\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.io.BufferedInputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.util.zip.CRC32;\r
-import java.util.zip.CheckedOutputStream;\r
-import java.util.zip.ZipEntry;\r
-import java.util.zip.ZipOutputStream;\r
-\r
-\r
-public class ZipCompressor {\r
-\r
- public static final Logger LOG = LoggerFactory.getLogger(ZipCompressor.class);\r
- static final int BUFFER = 8192;\r
-\r
- private File zipFile;\r
-\r
- public ZipCompressor(String pathName) {\r
- zipFile = new File(pathName);\r
- }\r
-\r
- /**\r
- * compress file according several path.\r
- * @param pathName file path name\r
- */\r
- public void compress(String... pathName) {\r
- ZipOutputStream out = null;\r
- try {\r
- FileOutputStream fileOutputStream = new FileOutputStream(zipFile);\r
- CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream, new CRC32());\r
- out = new ZipOutputStream(cos);\r
- String basedir = "";\r
- for (int i = 0; i < pathName.length; i++) {\r
- compress(new File(pathName[i]), out, basedir);\r
- }\r
- out.close();\r
- } catch (Exception e1) {\r
- throw new RuntimeException(e1);\r
- }\r
- }\r
-\r
- /**\r
- * compress file according file path.\r
- * @param srcPathName file path name\r
- */\r
- public void compress(String srcPathName) {\r
- File file = new File(srcPathName);\r
- if (!file.exists()) {\r
- throw new RuntimeException(srcPathName + "not exist!");\r
- }\r
- try {\r
- FileOutputStream fileOutputStream = new FileOutputStream(zipFile);\r
- CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream, new CRC32());\r
- ZipOutputStream out = new ZipOutputStream(cos);\r
- String basedir = "";\r
- compress(file, out, basedir);\r
- out.close();\r
- } catch (Exception e1) {\r
- throw new RuntimeException(e1);\r
- }\r
- }\r
-\r
- private void compress(File file, ZipOutputStream out, String basedir) {\r
- if (file.isDirectory()) {\r
- System.out.println("compress:" + basedir + file.getName());\r
- this.compressDirectory(file, out, basedir);\r
- } else {\r
- System.out.println("compress:" + basedir + file.getName());\r
- this.compressFile(file, out, basedir);\r
- }\r
- }\r
-\r
- private void compressDirectory(File dir, ZipOutputStream out, String basedir) {\r
- if (!dir.exists()) {\r
- return;\r
- }\r
-\r
- File[] files = dir.listFiles();\r
- for (int i = 0; i < files.length; i++) {\r
- compress(files[i], out, basedir + dir.getName() + "/");\r
- }\r
- }\r
-\r
- private void compressFile(File file, ZipOutputStream out, String basedir) {\r
- if (!file.exists()) {\r
- return;\r
- }\r
- try {\r
- byte data[] = new byte[BUFFER];\r
- BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));\r
- ZipEntry entry = new ZipEntry(basedir + file.getName());\r
- out.putNextEntry(entry);\r
- int count;\r
- while ((count = bis.read(data, 0, BUFFER)) != -1) {\r
- out.write(data, 0, count);\r
- }\r
- bis.close();\r
- } catch (Exception e1) {\r
- throw new RuntimeException(e1);\r
- }\r
- }\r
-}\r
+/**
+ * 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.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);
+ }
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-public class CsarQueryCondition {\r
-\r
- private String csarId;\r
-\r
- private String name;\r
-\r
- private String provider;\r
-\r
- private String version;\r
-\r
- private Boolean deletionPending;\r
-\r
- private EnumType type;\r
-}\r
+/**
+ * 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.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;
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity;\r
-\r
-public enum EnumOnboardState {\r
- onBoarded("onBoarded"), nonOnBoarded("non-onBoarded");\r
-\r
- String value;\r
-\r
- EnumOnboardState(String value) {\r
- this.value = value;\r
- }\r
-\r
- public String getValue() {\r
- return value;\r
- }\r
-}\r
+/**
+ * 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.entity;
+
+public enum EnumOnboardState {
+ onBoarded("onBoarded"), nonOnBoarded("non-onBoarded");
+
+ String value;
+
+ EnumOnboardState(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity;\r
-\r
-public enum EnumOperationalState {\r
- Enabled, Disabled\r
-}\r
+/**
+ * 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.entity;
+
+public enum EnumOperationalState {
+ Enabled, Disabled
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity;\r
-\r
-public enum EnumProcessState {\r
- normal, onBoarding, onBoardFailed, deleting, deleteFailed\r
-}\r
+/**
+ * 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.entity;
+
+public enum EnumProcessState {
+ normal, onBoarding, onBoardFailed, deleting, deleteFailed
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity;\r
-\r
-public enum EnumType {\r
- GSAR, SSAR, NSAR, NFAR\r
-}\r
+/**
+ * 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.entity;
+
+public enum EnumType {
+ GSAR, SSAR, NSAR, NFAR
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity;\r
-\r
-public enum EnumUsageState {\r
- InUse, NotInUse\r
-}\r
+/**
+ * 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.entity;
+
+public enum EnumUsageState {
+ InUse, NotInUse
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity;\r
-\r
-public class VnfPackage {\r
- private String vnfPackageId;\r
- private String name;\r
- private String version;\r
- private String provider;\r
- private String vnfd;\r
- private EnumOperationalState operationalState = EnumOperationalState.Disabled;\r
- private EnumUsageState usageState = EnumUsageState.InUse;\r
- private String deletionPending;\r
- private String vnfPackageUrl;\r
-\r
- public String getVnfPackageId() {\r
- return vnfPackageId;\r
- }\r
-\r
- public void setVnfPackageId(String vnfPackageId) {\r
- this.vnfPackageId = vnfPackageId;\r
- }\r
-\r
- public String getVersion() {\r
- return version;\r
- }\r
-\r
- public void setVersion(String version) {\r
- this.version = version;\r
- }\r
-\r
- public String getProvider() {\r
- return provider;\r
- }\r
-\r
- public void setProvider(String provider) {\r
- this.provider = provider;\r
- }\r
-\r
- public String getVnfd() {\r
- return vnfd;\r
- }\r
-\r
- public void setVnfd(String vnfd) {\r
- this.vnfd = vnfd;\r
- }\r
-\r
- public EnumOperationalState getOperationalState() {\r
- return operationalState;\r
- }\r
-\r
- public void setOperationalState(EnumOperationalState operationalState) {\r
- this.operationalState = operationalState;\r
- }\r
-\r
- public EnumUsageState getUsageState() {\r
- return usageState;\r
- }\r
-\r
- public void setUsageState(EnumUsageState usageState) {\r
- this.usageState = usageState;\r
- }\r
-\r
- public String getVnfPackageUrl() {\r
- return vnfPackageUrl;\r
- }\r
-\r
- public void setVnfPackageUrl(String vnfPackageUrl) {\r
- this.vnfPackageUrl = vnfPackageUrl;\r
- }\r
-\r
- public String getDeletionPending() {\r
- return deletionPending;\r
- }\r
-\r
- public void setDeletionPending(String deletionPending) {\r
- this.deletionPending = deletionPending;\r
- }\r
-\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-}\r
+/**
+ * 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.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;
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity.request;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-import org.openo.commontosca.catalog.entity.EnumType;\r
-\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-public class PackageBasicInfo {\r
-\r
- private String provider;\r
-\r
- private EnumType type;\r
-\r
- private String version;\r
-\r
- private String format;\r
-\r
-}\r
+/**
+ * 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.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;
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity.request;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-import org.openo.commontosca.catalog.entity.EnumType;\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-public class UploadPackageFromFtpRequest {\r
-\r
- private String provider;\r
-\r
- private EnumType type;\r
-\r
- private String version;\r
-\r
- private String ftpUrl;\r
-\r
-}\r
+/**
+ * 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.entity.request;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import org.openo.commontosca.catalog.entity.EnumType;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class UploadPackageFromFtpRequest {
+
+ private String provider;
+
+ private EnumType type;
+
+ private String version;
+
+ private String ftpUrl;
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity.response;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-public class CsarFileUriResponse {\r
-\r
- private String downloadUri;\r
-\r
- private String localPath;\r
-}\r
+/**
+ * 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.entity.response;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CsarFileUriResponse {
+
+ private String downloadUri;
+
+ private String localPath;
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity.response;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-import org.openo.commontosca.catalog.entity.EnumOperationalState;\r
-import org.openo.commontosca.catalog.entity.EnumProcessState;\r
-import org.openo.commontosca.catalog.entity.EnumUsageState;\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-public class PackageMeta {\r
-\r
- private String csarId;\r
-\r
- private String name;\r
-\r
- private String downloadUri;\r
-\r
- private String size;\r
-\r
- private String version;\r
-\r
- private String provider;\r
-\r
- private String type;\r
-\r
- private String format;\r
-\r
- private boolean deletionPending;\r
-\r
- private String createTime;\r
-\r
- private String modifyTime;\r
-\r
- private EnumOperationalState operationalState;\r
-\r
- private EnumUsageState usageState;\r
-\r
- private String onBoardState;\r
-\r
- private EnumProcessState processState;\r
-\r
-}\r
+/**
+ * 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.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;
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity.response;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-public class UpdatePackageResponse {\r
-\r
- private String usageState;\r
-\r
-}\r
+/**
+ * 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.entity.response;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class UpdatePackageResponse {
+
+ private String usageState;
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.entity.response;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-public class UploadPackageResponse {\r
-\r
- private String csarId;\r
-\r
-}\r
+/**
+ * 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.entity.response;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class UploadPackageResponse {
+
+ private String csarId;
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.externalservice.msb;\r
-\r
-import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
-import org.glassfish.jersey.client.ClientConfig;\r
-import org.openo.commontosca.catalog.common.Config;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-\r
-public class MicroserviceBusConsumer {\r
- private static final Logger LOG = LoggerFactory.getLogger(MicroserviceBusConsumer.class);\r
-\r
- /**\r
- * register service to MSB.\r
- * @param entity ServiceRegisterEntity\r
- * @return boolean\r
- */\r
- public static boolean registerService(ServiceRegisterEntity entity) {\r
- ClientConfig config = new ClientConfig();\r
- try {\r
- MicroserviceBusRest resourceserviceproxy =\r
- ConsumerFactory.createConsumer(Config.getConfigration().getMsbServerAddr(), config,\r
- MicroserviceBusRest.class);\r
- resourceserviceproxy.registerServce("false", entity);\r
- } catch (Exception e1) {\r
- LOG.error("microservice register failed!" + e1.getMessage());\r
- return false;\r
- }\r
- return true;\r
- }\r
-}\r
+/**
+ * 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 com.eclipsesource.jaxrs.consumer.ConsumerFactory;
+import org.glassfish.jersey.client.ClientConfig;
+import org.openo.commontosca.catalog.common.Config;
+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();
+ 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;
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.externalservice.msb;\r
-\r
-import javax.ws.rs.Consumes;\r
-import javax.ws.rs.POST;\r
-import javax.ws.rs.Path;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.QueryParam;\r
-import javax.ws.rs.core.MediaType;\r
-\r
-@Path("/openoapi/microservices/v1/services")\r
-// @Path("/api/microservices/v1/services")\r
-public interface MicroserviceBusRest {\r
- @Path("")\r
- @POST\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- public ServiceRegisterEntity registerServce(@QueryParam("createOrUpdate") String createOrUpdate,\r
- ServiceRegisterEntity entity) throws Exception;\r
-}\r
+/**
+ * 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 javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+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;
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.externalservice.msb;\r
-\r
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-@JsonIgnoreProperties(ignoreUnknown = true)\r
-public class ServiceNode {\r
- private String ip;\r
- private String port;\r
- private int ttl;\r
-}\r
+/**
+ * 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 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;
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.externalservice.msb;\r
-\r
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-import java.util.ArrayList;\r
-\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-@JsonIgnoreProperties(ignoreUnknown = true)\r
-public class ServiceRegisterEntity {\r
- private String serviceName;\r
- private String version;\r
- private String url;\r
- private String protocol;\r
- private String visualRange;\r
- private ArrayList<ServiceNode> nodes = new ArrayList<ServiceNode>();\r
-\r
- /**\r
- * set single node.\r
- * @param ip ip\r
- * @param port port\r
- * @param ttl ttl\r
- */\r
- public void setSingleNode(String ip, String port, int ttl) {\r
- ServiceNode node = new ServiceNode();\r
- node.setIp(ip);\r
- node.setPort(port);\r
- node.setTtl(ttl);\r
- nodes.add(node);\r
- }\r
-\r
-}\r
+/**
+ * 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 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();
+ node.setIp(ip);
+ node.setPort(port);
+ node.setTtl(ttl);
+ nodes.add(node);
+ }
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.ftp;\r
-\r
-import lombok.AllArgsConstructor;\r
-import lombok.Data;\r
-import lombok.NoArgsConstructor;\r
-\r
-@Data\r
-@NoArgsConstructor\r
-@AllArgsConstructor\r
-public class Ftp {\r
-\r
- private String ipAddr;\r
-\r
- private Integer port;\r
-\r
- private String userName;\r
-\r
- private String pwd;\r
-\r
- private String path;\r
-\r
-}\r
+/**
+ * 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.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;
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.ftp;\r
-\r
-import org.apache.commons.net.ftp.FTPClient;\r
-import org.apache.commons.net.ftp.FTPFile;\r
-import org.apache.commons.net.ftp.FTPReply;\r
-import org.apache.log4j.Logger;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-\r
-public class FtpUtil {\r
-\r
- private static Logger logger = Logger.getLogger(FtpUtil.class);\r
-\r
- private static FTPClient ftp;\r
-\r
- /**\r
- * get ftp connection.\r
- * \r
- * @param conftp Ftp\r
- * @return boolean\r
- * @throws Exception e\r
- */\r
- public static boolean connectFtp(Ftp conftp) throws Exception {\r
- ftp = new FTPClient();\r
- boolean flag = false;\r
- if (conftp.getPort() == null) {\r
- ftp.connect(conftp.getIpAddr(), 21);\r
- } else {\r
- ftp.connect(conftp.getIpAddr(), conftp.getPort());\r
- }\r
- ftp.login(conftp.getUserName(), conftp.getPwd());\r
- ftp.setFileType(FTPClient.BINARY_FILE_TYPE);\r
- int reply = ftp.getReplyCode();\r
- if (!FTPReply.isPositiveCompletion(reply)) {\r
- ftp.disconnect();\r
- return flag;\r
- }\r
- ftp.changeWorkingDirectory(conftp.getPath());\r
- flag = true;\r
- return flag;\r
- }\r
-\r
- /**\r
- * close ftp connection.\r
- */\r
- public static void closeFtp() {\r
- if (ftp != null && ftp.isConnected()) {\r
- try {\r
- ftp.logout();\r
- ftp.disconnect();\r
- } catch (IOException e1) {\r
- e1.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * upload file by ftp.\r
- * \r
- * @param file file to upload\r
- * @throws Exception e\r
- */\r
- public static void upload(File file) throws Exception {\r
- if (file.isDirectory()) {\r
- ftp.makeDirectory(file.getName());\r
- ftp.changeWorkingDirectory(file.getName());\r
- String[] files = file.list();\r
- for (String fstr : files) {\r
- File file1 = new File(file.getPath() + "/" + fstr);\r
- if (file1.isDirectory()) {\r
- upload(file1);\r
- ftp.changeToParentDirectory();\r
- } else {\r
- File file2 = new File(file.getPath() + "/" + fstr);\r
- FileInputStream input = new FileInputStream(file2);\r
- ftp.storeFile(file2.getName(), input);\r
- input.close();\r
- }\r
- }\r
- } else {\r
- File file2 = new File(file.getPath());\r
- FileInputStream input = new FileInputStream(file2);\r
- ftp.storeFile(file2.getName(), input);\r
- input.close();\r
- }\r
- }\r
-\r
- /**\r
- * download inline config.\r
- * \r
- * @param downftp ftp to download\r
- * @param localBaseDir local directory\r
- * @param remoteBaseDir remote directory\r
- * @throws Exception e\r
- */\r
- public static void startDown(Ftp downftp, String localBaseDir, String remoteBaseDir)\r
- throws Exception {\r
- if (FtpUtil.connectFtp(downftp)) {\r
-\r
- try {\r
- FTPFile[] files = null;\r
- boolean changedir = ftp.changeWorkingDirectory(remoteBaseDir);\r
- if (changedir) {\r
- ftp.setControlEncoding("GBK");\r
- files = ftp.listFiles();\r
- for (int i = 0; i < files.length; i++) {\r
- try {\r
- downloadFile(files[i], localBaseDir, remoteBaseDir);\r
- } catch (Exception e1) {\r
- logger.error(e1);\r
- logger.error("<" + files[i].getName() + ">download failed");\r
- }\r
- }\r
- }\r
- } catch (Exception e1) {\r
- logger.error(e1);\r
- logger.error("error occoured while download");\r
- }\r
- } else {\r
- logger.error("Connect failed !");\r
- }\r
-\r
- }\r
-\r
-\r
- /**\r
- * download ftp file.\r
- * \r
- * @param ftpFile ftp file to download\r
- * @param relativeLocalPath relative local path\r
- * @param relativeRemotePath relative remote path\r
- */\r
- private static void downloadFile(FTPFile ftpFile, String relativeLocalPath,\r
- String relativeRemotePath) {\r
- if (ftpFile.isFile()) {\r
- if (ftpFile.getName().indexOf("?") == -1) {\r
- OutputStream outputStream = null;\r
- try {\r
- File locaFile = new File(relativeLocalPath + ftpFile.getName());\r
- // 判断文件是否存在,存在则返回\r
- if (locaFile.exists()) {\r
- return;\r
- } else {\r
- outputStream = new FileOutputStream(relativeLocalPath + ftpFile.getName());\r
- ftp.retrieveFile(ftpFile.getName(), outputStream);\r
- outputStream.flush();\r
- outputStream.close();\r
- }\r
- } catch (Exception e1) {\r
- logger.error(e1);\r
- } finally {\r
- try {\r
- if (outputStream != null) {\r
- outputStream.close();\r
- }\r
- } catch (IOException e1) {\r
- logger.error("输出文件流异常");\r
- }\r
- }\r
- }\r
- } else {\r
- String newlocalRelatePath = relativeLocalPath + ftpFile.getName();\r
- String newRemote = new String(relativeRemotePath + ftpFile.getName().toString());\r
- File fl = new File(newlocalRelatePath);\r
- if (!fl.exists()) {\r
- fl.mkdirs();\r
- }\r
- try {\r
- newlocalRelatePath = newlocalRelatePath + '/';\r
- newRemote = newRemote + "/";\r
- String currentWorkDir = ftpFile.getName().toString();\r
- boolean changedir = ftp.changeWorkingDirectory(currentWorkDir);\r
- if (changedir) {\r
- FTPFile[] files = null;\r
- files = ftp.listFiles();\r
- for (int i = 0; i < files.length; i++) {\r
- downloadFile(files[i], newlocalRelatePath, newRemote);\r
- }\r
- }\r
- if (changedir) {\r
- ftp.changeToParentDirectory();\r
- }\r
- } catch (Exception e1) {\r
- logger.error(e1);\r
- }\r
- }\r
- }\r
-}\r
+/**
+ * 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.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("输出文件流异常");
+ }
+ }
+ }
+ } 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);
+ }
+ }
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.health;\r
-\r
-import com.codahale.metrics.health.HealthCheck;\r
-\r
-public class ConsoleHealthCheck extends HealthCheck {\r
- private final String template;\r
-\r
- public ConsoleHealthCheck(String template) {\r
- this.template = template;\r
- }\r
-\r
- @Override\r
- protected Result check() throws Exception {\r
- final String saying = String.format(template, "TEST");\r
- if (!saying.contains("TEST")) {\r
- return Result.unhealthy("template doesn't include a name");\r
- }\r
- return Result.healthy();\r
- }\r
-}\r
+/**
+ * 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.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();
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.common;\r
-\r
-public enum EnumToscaNodeTypeDefinition {\r
- VNF {\r
- @Override\r
- public String getName() {\r
- return "tosca.nodes.nfv.VNF";\r
- }\r
- },\r
- VDU {\r
- @Override\r
- public String getName() {\r
- return "tosca.nodes.nfv.VDU";\r
- }\r
- },\r
- VNFC {\r
- @Override\r
- public String getName() {\r
- return "tosca.nodes.nfv.VNFC";\r
- }\r
- },\r
- VL {\r
- @Override\r
- public String getName() {\r
- return "tosca.nodes.nfv.VL";\r
- }\r
- },\r
- CP {\r
- @Override\r
- public String getName() {\r
- return "tosca.nodes.nfv.CP";\r
- }\r
- };\r
-\r
- public abstract String getName();\r
-\r
- /**\r
- * judge wether is tosca node type definition or not.\r
- * @param type node type\r
- * @return boolean\r
- */\r
- public static boolean isToscaNodeTypeDef(String type) {\r
- for (EnumToscaNodeTypeDefinition enumDef : EnumToscaNodeTypeDefinition.values()) {\r
- if (type.indexOf(enumDef.getName()) != -1) {\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
-}\r
+/**
+ * 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.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;
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.common;\r
-\r
-public enum EnumToscaRelationShipDefinition {\r
- VirtualBindsTo {\r
- @Override\r
- public String getName() {\r
- return "tosca.relationships.nfv.VirtualBindsTo";\r
- }\r
- },\r
- VirtualLinksTo {\r
- @Override\r
- public String getName() {\r
- return "tosca.relationships.nfv.VirtualLinksTo";\r
- }\r
- },\r
- DeployedOn {\r
- @Override\r
- public String getName() {\r
- return "tosca.relationships.nfv.DeployedOn";\r
- }\r
- },\r
- BelongTo {\r
- @Override\r
- public String getName() {\r
- return "tosca.relationships.nfv.BelongTo";\r
- }\r
- };\r
-\r
- public abstract String getName();\r
-\r
-}\r
+/**
+ * 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.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();
+
+}
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 javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
-import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerSelfService;
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 javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
-import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServicePackageList;
+
/**
* The opentosca container service returns data to the package entity.
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 javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
-import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServiceTemplateList;
-
/**
* The opentosca container self service returns data to the service template entity.
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.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServicePackageList;
-
-
/**
* The opentosca container interface for csar.
*
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;
-import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerSelfService;
-
/**
* The opentosca container interface for self service.
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.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServiceNodeTemplateList;
-import org.openo.commontosca.catalog.model.externalservice.entity.container.ContainerServiceTemplateList;
-
/**
* The opentosca container interface for service template.
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.externalservice.container;\r
-\r
-import org.xml.sax.Attributes;\r
-import org.xml.sax.SAXException;\r
-import org.xml.sax.helpers.XMLFilterImpl;\r
-\r
-/**\r
- * NamespaceFilter.\r
- * \r
- * @author 10189609\r
- * \r
- */\r
-public class NamespaceFilter extends XMLFilterImpl {\r
-\r
- private String usedNamespaceUri;\r
- private boolean addNamespace;\r
-\r
- // State variable\r
- private boolean addedNamespace = false;\r
-\r
- /**\r
- * constructor.\r
- * @param namespaceUri namspace uri\r
- * @param addNamespace add namespace or not\r
- */\r
- public NamespaceFilter(String namespaceUri, boolean addNamespace) {\r
- super();\r
-\r
- if (addNamespace) {\r
- this.usedNamespaceUri = namespaceUri;\r
- } else {\r
- this.usedNamespaceUri = "";\r
- }\r
- this.addNamespace = addNamespace;\r
- }\r
-\r
-\r
-\r
- @Override\r
- public void startDocument() throws SAXException {\r
- super.startDocument();\r
- if (addNamespace) {\r
- startControlledPrefixMapping();\r
- }\r
- }\r
-\r
-\r
-\r
- @Override\r
- public void startElement(String arg0, String arg1, String arg2, Attributes arg3)\r
- throws SAXException {\r
-\r
- super.startElement(this.usedNamespaceUri, arg1, arg2, arg3);\r
- }\r
-\r
- @Override\r
- public void endElement(String arg0, String arg1, String arg2) throws SAXException {\r
-\r
- super.endElement(this.usedNamespaceUri, arg1, arg2);\r
- }\r
-\r
- @Override\r
- public void startPrefixMapping(String prefix, String url) throws SAXException {\r
-\r
-\r
- if (addNamespace) {\r
- this.startControlledPrefixMapping();\r
- } else {\r
- // Remove the namespace, i.e. don´t call startPrefixMapping for parent!\r
- }\r
-\r
- }\r
-\r
- private void startControlledPrefixMapping() throws SAXException {\r
-\r
- if (this.addNamespace && !this.addedNamespace) {\r
- // We should add namespace since it is set and has not yet been done.\r
- super.startPrefixMapping("", this.usedNamespaceUri);\r
-\r
- // Make sure we dont do it twice\r
- this.addedNamespace = true;\r
- }\r
- }\r
-\r
-}\r
+/**
+ * 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.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;
+ }
+ }
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.externalservice.lifecycle;\r
-\r
-import javax.ws.rs.GET;\r
-import javax.ws.rs.Path;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.core.MediaType;\r
-\r
-/**\r
- * The lifecycle interface.\r
- * \r
- * @author 10189609\r
- * \r
- */\r
-@Path("/appinstances")\r
-public interface ILifeCycleServiceRest {\r
- @GET\r
- @Produces(MediaType.APPLICATION_JSON)\r
- public String getVnfInstances();\r
-}\r
+/**
+ * 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.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();
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.externalservice.lifecycle;\r
-\r
-import com.google.gson.Gson;\r
-import com.google.gson.reflect.TypeToken;\r
-\r
-import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
-import org.openo.commontosca.catalog.common.MsbUtil;\r
-import org.openo.commontosca.catalog.common.ToolUtil;\r
-import org.openo.commontosca.catalog.model.externalservice.entity.lifecycle.InstanceEntity;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.lang.reflect.Type;\r
-import java.util.ArrayList;\r
-\r
-\r
-\r
-/**\r
- * The lifecycle service.\r
- * \r
- * @author 10189609\r
- * \r
- */\r
-public class LifeCycleServiceConsumer {\r
- private static final Logger LOG = LoggerFactory.getLogger(LifeCycleServiceConsumer.class);\r
-\r
- /**\r
- * get lifecycle application instances.\r
- * \r
- * @return instance entity\r
- */\r
- public static ArrayList<InstanceEntity> getInstances() {\r
- ILifeCycleServiceRest resourceserviceproxy =\r
- ConsumerFactory.createConsumer(MsbUtil.getNsocLifecycleBaseUrl(),\r
- ILifeCycleServiceRest.class);\r
- String result = "";\r
- try {\r
- result = resourceserviceproxy.getVnfInstances();\r
- } catch (Exception e1) {\r
- LOG.error("query vim info faild.", e1);\r
- return null;\r
- }\r
- if (ToolUtil.isEmptyString(result)) {\r
- return null;\r
- }\r
-\r
- Gson gson = new Gson();\r
- Type listType = new TypeToken<ArrayList<InstanceEntity>>() {}.getType();\r
- return gson.fromJson(result, listType);\r
- }\r
-}\r
+/**
+ * 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.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);
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.externalservice.ro;\r
-\r
-import javax.ws.rs.GET;\r
-import javax.ws.rs.Path;\r
-import javax.ws.rs.PathParam;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.core.MediaType;\r
-\r
-/**\r
- * The roc resource interface.\r
- * \r
- * @author 10189609\r
- * \r
- */\r
-@Path("/resource")\r
-public interface IResourceServiceRest {\r
- @Path("/vims/{vim_id}")\r
- @GET\r
- @Produces(MediaType.APPLICATION_JSON)\r
- public String getResourceVim(@PathParam("vim_id") String vimId) throws Exception;\r
-}\r
+/**
+ * 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.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;
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.externalservice.ro;\r
-\r
-import com.google.gson.Gson;\r
-\r
-import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
-\r
-import org.openo.commontosca.catalog.common.MsbUtil;\r
-import org.openo.commontosca.catalog.common.ToolUtil;\r
-import org.openo.commontosca.catalog.model.externalservice.entity.ro.ResourceResponseEntity;\r
-import org.openo.commontosca.catalog.model.externalservice.entity.ro.VimEntity;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-\r
-/**\r
- * The roc resource service.\r
- * \r
- * @author 10189609\r
- * \r
- */\r
-public class ResourceServiceConsumer {\r
- private static final Logger LOG = LoggerFactory.getLogger(ResourceServiceConsumer.class);\r
-\r
- private static final String RESOURCE_REST_RESULT = "SUCCESS";\r
-\r
- /**\r
- * get vim entity from roc by vimid.\r
- * \r
- * @param vimId id\r
- * @return vim entity\r
- */\r
- public static VimEntity getResourceVim(String vimId) {\r
- LOG.info("begin query vim info from roc,vimId:" + vimId);\r
- IResourceServiceRest resourceserviceproxy =\r
- ConsumerFactory.createConsumer(MsbUtil.getRocBaseUrl(), IResourceServiceRest.class);\r
- String result = "";\r
- try {\r
- result = resourceserviceproxy.getResourceVim(vimId);\r
- } catch (Exception e1) {\r
- LOG.error("query vim info faild.", e1);\r
- return null;\r
- }\r
- if (ToolUtil.isEmptyString(result)) {\r
- LOG.error("query vim info faild, vim info is null, vimId:" + vimId);\r
- return null;\r
- }\r
-\r
- Gson gson = new Gson();\r
- ResourceResponseEntity responseEntity = gson.fromJson(result, ResourceResponseEntity.class);\r
- if (!RESOURCE_REST_RESULT.equalsIgnoreCase(responseEntity.getOperationResult())) {\r
- LOG.error("query vim info faild.vimId:" + vimId);\r
- return null;\r
- }\r
- if (responseEntity.getData().size() <= 0) {\r
- LOG.error("query vim info faild, vim info is empty, vimId:" + vimId);\r
- return null;\r
- }\r
-\r
- LOG.info("end query vim info from roc.");\r
- return responseEntity.getData().get(0);\r
- }\r
-}\r
+/**
+ * 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.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);
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.parser;\r
-\r
-import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
-\r
-public abstract class AbstractModelParser {\r
- \r
- public abstract String parse(String packageId, String fileLocation)\r
- throws CatalogResourceException;\r
-\r
-}\r
+/**
+ * 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.parser;
+
+import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
+
+public abstract class AbstractModelParser {
+
+ public abstract String parse(String packageId, String fileLocation)
+ throws CatalogResourceException;
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.parser;\r
-\r
-/**\r
- * enum data.\r
- * \r
- * @author 10189609\r
- * \r
- */\r
-public enum EnumPackageFormat {\r
- TOSCA_XML, TOSCA_YAML\r
-}\r
+/**
+ * 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.parser;
+
+/**
+ * enum data.
+ *
+ * @author 10189609
+ *
+ */
+public enum EnumPackageFormat {
+ TOSCA_XML, TOSCA_YAML
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.parser;\r
-\r
-public enum EnumTemplateType {\r
- NS, VNF\r
-}\r
+/**
+ * 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.parser;
+
+public enum EnumTemplateType {
+ NS, VNF
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.parser;\r
-\r
-import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-\r
-public class ModelParserFactory {\r
- private static final ModelParserFactory instance = new ModelParserFactory();\r
-\r
- public static ModelParserFactory getInstance() {\r
- return instance;\r
- }\r
-\r
- private Map<EnumPackageFormat, AbstractModelParser> pkgType2ParseMap =\r
- new HashMap<EnumPackageFormat, AbstractModelParser>();\r
-\r
- private ModelParserFactory() {\r
- // PackageParseMap.put(EnumPackageFormat.TOSCA_XML, new\r
- // ToscaXmlModelParser());\r
- pkgType2ParseMap.put(EnumPackageFormat.TOSCA_YAML, new ToscaYamlModelParser());\r
- }\r
-\r
- /**\r
- * parse package.\r
- * @param packageId package id\r
- * @param fileLocation package location\r
- * @param format package format\r
- * @return service template id \r
- * @throws CatalogResourceException e\r
- */\r
- public String parse(String packageId, String fileLocation, EnumPackageFormat format)\r
- throws CatalogResourceException {\r
- if (pkgType2ParseMap.get(format) == null) {\r
- throw new CatalogResourceException("Can't find its parser. package type = "\r
- + format.toString());\r
- }\r
-\r
- return pkgType2ParseMap.get(format).parse(packageId, fileLocation);\r
- }\r
-}\r
+/**
+ * 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.parser;
+
+import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
+
+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>();
+
+ private ModelParserFactory() {
+ // PackageParseMap.put(EnumPackageFormat.TOSCA_XML, new
+ // ToscaXmlModelParser());
+ pkgType2ParseMap.put(EnumPackageFormat.TOSCA_YAML, new ToscaYamlModelParser());
+ }
+
+ /**
+ * 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);
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.parser.yaml;\r
-\r
-import org.openo.commontosca.catalog.model.parser.yaml.entity.ParseYamlRequestParemeter;\r
-\r
-import javax.ws.rs.Consumes;\r
-import javax.ws.rs.POST;\r
-import javax.ws.rs.Path;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.core.MediaType;\r
-\r
-\r
-@Path("/parse")\r
-public interface IYamlParseRest {\r
-\r
- @POST\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- String parse(ParseYamlRequestParemeter request) throws Exception;\r
-}\r
+/**
+ * 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.parser.yaml;
+
+import org.openo.commontosca.catalog.model.parser.yaml.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;
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.parser.yaml;\r
-\r
-import com.google.gson.Gson;\r
-\r
-import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
-\r
-import org.glassfish.jersey.client.ClientConfig;\r
-import org.openo.commontosca.catalog.common.MsbUtil;\r
-import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
-import org.openo.commontosca.catalog.model.parser.yaml.entity.ParseYamlRequestParemeter;\r
-import org.openo.commontosca.catalog.model.parser.yaml.entity.ParseYamlResult;\r
-\r
-\r
-public class YamlParseServiceConsumer {\r
- /**\r
- * get service template by template id from container service.\r
- * \r
- * @param request parse yaml request\r
- * @return parase yaml result\r
- * @throws CatalogResourceException e\r
- */\r
- public static ParseYamlResult getServiceTemplates(final ParseYamlRequestParemeter request)\r
- throws CatalogResourceException {\r
- try {\r
- ClientConfig config = new ClientConfig();\r
- IYamlParseRest yamlParseProxy =\r
- ConsumerFactory.createConsumer(MsbUtil.getYamlParseBaseUrl(), config,\r
- IYamlParseRest.class);\r
- String jsonStr = yamlParseProxy.parse(request);\r
- return new Gson().fromJson(jsonStr, ParseYamlResult.class);\r
- } catch (Exception e1) {\r
- throw new CatalogResourceException("Call parser api failed.", e1);\r
- }\r
-\r
- }\r
-}\r
+/**
+ * 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.parser.yaml;
+
+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.entity.ParseYamlRequestParemeter;
+import org.openo.commontosca.catalog.model.parser.yaml.entity.ParseYamlResult;
+
+
+public class YamlParseServiceConsumer {
+ /**
+ * 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(final ParseYamlRequestParemeter request)
+ throws CatalogResourceException {
+ try {
+ ClientConfig config = new ClientConfig();
+ IYamlParseRest yamlParseProxy =
+ ConsumerFactory.createConsumer(MsbUtil.getYamlParseBaseUrl(), config,
+ IYamlParseRest.class);
+ String jsonStr = yamlParseProxy.parse(request);
+ return new Gson().fromJson(jsonStr, ParseYamlResult.class);
+ } catch (Exception e1) {
+ throw new CatalogResourceException("Call parser api failed.", e1);
+ }
+
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.parser.yaml.entity;\r
-\r
-\r
-public enum EnumYamlServiceTemplateInfo {\r
- ID {\r
- @Override\r
- public String getName() {\r
- return "id";\r
- }\r
- },\r
- VERSION {\r
- @Override\r
- public String getName() {\r
- return "version";\r
- }\r
- },\r
- PROVIDER {\r
- @Override\r
- public String getName() {\r
- return "vendor";\r
- }\r
- };\r
-\r
- public abstract String getName();\r
-}\r
+/**
+ * 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.parser.yaml.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();
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.parser.yaml.entity;\r
-\r
-import java.util.List;\r
-\r
-public class ParseYamlRequestParemeter {\r
- private String path = "E:\\NFVO\\130. yaml2xml\\0. tosca-parser\\sample\\ag-vnfd-floatingIp.zip";\r
-\r
- private List<Extension> extensionList;\r
-\r
- public String getPath() {\r
- return path;\r
- }\r
-\r
- public void setPath(String path) {\r
- this.path = path;\r
- }\r
-\r
- public List<Extension> getExtensionList() {\r
- return extensionList;\r
- }\r
-\r
- public void setExtensionList(List<Extension> extensionList) {\r
- this.extensionList = extensionList;\r
- }\r
-\r
- public Extension createExtension() {\r
- return new Extension();\r
- }\r
-\r
- public class Extension {\r
- private String name;\r
- private String value;\r
-\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public String getValue() {\r
- return value;\r
- }\r
-\r
- public void setValue(String value) {\r
- this.value = value;\r
- }\r
- }\r
-}\r
+/**
+ * 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.parser.yaml.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> extensionList;
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public List<Extension> getExtensionList() {
+ return extensionList;
+ }
+
+ public void setExtensionList(List<Extension> extensionList) {
+ this.extensionList = extensionList;
+ }
+
+ 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;
+ }
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.parser.yaml.entity;\r
-\r
-import com.google.gson.Gson;\r
-import com.google.gson.JsonArray;\r
-import com.google.gson.JsonElement;\r
-import com.google.gson.JsonObject;\r
-import com.google.gson.annotations.SerializedName;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Map.Entry;\r
-\r
-\r
-public class ParseYamlResult {\r
- private String toscaDefinitionsVersion;\r
- private String description;\r
- private JsonObject nodeTypes;\r
- private JsonObject capabilityTypes;\r
- private JsonObject relationshipTypes;\r
- private JsonObject policyTypes;\r
- private TopologyTemplate topologyTemplate;\r
- private Map<String, String> metadata;\r
- private JsonObject plans;\r
-\r
-\r
- public String getToscaDefinitionsVersion() {\r
- return toscaDefinitionsVersion;\r
- }\r
-\r
- public void setToscaDefinitionsVersion(String toscaDefinitionsVersion) {\r
- this.toscaDefinitionsVersion = toscaDefinitionsVersion;\r
- }\r
-\r
- public String getDescription() {\r
- return description;\r
- }\r
-\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
-\r
- public JsonObject getNodeTypes() {\r
- return nodeTypes;\r
- }\r
-\r
- public void setNodeTypes(JsonObject nodeTypes) {\r
- this.nodeTypes = nodeTypes;\r
- }\r
-\r
- public List<NodeType> getNodeTypeList() {\r
- return jsonObject2NodeTypes(nodeTypes);\r
- }\r
-\r
- private ArrayList<NodeType> jsonObject2NodeTypes(JsonObject nodeTypes) {\r
- ArrayList<NodeType> nodeTypeList = new ArrayList<NodeType>();\r
- Iterator<Entry<String, JsonElement>> iterator = nodeTypes.entrySet().iterator();\r
- while (iterator.hasNext()) {\r
- NodeType type = new NodeType();\r
- Entry<String, JsonElement> next = iterator.next();\r
- type.setType(next.getKey());\r
- type.setValue(new Gson().fromJson(next.getValue(), NodeType.NodeTypeValue.class));\r
- nodeTypeList.add(type);\r
- }\r
- return nodeTypeList;\r
- }\r
-\r
- public JsonObject getCapabilityTypes() {\r
- return capabilityTypes;\r
- }\r
-\r
- public void setCapabilityTypes(JsonObject capabilityTypes) {\r
- this.capabilityTypes = capabilityTypes;\r
- }\r
-\r
- public JsonObject getRelationshipTypes() {\r
- return relationshipTypes;\r
- }\r
-\r
- public void setRelationshipTypes(JsonObject relationshipTypes) {\r
- this.relationshipTypes = relationshipTypes;\r
- }\r
-\r
- public List<RelationshipType> getRelationshipTypeList() {\r
- return jsonObject2RelationshipTypes(relationshipTypes);\r
- }\r
-\r
- private ArrayList<RelationshipType> jsonObject2RelationshipTypes(JsonObject relationshipTypes) {\r
- ArrayList<RelationshipType> relationshipTypeList = new ArrayList<RelationshipType>();\r
- Iterator<Entry<String, JsonElement>> iterator = relationshipTypes.entrySet().iterator();\r
- while (iterator.hasNext()) {\r
- RelationshipType type = new RelationshipType();\r
- Entry<String, JsonElement> next = iterator.next();\r
- type.setType(next.getKey());\r
- type.setValue(new Gson().fromJson(next.getValue(), RelationshipType.RelationshipValue.class));\r
- relationshipTypeList.add(type);\r
- }\r
- return relationshipTypeList;\r
- }\r
-\r
- public JsonObject getPolicyTypes() {\r
- return policyTypes;\r
- }\r
-\r
- public void setPolicyTypes(JsonObject policyTypes) {\r
- this.policyTypes = policyTypes;\r
- }\r
-\r
- public TopologyTemplate getTopologyTemplate() {\r
- return topologyTemplate;\r
- }\r
-\r
- public void setTopologyTemplate(TopologyTemplate topologyTemplate) {\r
- this.topologyTemplate = topologyTemplate;\r
- }\r
-\r
- public Map<String, String> getMetadata() {\r
- return metadata;\r
- }\r
-\r
- public void setMetadata(Map<String, String> metadata) {\r
- this.metadata = metadata;\r
- }\r
-\r
- public JsonObject getPlans() {\r
- return plans;\r
- }\r
-\r
- public void setPlans(JsonObject plans) {\r
- this.plans = plans;\r
- }\r
-\r
- public List<Plan> getPlanList() {\r
- return jsonObject2PlanList(this.plans);\r
- }\r
-\r
- private List<Plan> jsonObject2PlanList(JsonObject plans) {\r
- if (plans == null) {\r
- return new ArrayList<>();\r
- }\r
- List<Plan> retList = new ArrayList<>();\r
- Iterator<Entry<String, JsonElement>> iterator = plans.entrySet().iterator();\r
- while (iterator.hasNext()) {\r
- Plan ret = new Plan();\r
- Entry<String, JsonElement> next = iterator.next();\r
- ret.setName(next.getKey());\r
- ret.setValue(new Gson().fromJson(next.getValue(), Plan.PlanValue.class));\r
- retList.add(ret);\r
- }\r
- return retList;\r
- }\r
-\r
- public class TopologyTemplate {\r
- private String description;\r
- private List<Input> inputs;\r
- private List<Output> outputs;\r
- private List<NodeTemplate> nodeTemplates;\r
- private SubstitutionMapping substitutionMappings;\r
-\r
- public String getDescription() {\r
- return description;\r
- }\r
-\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
-\r
- public List<Input> getInputs() {\r
- return inputs;\r
- }\r
-\r
- public void setInputs(List<Input> inputs) {\r
- this.inputs = inputs;\r
- }\r
-\r
- public List<Output> getOutputs() {\r
- return outputs;\r
- }\r
-\r
- public void setOutputs(List<Output> outputs) {\r
- this.outputs = outputs;\r
- }\r
-\r
- public List<NodeTemplate> getNodeTemplates() {\r
- return nodeTemplates;\r
- }\r
-\r
- public void setNodeTemplates(List<NodeTemplate> nodeTemplates) {\r
- this.nodeTemplates = nodeTemplates;\r
- }\r
-\r
- public SubstitutionMapping getSubstitutionMappings() {\r
- return substitutionMappings;\r
- }\r
-\r
- public void setSubstitutionMappings(SubstitutionMapping substitutionMappings) {\r
- this.substitutionMappings = substitutionMappings;\r
- }\r
-\r
- public class Input {\r
- private String name;\r
- private String type;\r
- private String description;\r
- private String defaultValue;\r
- private boolean required;\r
-\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public String getType() {\r
- return type;\r
- }\r
-\r
- public void setType(String type) {\r
- this.type = type;\r
- }\r
-\r
- public String getDescription() {\r
- return description;\r
- }\r
-\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
-\r
- public String getDefault() {\r
- return defaultValue;\r
- }\r
-\r
- public void setDefault(String defaultValue) {\r
- this.defaultValue = defaultValue;\r
- }\r
-\r
- public boolean isRequired() {\r
- return required;\r
- }\r
-\r
- public void setRequired(boolean required) {\r
- this.required = required;\r
- }\r
- }\r
-\r
- public class Output {\r
- private String name;\r
- private String description;\r
- private Object value;\r
-\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public String getDescription() {\r
- return description;\r
- }\r
-\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
-\r
- public Object getValue() {\r
- return value;\r
- }\r
-\r
- public void setValue(Object value) {\r
- this.value = value;\r
- }\r
- }\r
-\r
- public class NodeTemplate {\r
- private String name;\r
- private String nodeType;\r
- private JsonObject properties;\r
- private JsonObject[] requirements;\r
- private JsonObject capabilities;\r
- private List<Relationship> relationships;\r
-\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public String getNodeType() {\r
- return nodeType;\r
- }\r
-\r
- public void setNodeType(String nodeType) {\r
- this.nodeType = nodeType;\r
- }\r
-\r
- public JsonObject getProperties() {\r
- return properties;\r
- }\r
-\r
- public void setProperties(JsonObject properties) {\r
- this.properties = properties;\r
- }\r
-\r
- public Map<String, Object> getPropertyList() {\r
- return jsonObject2Properties(properties);\r
- }\r
-\r
- private Map<String, Object> jsonObject2Properties(JsonObject properties) {\r
- Map<String, Object> ret = new HashMap<>();\r
- Iterator<Entry<String, JsonElement>> iterator = properties.entrySet().iterator();\r
- while (iterator.hasNext()) {\r
- Entry<String, JsonElement> next = iterator.next();\r
- ret.put(next.getKey(), next.getValue().getAsString());\r
- }\r
- return ret;\r
- }\r
-\r
- public JsonObject[] getRequirements() {\r
- return requirements;\r
- }\r
-\r
- public void setRequirements(JsonObject[] requirements) {\r
- this.requirements = requirements;\r
- }\r
-\r
- public JsonObject getCapabilities() {\r
- return capabilities;\r
- }\r
-\r
- public void setCapabilities(JsonObject capabilities) {\r
- this.capabilities = capabilities;\r
- }\r
-\r
- public List<Relationship> getRelationships() {\r
- return relationships;\r
- }\r
-\r
- public void setRelationships(List<Relationship> relationships) {\r
- this.relationships = relationships;\r
- }\r
-\r
- /**\r
- * get scalable.\r
- * @return NodeTemplateScalable\r
- */\r
- public NodeTemplateScalable getScalable() {\r
- if (capabilities == null) {\r
- return null;\r
- }\r
- JsonElement scaleableJson = capabilities.get("scalable");\r
- if (scaleableJson == null || !scaleableJson.isJsonObject()) {\r
- return null;\r
- }\r
- JsonElement propertyJson = scaleableJson.getAsJsonObject().get("properties");\r
- if (propertyJson == null || !propertyJson.isJsonObject()) {\r
- return null;\r
- }\r
-\r
- NodeTemplateScalable scalable = new NodeTemplateScalable();\r
- scalable\r
- .setMin_instances(propertyJson.getAsJsonObject().get("min_instances").getAsString());\r
- scalable\r
- .setMax_instances(propertyJson.getAsJsonObject().get("max_instances").getAsString());\r
- scalable.setDefault_instances(\r
- propertyJson.getAsJsonObject().get("default_instances").getAsString());\r
- return scalable;\r
- }\r
-\r
- public class Relationship {\r
- private String targetNodeName;\r
- private String type;\r
- private String sourceNodeName;\r
-\r
- public String getTargetNodeName() {\r
- return targetNodeName;\r
- }\r
-\r
- public void setTargetNodeName(String targetNodeName) {\r
- this.targetNodeName = targetNodeName;\r
- }\r
-\r
- public String getType() {\r
- return type;\r
- }\r
-\r
- public void setType(String type) {\r
- this.type = type;\r
- }\r
-\r
- public String getSourceNodeName() {\r
- return sourceNodeName;\r
- }\r
-\r
- public void setSourceNodeName(String sourceNodeName) {\r
- this.sourceNodeName = sourceNodeName;\r
- }\r
- }\r
-\r
- public class NodeTemplateScalable {\r
- private String minInstances;\r
- private String maxInstances;\r
- private String defaultInstances;\r
-\r
- public String getMin_instances() {\r
- return minInstances;\r
- }\r
-\r
- public void setMin_instances(String minInstances) {\r
- this.minInstances = minInstances;\r
- }\r
-\r
- public String getMax_instances() {\r
- return maxInstances;\r
- }\r
-\r
- public void setMax_instances(String maxInstances) {\r
- this.maxInstances = maxInstances;\r
- }\r
-\r
- public String getDefault_instances() {\r
- return defaultInstances;\r
- }\r
-\r
- public void setDefault_instances(String defaultInstances) {\r
- this.defaultInstances = defaultInstances;\r
- }\r
- }\r
- }\r
-\r
- public class SubstitutionMapping {\r
- private String nodeType;\r
- private JsonObject requirements;\r
- private JsonObject capabilities;\r
- private JsonObject properties;\r
-\r
- public String getNodeType() {\r
- return nodeType;\r
- }\r
-\r
- public void setNodeType(String nodeType) {\r
- this.nodeType = nodeType;\r
- }\r
-\r
- public JsonObject getRequirements() {\r
- return requirements;\r
- }\r
-\r
- public void setRequirements(JsonObject requirements) {\r
- this.requirements = requirements;\r
- }\r
-\r
- public Map<String, String[]> getRequirementList() {\r
- return jsonObjects2Requirements(this.requirements);\r
- }\r
-\r
- private Map<String, String[]> jsonObjects2Requirements(JsonObject requirements) {\r
- Map<String, String[]> ret = new HashMap<String, String[]>();\r
-\r
- Iterator<Entry<String, JsonElement>> iterator = requirements.entrySet().iterator();\r
- while (iterator.hasNext()) {\r
- Entry<String, JsonElement> next = iterator.next();\r
- if (next.getValue().isJsonPrimitive() || next.getValue().isJsonObject()) {\r
- ret.put(next.getKey(), new String[] {next.getValue().getAsString()});\r
- continue;\r
- }\r
-\r
- if (next.getValue().isJsonArray()) {\r
- String[] value = parseListValue((JsonArray) next.getValue());\r
- ret.put(next.getKey(), value);\r
- }\r
- }\r
-\r
- return ret;\r
- }\r
-\r
- private String[] parseListValue(JsonArray jsonArray) {\r
- String[] value = new String[jsonArray.size()];\r
- for (int i = 0, size = jsonArray.size(); i < size; i++) {\r
- value[i] = jsonArray.get(i).getAsString();\r
- }\r
- return value;\r
- }\r
-\r
- public JsonObject getCapabilities() {\r
- return capabilities;\r
- }\r
-\r
- public void setCapabilities(JsonObject capabilities) {\r
- this.capabilities = capabilities;\r
- }\r
-\r
- public Map<String, String[]> getCapabilityList() {\r
- return jsonObject2Capabilities(this.capabilities);\r
- }\r
-\r
- private Map<String, String[]> jsonObject2Capabilities(JsonObject capabilities) {\r
- Map<String, String[]> ret = new HashMap<String, String[]>();\r
-\r
- Iterator<Entry<String, JsonElement>> iterator = capabilities.entrySet().iterator();\r
- while (iterator.hasNext()) {\r
- Entry<String, JsonElement> next = iterator.next();\r
-\r
- if (next.getValue().isJsonPrimitive() || next.getValue().isJsonObject()) {\r
- ret.put(next.getKey(), new String[] {next.getValue().getAsString()});\r
- continue;\r
- }\r
-\r
- if (next.getValue().isJsonArray()) {\r
- String[] value = parseListValue((JsonArray) next.getValue());\r
- ret.put(next.getKey(), value);\r
- }\r
- }\r
-\r
- return ret;\r
- }\r
-\r
- public JsonObject getProperties() {\r
- return properties;\r
- }\r
-\r
- public void setProperties(JsonObject properties) {\r
- this.properties = properties;\r
- }\r
-\r
- public Map<String, Object> getPropertyList() {\r
- return jsonObject2Properties(properties);\r
- }\r
-\r
- private Map<String, Object> jsonObject2Properties(JsonObject properties) {\r
- Map<String, Object> ret = new HashMap<>();\r
- Iterator<Entry<String, JsonElement>> iterator = properties.entrySet().iterator();\r
- while (iterator.hasNext()) {\r
- Entry<String, JsonElement> next = iterator.next();\r
- ret.put(next.getKey(), next.getValue().getAsString());\r
- }\r
- return ret;\r
- }\r
- }\r
- }\r
-\r
-\r
- public class RelationshipType {\r
- private String type;\r
- private RelationshipValue value;\r
-\r
- public String getType() {\r
- return type;\r
- }\r
-\r
- public void setType(String type) {\r
- this.type = type;\r
- }\r
-\r
- public RelationshipValue getValue() {\r
- return value;\r
- }\r
-\r
- public void setValue(RelationshipValue value) {\r
- this.value = value;\r
- }\r
-\r
- public class RelationshipValue {\r
- private String derivedFrom;\r
- private String[] validTargetTypes;\r
-\r
- public String getDerivedFrom() {\r
- return derivedFrom;\r
- }\r
-\r
- public void setDerivedFrom(String derivedFrom) {\r
- this.derivedFrom = derivedFrom;\r
- }\r
-\r
- public String[] getValid_target_types() {\r
- return validTargetTypes;\r
- }\r
-\r
- public void setValid_target_types(String[] validTargetTypes) {\r
- this.validTargetTypes = validTargetTypes;\r
- }\r
- }\r
- }\r
-\r
-\r
- public class NodeType {\r
- private String type;\r
- private NodeTypeValue value;\r
-\r
- public String getType() {\r
- return type;\r
- }\r
-\r
- public void setType(String type) {\r
- this.type = type;\r
- }\r
-\r
- public NodeTypeValue getValue() {\r
- return value;\r
- }\r
-\r
- public void setValue(NodeTypeValue value) {\r
- this.value = value;\r
- }\r
-\r
- public class NodeTypeValue {\r
- private String derivedFrom;\r
- private JsonObject properties;\r
- private JsonObject[] requirements;\r
- private JsonObject capabilities;\r
-\r
- public String getDerivedFrom() {\r
- return derivedFrom;\r
- }\r
-\r
- public void setDerived_from(String derivedFrom) {\r
- this.derivedFrom = derivedFrom;\r
- }\r
-\r
- public JsonObject getProperties() {\r
- return properties;\r
- }\r
-\r
- public void setProperties(JsonObject properties) {\r
- this.properties = properties;\r
- }\r
-\r
- public List<NodeTypeProperty> getPropertyList() {\r
- return jsonObject2Properties(properties);\r
- }\r
-\r
- private List<NodeTypeProperty> jsonObject2Properties(JsonObject properties) {\r
- List<NodeTypeProperty> propertieList = new ArrayList<NodeTypeProperty>();\r
- Iterator<Entry<String, JsonElement>> iterator = properties.entrySet().iterator();\r
- while (iterator.hasNext()) {\r
- NodeTypeProperty type = new NodeTypeProperty();\r
- Entry<String, JsonElement> next = iterator.next();\r
- type.setKey(next.getKey());\r
- type.setValue(new Gson().fromJson(next.getValue(), JsonObject.class));\r
- propertieList.add(type);\r
- }\r
- return propertieList;\r
- }\r
-\r
- public class NodeTypeProperty {\r
- private String key;\r
- private JsonObject value;\r
-\r
- public String getKey() {\r
- return key;\r
- }\r
-\r
- public void setKey(String key) {\r
- this.key = key;\r
- }\r
-\r
- /**\r
- * get default value.\r
- * @return default value\r
- */\r
- public String getDefaultValue() {\r
- JsonElement defaultValue = value.get("default");\r
- if (defaultValue == null || defaultValue.isJsonObject()) {\r
- return "";\r
- }\r
-\r
- return defaultValue.getAsString();\r
- }\r
-\r
- public JsonObject getValue() {\r
- return value;\r
- }\r
-\r
- public void setValue(JsonObject value) {\r
- this.value = value;\r
- }\r
- }\r
-\r
- public JsonObject[] getRequirements() {\r
- return requirements;\r
- }\r
-\r
- public void setRequirements(JsonObject[] requirements) {\r
- this.requirements = requirements;\r
- }\r
-\r
- public JsonObject getCapabilities() {\r
- return capabilities;\r
- }\r
-\r
- public void setCapabilities(JsonObject capabilities) {\r
- this.capabilities = capabilities;\r
- }\r
- }\r
- }\r
-\r
- public class Plan {\r
- private String name;\r
- private PlanValue value;\r
-\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public String getDescription() {\r
- return value.getDescription();\r
- }\r
-\r
- public String getReference() {\r
- return value.getReference();\r
- }\r
-\r
- public String getPlanLanguage() {\r
- return value.getPlanLanguage();\r
- }\r
-\r
- public List<PlanValue.PlanInput> getInputList() {\r
- return value.getInputList();\r
- }\r
-\r
- public PlanValue getValue() {\r
- return value;\r
- }\r
-\r
- public void setValue(PlanValue value) {\r
- this.value = value;\r
- }\r
-\r
- public class PlanValue {\r
- private String description;\r
- private String reference;\r
- private String planLanguage;\r
- private JsonObject inputs;\r
-\r
- public String getDescription() {\r
- return description;\r
- }\r
-\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
-\r
- public String getReference() {\r
- return reference;\r
- }\r
-\r
- public void setReference(String reference) {\r
- this.reference = reference;\r
- }\r
-\r
- public String getPlanLanguage() {\r
- return planLanguage;\r
- }\r
-\r
- public void setPlanLanguage(String planLanguage) {\r
- this.planLanguage = planLanguage;\r
- }\r
-\r
- public JsonObject getInputs() {\r
- return inputs;\r
- }\r
-\r
- public void setInputs(JsonObject inputs) {\r
- this.inputs = inputs;\r
- }\r
-\r
- public List<PlanInput> getInputList() {\r
- return jsonObject2PlanInputList(inputs);\r
-\r
- }\r
-\r
- private List<PlanInput> jsonObject2PlanInputList(JsonObject inputs) {\r
- List<PlanInput> retList = new ArrayList<PlanInput>();\r
- Iterator<Entry<String, JsonElement>> iterator = inputs.entrySet().iterator();\r
- while (iterator.hasNext()) {\r
- PlanInput ret = new PlanInput();\r
- Entry<String, JsonElement> next = iterator.next();\r
- ret.setName(next.getKey());\r
- ret.setValue(new Gson().fromJson(next.getValue(), PlanInput.PlanInputValue.class));\r
- retList.add(ret);\r
- }\r
- return retList;\r
- }\r
-\r
- public class PlanInput {\r
- private String name;\r
- private PlanInputValue value;\r
-\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public String getType() {\r
- return value.getType();\r
- }\r
-\r
- public String getDescription() {\r
- return value.getDescription();\r
- }\r
-\r
- public String getDefault() {\r
- return value.getDefaultValue();\r
- }\r
-\r
- public boolean isRequired() {\r
- return value.isRequired();\r
- }\r
-\r
- public PlanInputValue getValue() {\r
- return value;\r
- }\r
-\r
- public void setValue(PlanInputValue value) {\r
- this.value = value;\r
- }\r
-\r
- public class PlanInputValue {\r
- private String type;\r
- private String description;\r
- @SerializedName("default")\r
- private String defaultValue;\r
- private boolean required;\r
-\r
- public String getType() {\r
- return type;\r
- }\r
-\r
- public void setType(String type) {\r
- this.type = type;\r
- }\r
-\r
- public String getDescription() {\r
- return description;\r
- }\r
-\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
-\r
- public String getDefaultValue() {\r
- return defaultValue;\r
- }\r
-\r
- public void setDefaultValue(String defaultValue) {\r
- this.defaultValue = defaultValue;\r
- }\r
-\r
- public boolean isRequired() {\r
- return required;\r
- }\r
-\r
- public void setRequired(boolean required) {\r
- this.required = required;\r
- }\r
- }\r
- }\r
- }\r
- }\r
-}\r
+/**
+ * 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.parser.yaml.entity;
+
+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;
+
+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;
+
+
+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;
+
+
+ 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() {
+ 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(), next.getValue().getAsString());
+ }
+ 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(propertyJson.getAsJsonObject().get("min_instances").getAsString());
+ scalable
+ .setMax_instances(propertyJson.getAsJsonObject().get("max_instances").getAsString());
+ scalable.setDefault_instances(
+ propertyJson.getAsJsonObject().get("default_instances").getAsString());
+ 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 nodeType;
+ private JsonObject requirements;
+ private JsonObject capabilities;
+ private JsonObject properties;
+
+ public String getNodeType() {
+ return nodeType;
+ }
+
+ public void setNodeType(String nodeType) {
+ this.nodeType = nodeType;
+ }
+
+ 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) {
+ 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[] {next.getValue().getAsString()});
+ 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] = jsonArray.get(i).getAsString();
+ }
+ 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) {
+ 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[] {next.getValue().getAsString()});
+ continue;
+ }
+
+ if (next.getValue().isJsonArray()) {
+ String[] value = parseListValue((JsonArray) next.getValue());
+ ret.put(next.getKey(), value);
+ }
+ }
+
+ return ret;
+ }
+
+ 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(), next.getValue().getAsString());
+ }
+ 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 defaultValue.getAsString();
+ }
+
+ 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;
+ }
+ }
+ }
+ }
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.plan.wso2;\r
-\r
-import org.openo.commontosca.catalog.model.plan.wso2.entity.DeletePackageResponse;\r
-import org.openo.commontosca.catalog.model.plan.wso2.entity.StartProcessRequest;\r
-import org.openo.commontosca.catalog.model.plan.wso2.entity.StartProcessResponse;\r
-\r
-import javax.ws.rs.Consumes;\r
-import javax.ws.rs.DELETE;\r
-import javax.ws.rs.POST;\r
-import javax.ws.rs.Path;\r
-import javax.ws.rs.PathParam;\r
-import javax.ws.rs.Produces;\r
-import javax.ws.rs.core.MediaType;\r
-\r
-@Path("/openoapi/wso2bpel/v1")\r
-public interface Iwso2RestService {\r
- // /**\r
- // * @param request\r
- // * @return\r
- // * @throws Exception\r
- // */\r
- // @Path("/package")\r
- // @POST\r
- // @Consumes(MediaType.APPLICATION_JSON)\r
- // @Produces(MediaType.APPLICATION_JSON)\r
- // DeployPackageResponse deployPackage(FormDataMultiPart request) throws Exception;\r
-\r
- @Path("/package/{packageName}")\r
- @DELETE\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- DeletePackageResponse deletePackage(\r
- @PathParam("packageName") String packageName) throws Exception;\r
-\r
- @Path("process/instance")\r
- @POST\r
- @Consumes(MediaType.APPLICATION_JSON)\r
- @Produces(MediaType.APPLICATION_JSON)\r
- StartProcessResponse startProcess(StartProcessRequest request)\r
- throws Exception;\r
-}\r
+/**
+ * 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.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;
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.plan.wso2;\r
-\r
-import com.google.gson.Gson;\r
-\r
-import com.eclipsesource.jaxrs.consumer.ConsumerFactory;\r
-\r
-import org.apache.http.HttpEntity;\r
-import org.apache.http.entity.ContentType;\r
-import org.apache.http.entity.mime.MultipartEntityBuilder;\r
-import org.glassfish.jersey.client.ClientConfig;\r
-import org.openo.commontosca.catalog.common.Config;\r
-import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
-import org.openo.commontosca.catalog.model.plan.wso2.entity.DeletePackageResponse;\r
-import org.openo.commontosca.catalog.model.plan.wso2.entity.DeployPackageResponse;\r
-import org.openo.commontosca.catalog.model.plan.wso2.entity.StartProcessRequest;\r
-import org.openo.commontosca.catalog.model.plan.wso2.entity.StartProcessResponse;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.io.BufferedInputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.util.Map;\r
-import java.util.zip.ZipEntry;\r
-import java.util.zip.ZipFile;\r
-import java.util.zip.ZipInputStream;\r
-\r
-\r
-\r
-public class Wso2ServiceConsumer {\r
- public static final String WSO2_APP_URL = "/openoapi/wso2bpel/v1/package";\r
- private static final Logger LOGGER = LoggerFactory.getLogger(Wso2ServiceConsumer.class);\r
- \r
- /**\r
- * deploy package.\r
- * @param zipFileLocation zip file location\r
- * @param planFilePath plan file path\r
- * @return DeployPackageResponse\r
- * @throws CatalogResourceException e1\r
- */\r
- public static DeployPackageResponse deployPackage(String zipFileLocation, String planFilePath)\r
- throws CatalogResourceException {\r
- InputStream ins = null;\r
- try {\r
- ins = getInputStream(zipFileLocation, planFilePath);\r
- RestResponse res = RestfulClient.post(Config.getConfigration().getWso2HostIp(),\r
- Integer.parseInt(Config.getConfigration().getWso2HostPort()), WSO2_APP_URL,\r
- buildRequest(ins, planFilePath));\r
-\r
- if (res.getStatusCode() == null || res.getResult() == null) {\r
- throw new CatalogResourceException(\r
- "Deploy Package return null. Response = " + res);\r
- }\r
- \r
- if (200 == res.getStatusCode() || 201 == res.getStatusCode()) {\r
- DeployPackageResponse response =\r
- new Gson().fromJson(res.getResult(), DeployPackageResponse.class);\r
- if (response.isSuccess()) {\r
- return response;\r
- }\r
- }\r
-\r
- throw new CatalogResourceException(\r
- "Deploy Package return fail. Response = " + res.getResult());\r
- } catch (FileNotFoundException e1) {\r
- throw new CatalogResourceException("Deploy Package failed.", e1);\r
- } finally {\r
- if (ins != null) {\r
- try {\r
- ins.close();\r
- } catch (IOException e1) {\r
- LOGGER.error("inputStream close failed !");\r
- }\r
- }\r
- }\r
- }\r
-\r
- private static HttpEntity buildRequest(InputStream inputStream, String filePath)\r
- throws FileNotFoundException {\r
- MultipartEntityBuilder builder = MultipartEntityBuilder.create();\r
- builder.seContentType(ContentType.MULTIPART_FORM_DATA);\r
- builder.addBinaryBody("file", inputStream, ContentType.APPLICATION_OCTET_STREAM,\r
- new File(filePath).getName());\r
- return builder.build();\r
- }\r
-\r
- @SuppressWarnings("resource")\r
- private static InputStream getInputStream(String zipFileLocation, String planFilePath)\r
- throws CatalogResourceException {\r
- ZipInputStream zin = null;\r
- try {\r
- InputStream in = new BufferedInputStream(new FileInputStream(zipFileLocation));\r
- zin = new ZipInputStream(in);\r
- ZipEntry ze;\r
- while ((ze = zin.getNextEntry()) != null) {\r
- if (planFilePath.equals(ze.getName())) {\r
- ZipFile zf = new ZipFile(zipFileLocation);\r
- return zf.getInputStream(ze);\r
- }\r
- }\r
- } catch (IOException e1) {\r
- throw new CatalogResourceException("Get InputStream failed. planFilePath = " + planFilePath,\r
- e1);\r
- } finally {\r
- closeStream(zin);\r
- }\r
-\r
- throw new CatalogResourceException("Get InputStream failed. planFilePath = " + planFilePath);\r
- }\r
-\r
- private static void closeStream(ZipInputStream zin) {\r
-\r
- if (zin != null) {\r
- try {\r
- zin.closeEntry();\r
- } catch (IOException e1) {\r
- LOGGER.error("zip inputStream close failed !");\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * delet package.\r
- * @param packageName package to delete according packageName\r
- * @return DeletePackageResponse\r
- * @throws CatalogResourceException e1\r
- */\r
- public static DeletePackageResponse deletePackage(String packageName)\r
- throws CatalogResourceException {\r
- try {\r
- ClientConfig config = new ClientConfig();\r
- Iwso2RestService wso2Proxy = ConsumerFactory.createConsumer(\r
- Config.getConfigration().getWso2BaseUrl(), config, Iwso2RestService.class);\r
- DeletePackageResponse response = wso2Proxy.deletePackage(packageName);\r
- if (response.isSuccess()) {\r
- return response;\r
- }\r
- throw new CatalogResourceException(response.getException());\r
- } catch (Exception e1) {\r
- throw new CatalogResourceException(\r
- "Call Delete Package api failed. packageName = " + packageName, e1);\r
- }\r
- }\r
-\r
-\r
- /**\r
- * start process.\r
- * @param processId process id\r
- * @param params params\r
- * @return StartProcessResponse\r
- * @throws CatalogResourceException e1\r
- */\r
- public static StartProcessResponse startProcess(String processId, Map<String, Object> params)\r
- throws CatalogResourceException {\r
- try {\r
- ClientConfig config = new ClientConfig();\r
- Iwso2RestService wso2Proxy = ConsumerFactory.createConsumer(\r
- Config.getConfigration().getWso2BaseUrl(), config, Iwso2RestService.class);\r
- StartProcessResponse response =\r
- wso2Proxy.startProcess(new StartProcessRequest(processId, params));\r
- if (response.isSuccess()) {\r
- return response;\r
- }\r
- throw new CatalogResourceException(response.getException());\r
- } catch (Exception e1) {\r
- throw new CatalogResourceException("Call Start Process api failed.", e1);\r
- }\r
- }\r
-\r
-}\r
+/**
+ * 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.plan.wso2;
+
+import com.google.gson.Gson;
+
+import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
+
+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.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 java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
+
+
+
+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 {
+ InputStream ins = null;
+ try {
+ ins = getInputStream(zipFileLocation, planFilePath);
+ RestResponse res = RestfulClient.post(Config.getConfigration().getWso2HostIp(),
+ Integer.parseInt(Config.getConfigration().getWso2HostPort()), 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 fail. Response = " + res.getResult());
+ } catch (FileNotFoundException e1) {
+ throw new CatalogResourceException("Deploy Package failed.", e1);
+ } finally {
+ if (ins != null) {
+ try {
+ ins.close();
+ } catch (IOException e1) {
+ LOGGER.error("inputStream close failed !");
+ }
+ }
+ }
+ }
+
+ 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();
+ }
+
+ @SuppressWarnings("resource")
+ private static InputStream getInputStream(String zipFileLocation, String planFilePath)
+ throws CatalogResourceException {
+ ZipInputStream zin = null;
+ try {
+ InputStream in = new BufferedInputStream(new FileInputStream(zipFileLocation));
+ zin = new ZipInputStream(in);
+ ZipEntry ze;
+ while ((ze = zin.getNextEntry()) != null) {
+ if (planFilePath.equals(ze.getName())) {
+ ZipFile zf = new ZipFile(zipFileLocation);
+ return zf.getInputStream(ze);
+ }
+ }
+ } catch (IOException e1) {
+ throw new CatalogResourceException("Get InputStream failed. planFilePath = " + planFilePath,
+ e1);
+ } finally {
+ closeStream(zin);
+ }
+
+ throw new CatalogResourceException("Get InputStream failed. planFilePath = " + planFilePath);
+ }
+
+ private static void closeStream(ZipInputStream zin) {
+
+ if (zin != null) {
+ try {
+ zin.closeEntry();
+ } catch (IOException e1) {
+ LOGGER.error("zip inputStream close failed !");
+ }
+ }
+ }
+
+ /**
+ * 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().getWso2BaseUrl(), config, Iwso2RestService.class);
+ DeletePackageResponse response = wso2Proxy.deletePackage(packageName);
+ if (response.isSuccess()) {
+ return response;
+ }
+ throw new CatalogResourceException(response.getException());
+ } catch (Exception e1) {
+ throw new CatalogResourceException(
+ "Call Delete Package api failed. packageName = " + packageName, e1);
+ }
+ }
+
+
+ /**
+ * 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().getWso2BaseUrl(), config, Iwso2RestService.class);
+ StartProcessResponse response =
+ wso2Proxy.startProcess(new StartProcessRequest(processId, params));
+ if (response.isSuccess()) {
+ return response;
+ }
+ throw new CatalogResourceException(response.getException());
+ } catch (Exception e1) {
+ throw new CatalogResourceException("Call Start Process api failed.", e1);
+ }
+ }
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.model.wrapper;\r
-\r
-import org.openo.commontosca.catalog.common.ToolUtil;\r
-import org.openo.commontosca.catalog.db.entity.NodeTemplateData;\r
-import org.openo.commontosca.catalog.db.entity.PackageData;\r
-import org.openo.commontosca.catalog.db.entity.ServiceTemplateData;\r
-import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData;\r
-import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
-import org.openo.commontosca.catalog.db.resource.TemplateManager;\r
-import org.openo.commontosca.catalog.model.common.TemplateDataHelper;\r
-import org.openo.commontosca.catalog.model.entity.InputParameter;\r
-import org.openo.commontosca.catalog.model.entity.NfvTemplate;\r
-import org.openo.commontosca.catalog.model.entity.NodeTemplate;\r
-import org.openo.commontosca.catalog.model.entity.Parameters;\r
-import org.openo.commontosca.catalog.model.entity.QueryRawDataCondition;\r
-import org.openo.commontosca.catalog.model.entity.ServiceTemplate;\r
-import org.openo.commontosca.catalog.model.entity.ServiceTemplateOperation;\r
-import org.openo.commontosca.catalog.model.entity.ServiceTemplateRawData;\r
-import org.openo.commontosca.catalog.model.entity.SubstitutionMapping;\r
-import org.openo.commontosca.catalog.resources.CatalogBadRequestException;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.List;\r
-\r
-\r
-public class ServiceTemplateWrapper {\r
- private static ServiceTemplateWrapper instance;\r
- private static final Logger logger = LoggerFactory.getLogger(ServiceTemplateWrapper.class);\r
-\r
- /**\r
- * get service template wrapper instance.\r
- * @return ServiceTemplateWrapper instance\r
- */\r
- public static ServiceTemplateWrapper getInstance() {\r
- if (instance == null) {\r
- instance = new ServiceTemplateWrapper();\r
- }\r
- return instance;\r
- }\r
-\r
- /**\r
- * get service template by id.\r
- * @param serviceTemplateId service template id\r
- * @return service template\r
- * @throws CatalogResourceException e1\r
- */\r
- public ServiceTemplate getServiceTemplateById(String serviceTemplateId)\r
- throws CatalogResourceException {\r
- logger.info("getServiceTemplateById. serviceTemplateId = " + serviceTemplateId);\r
-\r
- List<ServiceTemplateData> stdList =\r
- TemplateManager.getInstance().queryServiceTemplateById(serviceTemplateId);\r
- if (stdList == null || stdList.isEmpty()) {\r
- throw new CatalogResourceException("Can't find this servcie template");\r
- }\r
-\r
- return TemplateDataHelper.convert2ServiceTemplate(stdList.get(0));\r
- }\r
-\r
-\r
- /**\r
- * get service templates.\r
- * @param status usage status\r
- * @param deletionPending package's deletionPending\r
- * @return service template list\r
- * @throws CatalogResourceException e\r
- */\r
- public ServiceTemplate[] getServiceTemplates(String status, boolean deletionPending)\r
- throws CatalogResourceException {\r
- PackageData pd = new PackageData();\r
- pd.setUsageState(status);\r
- pd.setDeletionPending(String.valueOf(deletionPending));\r
-\r
- List<ServiceTemplateData> stdList =\r
- TemplateManager.getInstance().queryServiceTemplateByCsarPackageInfo(pd);\r
-\r
- return TemplateDataHelper.convert2ServiceTemplates(stdList);\r
- }\r
-\r
-\r
- /**\r
- * get nesting service template.\r
- * @param nodeTypeIds nodeType id list\r
- * @return service template list\r
- * @throws CatalogResourceException e\r
- */\r
- public ServiceTemplate[] getNestingServiceTemplate(String[] nodeTypeIds)\r
- throws CatalogResourceException {\r
- ServiceTemplate[] sts = new ServiceTemplate[nodeTypeIds.length];\r
- for (int i = 0; i < nodeTypeIds.length; i++) {\r
- SubstitutionMapping stm = getSubstitutionMappingsByNodeTypeId(nodeTypeIds[i]);\r
- if (stm == null) {\r
- sts[i] = null;\r
- } else {\r
- sts[i] = getServiceTemplateById(stm.getServiceTemplateId());\r
- }\r
- }\r
-\r
- return sts;\r
- }\r
-\r
- /**\r
- * get substitution mappings by nodeTpe id.\r
- * @param nodeTypeId nodeType id\r
- * @return SubstitutionMapping\r
- * @throws CatalogResourceException e\r
- */\r
- private SubstitutionMapping getSubstitutionMappingsByNodeTypeId(String nodeTypeId)\r
- throws CatalogResourceException {\r
- List<ServiceTemplateMappingData> stmDataList =\r
- TemplateManager.getInstance().queryServiceTemplateMapping(nodeTypeId, null);\r
- if (stmDataList == null || stmDataList.isEmpty()) {\r
- return null;\r
- }\r
-\r
- return TemplateDataHelper.convert2SubstitutionMapping(stmDataList.get(0));\r
- }\r
-\r
-\r
- /**\r
- * get service template raw data.\r
- * @param queryCondition query raw data condition\r
- * @return ServiceTemplateRawData\r
- * @throws CatalogResourceException e1\r
- * @throws CatalogBadRequestException e2\r
- */\r
- public ServiceTemplateRawData getServiceTemplateRawData(QueryRawDataCondition queryCondition)\r
- throws CatalogResourceException, CatalogBadRequestException {\r
- ServiceTemplateData std = getServiceTemplateDataByCsarId(queryCondition.getCsarId());\r
- return new ServiceTemplateRawData(std.getRowData());\r
- }\r
-\r
- /**\r
- * get service template data by package id.\r
- * @param csarId package id\r
- * @return ServiceTemplateData\r
- * @throws CatalogBadRequestException e1\r
- * @throws CatalogResourceException e2\r
- */\r
- private ServiceTemplateData getServiceTemplateDataByCsarId(String csarId)\r
- throws CatalogBadRequestException, CatalogResourceException {\r
- if (ToolUtil.isTrimedEmptyString(csarId)) {\r
- throw new CatalogBadRequestException("CsarId is null.");\r
- }\r
- PackageData pd = new PackageData();\r
- pd.setCsarId(csarId);\r
-\r
- List<ServiceTemplateData> stdList =\r
- TemplateManager.getInstance().queryServiceTemplateByCsarPackageInfo(pd);\r
-\r
- if (stdList == null || stdList.isEmpty()) {\r
- throw new CatalogResourceException("Can't find this servcie template");\r
- }\r
-\r
- return stdList.get(0);\r
- }\r
-\r
- /**\r
- * get service template by package id.\r
- * @param packageId package id\r
- * @return service template data\r
- * @throws CatalogBadRequestException e1\r
- * @throws CatalogResourceException e2\r
- */\r
- public ServiceTemplate getServiceTemplateByCsarId(String packageId)\r
- throws CatalogBadRequestException, CatalogResourceException {\r
- ServiceTemplateData std = getServiceTemplateDataByCsarId(packageId);\r
- ServiceTemplate st = TemplateDataHelper.convert2ServiceTemplate(std);\r
- return st;\r
- }\r
-\r
- /**\r
- * get service template parameters.\r
- * @param serviceTemplateId service template id\r
- * @return service template parameters\r
- * @throws CatalogResourceException e\r
- */\r
- public Parameters getServiceTemplateParameters(String serviceTemplateId)\r
- throws CatalogResourceException {\r
- ServiceTemplate st = getServiceTemplateById(serviceTemplateId);\r
- return new Parameters(st.getInputs(), st.getOutputs());\r
- }\r
-\r
- /**\r
- * get template operation.\r
- * @param serviceTemplateId service template id\r
- * @return service template operations\r
- */\r
- public ServiceTemplateOperation[] getTemplateOperations(String serviceTemplateId)\r
- throws CatalogResourceException {\r
- ServiceTemplate st = getServiceTemplateById(serviceTemplateId);\r
-\r
- if (st.getOperations() == null) {\r
- return new ServiceTemplateOperation[0];\r
- }\r
- return st.getOperations();\r
- }\r
-\r
- /**\r
- * get parameters by operation name.\r
- * @param serviceTemplateId service template id\r
- * @param operationName operation name\r
- * @return InputParameter list\r
- * @throws CatalogResourceException e\r
- */\r
- public InputParameter[] getParametersByOperationName(String serviceTemplateId,\r
- String operationName) throws CatalogResourceException {\r
- if (ToolUtil.isTrimedEmptyString(operationName)) {\r
- throw new CatalogResourceException("Operation Name is null.");\r
- }\r
-\r
- ServiceTemplateOperation[] operations = getTemplateOperations(serviceTemplateId);\r
- for (int i = 0; i < operations.length; i++) {\r
- if (operationName.equals(operations[i].getName())) {\r
- return operations[i].getInputs();\r
- }\r
- }\r
-\r
- throw new CatalogResourceException("Can't find this operation.");\r
- }\r
-\r
-\r
- /**\r
- * get nodeTemplate by id.\r
- * @param serviceTemplateId service template id\r
- * @param nodeTemplateId node template id\r
- * @return NodeTemplate\r
- * @throws CatalogResourceException e1\r
- */\r
- public NodeTemplate getNodeTemplateById(String serviceTemplateId, String nodeTemplateId)\r
- throws CatalogResourceException {\r
- List<NodeTemplateData> ntdList =\r
- TemplateManager.getInstance().queryNodeTemplateById(serviceTemplateId, nodeTemplateId);\r
-\r
- if (ntdList == null || ntdList.isEmpty()) {\r
- throw new CatalogResourceException("Can't find this node template.");\r
- }\r
-\r
- return TemplateDataHelper.convert2NodeTemplate(ntdList.get(0));\r
- }\r
-\r
- /**\r
- * get node templates.\r
- * @param serviceTemplateId service template id\r
- * @param types type list\r
- * @return NodeTemplate list\r
- * @throws CatalogResourceException e\r
- */\r
- public NodeTemplate[] getNodeTemplates(String serviceTemplateId, String[] types)\r
- throws CatalogResourceException {\r
- List<NodeTemplateData> ntdList =\r
- TemplateManager.getInstance().queryNodeTemplateBySeriviceTemplateId(serviceTemplateId);\r
- if (ntdList == null || ntdList.isEmpty()) {\r
- return new NodeTemplate[0];\r
- }\r
-\r
- if (ToolUtil.isTrimedEmptyArray(types)) { // return all node templates\r
- return TemplateDataHelper.convert2NodeTemplates(ntdList);\r
- }\r
-\r
- List<NodeTemplate> ntList = new ArrayList<>();\r
- for (String type : types) {\r
- if (!ToolUtil.isTrimedEmptyString(type)) {\r
- List<NodeTemplateData> typedNtdList = filterNodeTemplateDataListByType(ntdList, type);\r
- ntList.addAll(Arrays.asList(TemplateDataHelper.convert2NodeTemplates(typedNtdList)));\r
- }\r
- }\r
- return ntList.toArray(new NodeTemplate[0]);\r
- }\r
-\r
- /**\r
- * filter node template data list by type.\r
- * @param ntdList nodeTemplate list\r
- * @param type node type\r
- * @return node template data list\r
- */\r
- private List<NodeTemplateData> filterNodeTemplateDataListByType(List<NodeTemplateData> ntdList,\r
- String type) {\r
- List<NodeTemplateData> retList = new ArrayList<>();\r
- for (NodeTemplateData ntd : ntdList) {\r
- if (type.equals(ntd.getType())) {\r
- retList.add(ntd);\r
- }\r
- }\r
- return retList;\r
- }\r
-\r
-\r
- /**\r
- * get nfv template.\r
- * @param serviceTemlateId service template id\r
- * @return NfvTemplate\r
- * @throws CatalogResourceException e\r
- */\r
- public NfvTemplate getNfvTemplate(String serviceTemlateId) throws CatalogResourceException {\r
- NodeTemplate[] nts = getNodeTemplates(serviceTemlateId, null);\r
-\r
- List<NodeTemplate> vduNodes = new ArrayList<>();\r
- List<NodeTemplate> networkNodes = new ArrayList<>();\r
- List<NodeTemplate> vnfcNodes = new ArrayList<>();\r
- List<NodeTemplate> vnfNodes = new ArrayList<>();\r
- for (NodeTemplate nt : nts) {\r
- if (isVduNode(nt.getType())) {\r
- vduNodes.add(nt);\r
- continue;\r
- }\r
-\r
- if (isNetworkNode(nt.getType())) {\r
- networkNodes.add(nt);\r
- continue;\r
- }\r
-\r
- if (isVnfcNode(nt.getType())) {\r
- vnfcNodes.add(nt);\r
- continue;\r
- }\r
-\r
- if (isVnfNode(nt.getType())) {\r
- vnfNodes.add(nt);\r
- continue;\r
- }\r
- }\r
-\r
- return new NfvTemplate(vduNodes, networkNodes, vnfcNodes, vnfNodes);\r
- }\r
-\r
- private boolean isVnfNode(String type) {\r
- return type.toUpperCase().indexOf(".VNF") > 0;\r
- }\r
-\r
- private boolean isVnfcNode(String type) {\r
- return type.toUpperCase().indexOf(".VNFC") > 0;\r
- }\r
-\r
- private boolean isNetworkNode(String type) {\r
- return type.toUpperCase().indexOf(".VL") > 0 || type.toUpperCase().indexOf(".VIRTUALLINK") > 0;\r
- }\r
-\r
- private boolean isVduNode(String type) {\r
- return type.toUpperCase().indexOf(".VDU") > 0;\r
- }\r
-\r
-}\r
+/**
+ * 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.wrapper;
+
+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.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;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+
+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(String status, boolean deletionPending)
+ throws CatalogResourceException {
+ PackageData pd = new PackageData();
+ pd.setUsageState(status);
+ pd.setDeletionPending(String.valueOf(deletionPending));
+
+ List<ServiceTemplateData> stdList =
+ TemplateManager.getInstance().queryServiceTemplateByCsarPackageInfo(pd);
+
+ return TemplateDataHelper.convert2ServiceTemplates(stdList);
+ }
+
+
+ /**
+ * 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;
+ } else {
+ sts[i] = getServiceTemplateById(stm.getServiceTemplateId());
+ }
+ }
+
+ return sts;
+ }
+
+ /**
+ * 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;
+ }
+
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.resources;\r
-\r
-import org.openo.commontosca.catalog.common.CommonErrorResponse;\r
-import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
-\r
-import javax.ws.rs.BadRequestException;\r
-import javax.ws.rs.InternalServerErrorException;\r
-import javax.ws.rs.core.Response;\r
-\r
-public class RestUtils {\r
- public static InternalServerErrorException newInternalServerErrorException(\r
- CatalogResourceException e1) {\r
- return new InternalServerErrorException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)\r
- .entity(new CommonErrorResponse(e1.getErrcode() + "", e1.getMessage())).build(), e1);\r
- }\r
-\r
- public static BadRequestException newBadRequestException(CatalogBadRequestException e1) {\r
- return new BadRequestException(Response.status(Response.Status.BAD_REQUEST)\r
- .entity(new CommonErrorResponse(e1.getErrcode() + "", e1.getMessage())).build(), e1);\r
- }\r
-}\r
+/**
+ * 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.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);
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.wrapper;\r
-\r
-import org.glassfish.jersey.media.multipart.FormDataContentDisposition;\r
-import org.openo.commontosca.catalog.common.CommonConstant;\r
-import org.openo.commontosca.catalog.common.HttpServerPathConfig;\r
-import org.openo.commontosca.catalog.common.RestUtil;\r
-import org.openo.commontosca.catalog.common.ToolUtil;\r
-import org.openo.commontosca.catalog.common.ZipCompressor;\r
-import org.openo.commontosca.catalog.db.entity.PackageData;\r
-import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
-import org.openo.commontosca.catalog.db.resource.PackageManager;\r
-import org.openo.commontosca.catalog.db.resource.TemplateManager;\r
-import org.openo.commontosca.catalog.entity.EnumType;\r
-import org.openo.commontosca.catalog.entity.request.PackageBasicInfo;\r
-import org.openo.commontosca.catalog.entity.request.UploadPackageFromFtpRequest;\r
-import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse;\r
-import org.openo.commontosca.catalog.entity.response.PackageMeta;\r
-import org.openo.commontosca.catalog.entity.response.UploadPackageResponse;\r
-import org.openo.commontosca.catalog.filemanage.FileManagerFactory;\r
-import org.openo.commontosca.catalog.filemanage.entity.FileLink;\r
-import org.openo.commontosca.catalog.model.parser.EnumPackageFormat;\r
-import org.openo.commontosca.catalog.model.parser.ModelParserFactory;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.io.BufferedInputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.InputStream;\r
-import java.text.SimpleDateFormat;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-\r
-import javax.ws.rs.core.HttpHeaders;\r
-import javax.ws.rs.core.Response;\r
-import javax.ws.rs.core.Response.Status;\r
-\r
-public class PackageWrapper {\r
- private static PackageWrapper packageWrapper;\r
- private static final Logger LOG = LoggerFactory.getLogger(PackageWrapper.class);\r
-\r
- /**\r
- * get PackageWrapper instance.\r
- * @return package wrapper instance\r
- */\r
- public static PackageWrapper getInstance() {\r
- if (packageWrapper == null) {\r
- packageWrapper = new PackageWrapper();\r
- }\r
- return packageWrapper;\r
- }\r
-\r
- /**\r
- * query package by id.\r
- * @param csarId package id\r
- * @return Response\r
- */\r
- public Response queryPackageById(String csarId) {\r
- ArrayList<PackageData> dbResult = new ArrayList<PackageData>();\r
- ArrayList<PackageMeta> result = new ArrayList<PackageMeta>();\r
- dbResult = PackageWrapperUtil.getPackageInfoById(csarId);\r
- if (dbResult.size() != 0) {\r
- result = PackageWrapperUtil.packageDataList2PackageMetaList(dbResult);\r
- return Response.ok(result).build();\r
- } else {\r
- String errorMsg = "get package info by Id error !";\r
- return RestUtil.getRestException(errorMsg);\r
- }\r
- }\r
-\r
- /**\r
- * upload package.\r
- * @param uploadedInputStream inputStream\r
- * @param fileDetail package detail\r
- * @param head http header\r
- * @return Response\r
- * @throws Exception e\r
- */\r
- public Response uploadPackage(InputStream uploadedInputStream,\r
- FormDataContentDisposition fileDetail, HttpHeaders head) throws Exception {\r
- PackageBasicInfo basicInfo = new PackageBasicInfo();\r
- String tempDirName = null;\r
- int fileSize = 0;\r
- String fileName = "";\r
- UploadPackageResponse result = new UploadPackageResponse();\r
- PackageMeta packageMeta = new PackageMeta();\r
- if (uploadedInputStream == null) {\r
- LOG.info("the uploadStream is null");\r
- return Response.serverError().build();\r
- }\r
- if (fileDetail == null) {\r
- LOG.info("the fileDetail is null");\r
- return Response.serverError().build();\r
- }\r
-\r
- try {\r
- String contentRange = null;\r
- fileName = ToolUtil.processFileName(fileDetail.getFileName());\r
- tempDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName);\r
- if (head != null) {\r
- contentRange = head.getHeaderString(CommonConstant.HTTP_HEADER_CONTENT_RANGE);\r
- }\r
- LOG.debug("store package chunk file, fileName:" + fileName + ",contentRange:" + contentRange);\r
- if (ToolUtil.isEmptyString(contentRange)) {\r
- fileSize = uploadedInputStream.available();\r
- contentRange = "0-" + fileSize + "/" + fileSize;\r
- }\r
- String fileLocation =\r
- ToolUtil.storeChunkFileInLocal(tempDirName, fileName, uploadedInputStream);\r
- LOG.info("the fileLocation when upload package is :" + fileLocation);\r
- uploadedInputStream.close();\r
-\r
- basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation);\r
- String path =\r
- basicInfo.getType().toString() + File.separator + basicInfo.getProvider()\r
- + File.separator + fileName.replace(".csar", "") + File.separator\r
- + basicInfo.getVersion();\r
- LOG.info("dest path is : " + path);\r
- packageMeta = PackageWrapperUtil.getPackageMeta(fileName, fileLocation, basicInfo);\r
- String dowloadUri = File.separator + path + File.separator;\r
- String destPath = File.separator + path;\r
- packageMeta.setDownloadUri(dowloadUri);\r
- LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta));\r
- Boolean isEnd = PackageWrapperUtil.isUploadEnd(contentRange, fileName);\r
- if (isEnd) {\r
- boolean uploadResult = FileManagerFactory.createFileManager().upload(tempDirName, destPath);\r
- if (uploadResult == true) {\r
- // 调袁虎的接口,将fileLocation 和 packageId传给他,由他去解析包,并向数据库存储数据\r
- // String parseResult =\r
- // ModelParserFactory.getInstance().parse(packageMeta.getCsarId(),\r
- // fileLocation , EnumPackageFormat.valueOf(packageMeta.getFormat()));\r
- PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta);\r
- PackageManager.getInstance().addPackage(packageData);\r
- }\r
- LOG.info("upload package file end, fileName:" + fileName);\r
- }\r
- result.setCsarId(packageMeta.getCsarId());\r
- return Response.ok(result).build();\r
- } catch (Exception e1) {\r
- LOG.error("upload package fail.", e1);\r
- String csarId = packageMeta.getCsarId();\r
- if (csarId != null) {\r
- PackageManager.getInstance().deletePackage(csarId);\r
- }\r
- return RestUtil.getRestException(e1.getMessage());\r
- } finally {\r
- if (tempDirName != null) {\r
- ToolUtil.deleteDir(new File(tempDirName));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * delete package by package id.\r
- * @param csarId package id\r
- * @return Response\r
- */\r
- public Response delPackage(String csarId) {\r
- LOG.info("delete package info.csarId:" + csarId);\r
- if (ToolUtil.isEmptyString(csarId)) {\r
- LOG.error("delete package fail, csarid is null");\r
- return Response.serverError().build();\r
- }\r
- try {\r
- DelCsarThread thread = new DelCsarThread(csarId, false);\r
- new Thread(thread).start();\r
- return Response.noContent().build();\r
- } catch (Exception e1) {\r
- LOG.error("delete fail.", e1);\r
- return RestUtil.getRestException(e1.getMessage());\r
- }\r
- }\r
-\r
- // public Response delPackageByServiceTemplateId(String serviceTemplateId) {\r
- // LOG.info("delete package info.serviceTemplateId:" + serviceTemplateId);\r
- // if (ToolUtil.isEmptyString(serviceTemplateId)) {\r
- // LOG.error("delete package fail, serviceTemplateId is null");\r
- // return Response.serverError().build();\r
- // }\r
- // ArrayList<PackageData> result = new ArrayList<PackageData>();\r
- // try {\r
- // result = PackageManager.getInstance().queryPackageByServiceTemplateId(serviceTemplateId);\r
- //\r
- // } catch (CatalogResourceException e) {\r
- // LOG.error("query package by csarId from db error ! " + e.getMessage());\r
- // return RestUtil.getRestException(e.getMessage());\r
- // }\r
- // if (result.size() <= 0) {\r
- // LOG.warn("not exist package by serviceTemplateId");\r
- // return Response.status(Status.NOT_FOUND).build();\r
- // }\r
- // if ("true".equals(result.get(0).getDeletionPending())) {\r
- // LOG.info("start delete package.csarId:" + result.get(0).getCsarId());\r
- // delCsarThread thread = new delCsarThread(result.get(0).getCsarId(), true);\r
- // new Thread(thread).start();\r
- // }\r
- // return Response.noContent().build();\r
- // }\r
-\r
- class DelCsarThread implements Runnable {\r
- private String csarid;\r
- private boolean isInstanceTemplate = false;\r
-\r
- public DelCsarThread(String csarid, boolean isInstanceTemplate) {\r
- this.csarid = csarid;\r
- this.isInstanceTemplate = isInstanceTemplate;\r
- }\r
-\r
- @Override\r
- public void run() {\r
- try {\r
- if (!ToolUtil.isEmptyString(csarid)) {\r
- delCsarData(csarid);\r
- }\r
- } catch (Exception e1) {\r
- LOG.error("del instance csar fail.", e1);\r
- updatePackageStatus(csarid, null, null, null, CommonConstant.PACKAGE_STATUS_DELETE_FAIL,\r
- null);\r
- // publishDelFinishCometdMessage(csarid, "false");\r
- }\r
- }\r
-\r
- private void delCsarData(String csarId) {\r
- updatePackageStatus(csarid, null, null, null, CommonConstant.PACKAGE_STATUS_DELETING, null);\r
- String packagePath = PackageWrapperUtil.getPackagePath(csarId);\r
- if (packagePath == null) {\r
- LOG.error("package path is null! ");\r
- return;\r
- }\r
- FileManagerFactory.createFileManager().delete(packagePath);\r
- try {\r
- PackageManager.getInstance().deletePackage(csarId);\r
- } catch (CatalogResourceException e1) {\r
- LOG.error("delete package by csarId from db error ! " + e1.getMessage());\r
- }\r
- // delete template data from db\r
- PackageData packageData = new PackageData();\r
- packageData.setCsarId(csarId);\r
- try {\r
- TemplateManager.getInstance().deleteServiceTemplateByCsarPackageInfo(packageData);\r
- } catch (CatalogResourceException e2) {\r
- LOG.error("delete template data from db error! csarId = " + csarId);\r
- }\r
- // publishDelFinishCometdMessage(csarid, "true");\r
- }\r
-\r
- // private void publishDelFinishCometdMessage(String csarid, String csarDelStatus) {\r
- // if (isInstanceTemplate) {\r
- // LOG.info("delete instance Template finish. csarid:{}", csarid);\r
- // return;\r
- // }\r
- // try {\r
- // Map<String, Object> cometdMessage = new HashMap<String, Object>();\r
- // cometdMessage.put("csarid", csarid);\r
- // cometdMessage.put("status", csarDelStatus);\r
- // CometdService.getInstance().publish(CommonConstant.COMETD_CHANNEL_PACKAGE_DELETE,\r
- // cometdMessage);\r
- // } catch (CometdException e) {\r
- // LOG.error("publish delfinish cometdmsg fail.", e);\r
- // }\r
- // }\r
- }\r
-\r
- /**\r
- * update package status.\r
- * @param csarId package id\r
- * @param operationalState package operational state\r
- * @param usageState package usage state\r
- * @param onBoardState package onboard state\r
- * @param processState package process state\r
- * @param deletionPending package deletionPending status\r
- * @return Response\r
- */\r
- public Response updatePackageStatus(String csarId, String operationalState, String usageState,\r
- String onBoardState, String processState, String deletionPending) {\r
- LOG.info("update package status info.csarId:" + csarId + " operationalState:"\r
- + operationalState);\r
- if (ToolUtil.isEmptyString(csarId)) {\r
- LOG.error("update csar status fail, csarid is null");\r
- return Response.serverError().build();\r
- }\r
- try {\r
- // UpdatePackageResponse result = new UpdatePackageResponse();\r
- PackageData packageInfo = new PackageData();\r
- if (operationalState != null) {\r
- packageInfo.setOperationalState(operationalState);\r
- }\r
- if (usageState != null) {\r
- packageInfo.setUsageState(usageState);\r
- }\r
- if (onBoardState != null) {\r
- packageInfo.setOnBoardState(onBoardState);\r
- }\r
- if (processState != null) {\r
- packageInfo.setProcessState(processState);\r
- }\r
- if (deletionPending != null) {\r
- packageInfo.setDeletionPending(deletionPending);\r
- }\r
- SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
- String currentTime = sdf1.format(new Date());\r
- packageInfo.setModifyTime(currentTime);\r
- PackageManager.getInstance().updatePackage(packageInfo, csarId);\r
- // ArrayList<PackageData> pacackgeList = PackageWrapperUtil.getPackageInfoById(csarId);\r
- // String finalUsageState = pacackgeList.get(0).getUsageState();\r
- // result.setUsageState(finalUsageState);\r
- return Response.ok().build();\r
- } catch (CatalogResourceException e1) {\r
- LOG.error("update package status by csarId from db error ! " + e1.getMessage());\r
- return RestUtil.getRestException(e1.getMessage());\r
- }\r
- }\r
-\r
- /**\r
- * download package by package id.\r
- * @param csarId package id\r
- * @return Response\r
- */\r
- public Response downloadCsarPackagesById(String csarId) {\r
- ArrayList<PackageData> packageList = PackageWrapperUtil.getPackageInfoById(csarId);\r
- String packageName = null;\r
- if (null != packageList && packageList.size() > 0) {\r
- packageName = packageList.get(0).getName();\r
- }\r
- String path = ToolUtil.getCatalogueCsarPath() + File.separator + packageName;\r
- File csarFile = new File(path);\r
- if (!csarFile.exists()) {\r
- return Response.status(Status.NOT_FOUND).build();\r
- }\r
-\r
- try {\r
- InputStream fis = new BufferedInputStream(new FileInputStream(path));\r
- return Response.ok(fis)\r
- .header("Content-Disposition", "attachment; filename=\"" + csarFile.getName() + "\"")\r
- .build();\r
- } catch (Exception e1) {\r
- LOG.error("download vnf package fail.", e1);\r
- return RestUtil.getRestException(e1.getMessage());\r
- }\r
- }\r
-\r
- /**\r
- * query package list by condition.\r
- * @param name package name\r
- * @param provider package provider\r
- * @param version package version\r
- * @param deletionPending package deletionPending\r
- * @param type package type\r
- * @return Response\r
- */\r
- public Response queryPackageListByCond(String name, String provider, String version,\r
- String deletionPending, String type) {\r
- ArrayList<PackageData> dbresult = new ArrayList<PackageData>();\r
- ArrayList<PackageMeta> result = new ArrayList<PackageMeta>();\r
- LOG.info("query package info.name:" + name + " provider:" + provider + " version" + version\r
- + " deletionPending" + deletionPending + " type:" + type);\r
- try {\r
- dbresult =\r
- PackageManager.getInstance().queryPackage(name, provider, version, deletionPending, type);\r
- result = PackageWrapperUtil.packageDataList2PackageMetaList(dbresult);\r
- return Response.ok(result).build();\r
- } catch (CatalogResourceException e1) {\r
- LOG.error("query package by csarId from db error ! " + e1.getMessage());\r
- return RestUtil.getRestException(e1.getMessage());\r
- }\r
- }\r
-\r
- /**\r
- * get package file uri.\r
- * @param csarId package id\r
- * @param relativePath file relative path\r
- * @return Response\r
- */\r
- public Response getCsarFileUri(String csarId, String relativePath) {\r
- try {\r
- CsarFileUriResponse result = getCsarFileDownloadUri(csarId, relativePath);\r
- return Response.ok(result).build();\r
- } catch (CatalogResourceException e1) {\r
- LOG.error("Query CSAR package by ID failed ! csarId = " + csarId);\r
- }\r
-\r
- return Response.serverError().build();\r
- }\r
-\r
- /**\r
- * get package file download uri.\r
- * @param csarId package id\r
- * @param relativePath package file relative path\r
- * @return CsarFileUriResponse\r
- * @throws CatalogResourceException\r
- */\r
- public CsarFileUriResponse getCsarFileDownloadUri(String csarId, String relativePath)\r
- throws CatalogResourceException {\r
- CsarFileUriResponse result = new CsarFileUriResponse();\r
- String downloadUrl = null;\r
- String downloadUri = null;\r
- String localPath = null;\r
- ArrayList<PackageData> packageList = PackageManager.getInstance().queryPackageByCsarId(csarId);\r
- if (packageList != null && packageList.size() != 0) {\r
- String packageName = packageList.get(0).getName();\r
- String relativeUri = packageList.get(0).getDownloadUri() + packageName;\r
- downloadUri = relativeUri + relativePath;\r
- downloadUrl = PackageWrapperUtil.getUrl(downloadUri);\r
- String httpUri = HttpServerPathConfig.getHttpServerPath() + downloadUri;\r
- localPath = PackageWrapperUtil.getLocalPath(httpUri);\r
- }\r
- result.setDownloadUri(downloadUrl);\r
- result.setLocalPath(localPath);\r
- return result;\r
- }\r
-\r
- /**\r
- * upload package from ftp.\r
- * @param request package basic information\r
- * @return Response\r
- */\r
- public Response uploadPackageFromFtp(UploadPackageFromFtpRequest request) {\r
- PackageBasicInfo basicInfo = new PackageBasicInfo();\r
- String tempDirName = null;\r
- String fileName = "";\r
- UploadPackageResponse result = new UploadPackageResponse();\r
- basicInfo.setProvider("zte");\r
- basicInfo.setType(EnumType.NSAR);\r
- basicInfo.setVersion("v1.0");\r
- PackageMeta packageMeta = new PackageMeta();\r
-\r
- try {\r
- String ftpUrl = request.getFtpUrl();\r
- String packageName = PackageWrapperUtil.getPackageName(ftpUrl);\r
- fileName = ToolUtil.processFileName(packageName);\r
- tempDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName);\r
- PackageWrapperUtil.downPackageFromFtp(ftpUrl, tempDirName);\r
- String path =\r
- basicInfo.getType().toString() + File.separator + basicInfo.getProvider()\r
- + File.separator + fileName.replace(".csar", "") + File.separator\r
- + basicInfo.getVersion();\r
- LOG.info("dest path is : " + path);\r
- packageMeta = PackageWrapperUtil.getPackageMeta(fileName, tempDirName, basicInfo);\r
- String dowloadUri = File.separator + path + File.separator + fileName;\r
- packageMeta.setDownloadUri(dowloadUri);\r
- LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta));\r
- String destPath = File.separator + path;\r
- boolean uploadResult = FileManagerFactory.createFileManager().upload(tempDirName, destPath);\r
- if (uploadResult == true) {\r
- String newZipPath = tempDirName + fileName.replace(".csar", ".zip");\r
- ZipCompressor zc = new ZipCompressor(newZipPath);\r
- String metadataPath = tempDirName + File.separator + CommonConstant.TOSCA_METADATA;\r
- String definitions = tempDirName + File.separator + CommonConstant.DEFINITIONS;\r
- zc.compress(metadataPath, definitions);\r
- // 调袁虎的接口,将fileLocation 和 packageId传给他,由他去解析包,并向数据库存储数据\r
-// String parseResult =\r
- ModelParserFactory.getInstance().parse(packageMeta.getCsarId(), newZipPath,\r
- EnumPackageFormat.valueOf(packageMeta.getFormat()));\r
- PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta);\r
- PackageManager.getInstance().addPackage(packageData);\r
- }\r
- LOG.info("upload package file end, fileName:" + fileName);\r
- result.setCsarId(packageMeta.getCsarId());\r
- return Response.ok(result).build();\r
- } catch (Exception e1) {\r
- LOG.error("upload package fail.", e1);\r
- String csarId = packageMeta.getCsarId();\r
- if (csarId != null) {\r
- try {\r
- PackageManager.getInstance().deletePackage(csarId);\r
- } catch (CatalogResourceException e2) {\r
- LOG.error("delete package failed !");\r
- }\r
- }\r
- return RestUtil.getRestException(e1.getMessage());\r
- } finally {\r
- if (tempDirName != null) {\r
- ToolUtil.deleteDir(new File(tempDirName));\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * get csar plan uri.\r
- * @param csarId package id\r
- * @return Response\r
- */\r
- public Response getCsarPlansUri(String csarId) {\r
- ArrayList<FileLink> fileLinks = new ArrayList<FileLink>();\r
- LOG.info("start query plans of package.csarId:" + csarId);\r
- ArrayList<PackageData> packageList = new ArrayList<PackageData>();\r
- try {\r
- packageList = PackageManager.getInstance().queryPackageByCsarId(csarId);\r
- if (packageList != null && packageList.size() != 0) {\r
- String downloadUri = packageList.get(0).getDownloadUri();\r
- fileLinks = FileManagerFactory.createFileManager().queryWorkFlow(downloadUri);\r
- }\r
- return Response.ok(fileLinks).build();\r
- } catch (CatalogResourceException e1) {\r
- LOG.error("Query plans of package by ID failed ! csarId = " + csarId);\r
- return RestUtil.getRestException(e1.getMessage());\r
- }\r
- // return Response.serverError().build();\r
- }\r
-}\r
+/**
+ * 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.wrapper;
+
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+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.common.ZipCompressor;
+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.db.resource.TemplateManager;
+import org.openo.commontosca.catalog.entity.EnumType;
+import org.openo.commontosca.catalog.entity.request.PackageBasicInfo;
+import org.openo.commontosca.catalog.entity.request.UploadPackageFromFtpRequest;
+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.filemanage.entity.FileLink;
+import org.openo.commontosca.catalog.model.parser.EnumPackageFormat;
+import org.openo.commontosca.catalog.model.parser.ModelParserFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+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) {
+ ArrayList<PackageData> dbResult = new ArrayList<PackageData>();
+ ArrayList<PackageMeta> result = new ArrayList<PackageMeta>();
+ dbResult = PackageWrapperUtil.getPackageInfoById(csarId);
+ if (dbResult.size() != 0) {
+ result = PackageWrapperUtil.packageDataList2PackageMetaList(dbResult);
+ return Response.ok(result).build();
+ } else {
+ String errorMsg = "get package info by Id error !";
+ return RestUtil.getRestException(errorMsg);
+ }
+ }
+
+ /**
+ * 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 {
+ PackageBasicInfo basicInfo = new PackageBasicInfo();
+ String tempDirName = null;
+ int fileSize = 0;
+ String fileName = "";
+ UploadPackageResponse result = new UploadPackageResponse();
+ PackageMeta packageMeta = new PackageMeta();
+ 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();
+ }
+
+ try {
+ String contentRange = null;
+ fileName = ToolUtil.processFileName(fileDetail.getFileName());
+ tempDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName);
+ if (head != null) {
+ contentRange = head.getHeaderString(CommonConstant.HTTP_HEADER_CONTENT_RANGE);
+ }
+ LOG.debug("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();
+
+ basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation);
+ 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 = PackageWrapperUtil.getPackageMeta(fileName, fileLocation, basicInfo);
+ String dowloadUri = File.separator + path + File.separator;
+ String destPath = File.separator + path;
+ packageMeta.setDownloadUri(dowloadUri);
+ LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta));
+ Boolean isEnd = PackageWrapperUtil.isUploadEnd(contentRange, fileName);
+ if (isEnd) {
+ boolean uploadResult = FileManagerFactory.createFileManager().upload(tempDirName, destPath);
+ if (uploadResult == true) {
+ try {
+ String tempCsarPath = tempDirName + File.separator + fileName;
+ ModelParserFactory.getInstance().parse(packageMeta.getCsarId(),
+ tempCsarPath , PackageWrapperUtil.getPackageFormat(packageMeta.getFormat()));
+ } catch (CatalogResourceException e1) {
+ LOG.error("parse package error ! " + e1.getMessage());
+ }
+ PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta);
+ PackageManager.getInstance().addPackage(packageData);
+ }
+ LOG.info("upload package file end, fileName:" + fileName);
+ }
+ result.setCsarId(packageMeta.getCsarId());
+ return Response.ok(result).build();
+ } catch (Exception e1) {
+ LOG.error("upload package fail.", e1);
+ String csarId = packageMeta.getCsarId();
+ if (csarId != null) {
+ PackageManager.getInstance().deletePackage(csarId);
+ }
+ return RestUtil.getRestException(e1.getMessage());
+ } finally {
+ if (tempDirName != null) {
+ ToolUtil.deleteDir(new File(tempDirName));
+ }
+ }
+ }
+
+ /**
+ * 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);
+ new Thread(thread).start();
+ return Response.noContent().build();
+ } catch (Exception e1) {
+ LOG.error("delete fail.", e1);
+ return RestUtil.getRestException(e1.getMessage());
+ }
+ }
+
+ // public Response delPackageByServiceTemplateId(String serviceTemplateId) {
+ // LOG.info("delete package info.serviceTemplateId:" + serviceTemplateId);
+ // if (ToolUtil.isEmptyString(serviceTemplateId)) {
+ // LOG.error("delete package fail, serviceTemplateId is null");
+ // return Response.serverError().build();
+ // }
+ // ArrayList<PackageData> result = new ArrayList<PackageData>();
+ // try {
+ // result = PackageManager.getInstance().queryPackageByServiceTemplateId(serviceTemplateId);
+ //
+ // } catch (CatalogResourceException e) {
+ // LOG.error("query package by csarId from db error ! " + e.getMessage());
+ // return RestUtil.getRestException(e.getMessage());
+ // }
+ // if (result.size() <= 0) {
+ // LOG.warn("not exist package by serviceTemplateId");
+ // return Response.status(Status.NOT_FOUND).build();
+ // }
+ // if ("true".equals(result.get(0).getDeletionPending())) {
+ // LOG.info("start delete package.csarId:" + result.get(0).getCsarId());
+ // delCsarThread thread = new delCsarThread(result.get(0).getCsarId(), true);
+ // new Thread(thread).start();
+ // }
+ // return Response.noContent().build();
+ // }
+
+ 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);
+ 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;
+ }
+ FileManagerFactory.createFileManager().delete(packagePath);
+ try {
+ PackageManager.getInstance().deletePackage(csarId);
+ } catch (CatalogResourceException e1) {
+ LOG.error("delete package by csarId from db error ! " + e1.getMessage());
+ }
+ // delete template data from db
+ PackageData packageData = new PackageData();
+ packageData.setCsarId(csarId);
+ try {
+ TemplateManager.getInstance().deleteServiceTemplateByCsarPackageInfo(packageData);
+ } catch (CatalogResourceException e2) {
+ LOG.error("delete template data from db error! csarId = " + csarId);
+ }
+ // publishDelFinishCometdMessage(csarid, "true");
+ }
+
+ // private void publishDelFinishCometdMessage(String csarid, String csarDelStatus) {
+ // if (isInstanceTemplate) {
+ // LOG.info("delete instance Template finish. csarid:{}", csarid);
+ // return;
+ // }
+ // try {
+ // Map<String, Object> cometdMessage = new HashMap<String, Object>();
+ // cometdMessage.put("csarid", csarid);
+ // cometdMessage.put("status", csarDelStatus);
+ // CometdService.getInstance().publish(CommonConstant.COMETD_CHANNEL_PACKAGE_DELETE,
+ // cometdMessage);
+ // } catch (CometdException e) {
+ // LOG.error("publish delfinish cometdmsg fail.", e);
+ // }
+ // }
+ }
+
+ /**
+ * 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);
+ 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) {
+ ArrayList<PackageData> packageList = PackageWrapperUtil.getPackageInfoById(csarId);
+ String packageName = null;
+ if (null != packageList && packageList.size() > 0) {
+ packageName = packageList.get(0).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;
+ }
+
+ /**
+ * upload package from ftp.
+ * @param request package basic information
+ * @return Response
+ */
+ public Response uploadPackageFromFtp(UploadPackageFromFtpRequest request) {
+ PackageBasicInfo basicInfo = new PackageBasicInfo();
+ String tempDirName = null;
+ String fileName = "";
+ UploadPackageResponse result = new UploadPackageResponse();
+ basicInfo.setProvider("zte");
+ basicInfo.setType(EnumType.NSAR);
+ basicInfo.setVersion("v1.0");
+ PackageMeta packageMeta = new PackageMeta();
+
+ try {
+ String ftpUrl = request.getFtpUrl();
+ String packageName = PackageWrapperUtil.getPackageName(ftpUrl);
+ fileName = ToolUtil.processFileName(packageName);
+ tempDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName);
+ PackageWrapperUtil.downPackageFromFtp(ftpUrl, tempDirName);
+ 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 = PackageWrapperUtil.getPackageMeta(fileName, tempDirName, basicInfo);
+ String dowloadUri = File.separator + path + File.separator + fileName;
+ packageMeta.setDownloadUri(dowloadUri);
+ LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta));
+ String destPath = File.separator + path;
+ boolean uploadResult = FileManagerFactory.createFileManager().upload(tempDirName, destPath);
+ if (uploadResult == true) {
+ String newZipPath = tempDirName + fileName.replace(".csar", ".zip");
+ ZipCompressor zc = new ZipCompressor(newZipPath);
+ String metadataPath = tempDirName + File.separator + CommonConstant.TOSCA_METADATA;
+ String definitions = tempDirName + File.separator + CommonConstant.DEFINITIONS;
+ zc.compress(metadataPath, definitions);
+ String parseResult = ModelParserFactory.getInstance().parse(packageMeta.getCsarId(),
+ newZipPath, EnumPackageFormat.valueOf(packageMeta.getFormat()));
+ PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta);
+ PackageManager.getInstance().addPackage(packageData);
+ }
+ LOG.info("upload package file end, fileName:" + fileName);
+ result.setCsarId(packageMeta.getCsarId());
+ return Response.ok(result).build();
+ } catch (Exception e1) {
+ LOG.error("upload package fail.", e1);
+ String csarId = packageMeta.getCsarId();
+ if (csarId != null) {
+ try {
+ PackageManager.getInstance().deletePackage(csarId);
+ } catch (CatalogResourceException e2) {
+ LOG.error("delete package failed !");
+ }
+ }
+ return RestUtil.getRestException(e1.getMessage());
+ } finally {
+ if (tempDirName != null) {
+ ToolUtil.deleteDir(new File(tempDirName));
+ }
+ }
+ }
+
+ /**
+ * get csar plan uri.
+ * @param csarId package id
+ * @return Response
+ */
+ public Response getCsarPlansUri(String csarId) {
+ ArrayList<FileLink> fileLinks = new ArrayList<FileLink>();
+ LOG.info("start query plans of package.csarId:" + csarId);
+ ArrayList<PackageData> packageList = new ArrayList<PackageData>();
+ try {
+ packageList = PackageManager.getInstance().queryPackageByCsarId(csarId);
+ if (packageList != null && packageList.size() != 0) {
+ String downloadUri = packageList.get(0).getDownloadUri();
+ fileLinks = FileManagerFactory.createFileManager().queryWorkFlow(downloadUri);
+ }
+ return Response.ok(fileLinks).build();
+ } catch (CatalogResourceException e1) {
+ LOG.error("Query plans of package by ID failed ! csarId = " + csarId);
+ return RestUtil.getRestException(e1.getMessage());
+ }
+ // return Response.serverError().build();
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.openo.commontosca.catalog.wrapper;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.File;\r
-import java.io.FileReader;\r
-import java.io.IOException;\r
-import java.text.SimpleDateFormat;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-\r
-import javax.ws.rs.NotFoundException;\r
-\r
-import org.openo.commontosca.catalog.common.CommonConstant;\r
-import org.openo.commontosca.catalog.common.FileUtil;\r
-import org.openo.commontosca.catalog.common.MsbAddrConfig;\r
-import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
-import org.openo.commontosca.catalog.db.resource.PackageManager;\r
-import org.openo.commontosca.catalog.entity.EnumProcessState;\r
-import org.openo.commontosca.catalog.entity.EnumType;\r
-import org.openo.commontosca.catalog.entity.request.PackageBasicInfo;\r
-import org.openo.commontosca.catalog.ftp.Ftp;\r
-import org.openo.commontosca.catalog.model.entity.ServiceTemplate;\r
-import org.openo.commontosca.catalog.model.externalservice.entity.lifecycle.InstanceEntity;\r
-import org.openo.commontosca.catalog.model.externalservice.lifecycle.LifeCycleServiceConsumer;\r
-import org.openo.commontosca.catalog.common.ToolUtil;\r
-import org.openo.commontosca.catalog.db.entity.PackageData;\r
-import org.openo.commontosca.catalog.entity.CsarPackage;\r
-import org.openo.commontosca.catalog.entity.EnumOnboardState;\r
-import org.openo.commontosca.catalog.entity.EnumOperationalState;\r
-import org.openo.commontosca.catalog.entity.EnumUsageState;\r
-import org.openo.commontosca.catalog.entity.response.PackageMeta;\r
-import org.openo.commontosca.catalog.ftp.FtpUtil;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import com.google.gson.Gson;\r
-import com.google.gson.reflect.TypeToken;\r
-\r
-/**\r
- * @author 00164331\r
- * \r
- */\r
-public class PackageWrapperUtil {\r
- private static final Logger LOG = LoggerFactory.getLogger(PackageWrapperUtil.class);\r
-\r
-\r
- public static List<CsarPackage> formJson2Packages(String packageJson) {\r
- List<CsarPackage> packageList =\r
- new Gson().fromJson(packageJson, new TypeToken<List<CsarPackage>>() {}.getType());\r
- if (null == packageList || packageList.size() == 0) {\r
- throw new NotFoundException("Package do not exist");\r
- }\r
- return packageList;\r
- }\r
-\r
- public static long getPacakgeSize(String fileLocation) {\r
- File file = new File(fileLocation);\r
- return file.length();\r
- }\r
-\r
- public static PackageData getPackageData(PackageMeta meta) {\r
- PackageData packageData = new PackageData();\r
- packageData.setCreateTime(meta.getCreateTime());\r
- packageData.setDeletionPending(String.valueOf(meta.isDeletionPending()));\r
- packageData.setDownloadUri(meta.getDownloadUri());\r
- packageData.setFormat(meta.getFormat());\r
- packageData.setModifyTime(meta.getModifyTime());\r
- packageData.setName(meta.getName());\r
- packageData.setCsarId(meta.getCsarId());\r
- packageData.setOperationalState(meta.getOperationalState().toString());\r
- packageData.setProvider(meta.getProvider());\r
- String fileSize = meta.getSize();\r
- packageData.setSize(fileSize);\r
- packageData.setType(meta.getType());\r
- packageData.setUsageState(meta.getUsageState().toString());\r
- packageData.setVersion(meta.getVersion());\r
- packageData.setOnBoardState(meta.getOnBoardState());\r
- packageData.setProcessState(meta.getProcessState().toString());\r
- return packageData;\r
- }\r
-\r
- public static boolean isUploadEnd(String contentRange, String csarName) {\r
- String range = contentRange;\r
- range = range.replace("bytes", "").trim();\r
- range = range.substring(0, range.indexOf("/"));\r
- String size =\r
- contentRange.substring(contentRange.indexOf("/") + 1, contentRange.length()).trim();\r
- int fileSize = Integer.parseInt(size);\r
- String[] ranges = range.split("-");\r
- int startPosition = Integer.parseInt(ranges[0]);\r
- if (startPosition == 0) {\r
- // delPackageBySync(csarName);\r
- }\r
- // index start from 0\r
- int endPosition = Integer.parseInt(ranges[1]) + 1;\r
- if (endPosition >= fileSize) {\r
- return true;\r
- }\r
- return false;\r
- }\r
-\r
- public static ArrayList<PackageData> getPackageInfoById(String csarId) {\r
- ArrayList<PackageData> result = new ArrayList<PackageData>();\r
- try {\r
- result = PackageManager.getInstance().queryPackageByCsarId(csarId);\r
- } catch (CatalogResourceException e) {\r
- LOG.error("query package by csarId from db error ! " + e.getMessage());\r
- }\r
- return result;\r
- }\r
-\r
- public static PackageMeta getPackageMeta(String fileName, String fileLocation,\r
- PackageBasicInfo basic) {\r
- PackageMeta packageMeta = new PackageMeta();\r
- long size = getPacakgeSize(fileLocation);\r
- packageMeta.setFormat(basic.getFormat());\r
- String packageId = ToolUtil.generateId();\r
- packageMeta.setName(fileName.replace(CommonConstant.CSAR_SUFFIX, ""));\r
- packageMeta.setCsarId(packageId);\r
- packageMeta.setType(basic.getType().toString());\r
- packageMeta.setVersion(basic.getVersion());\r
- packageMeta.setProvider(basic.getProvider());\r
- packageMeta.setDeletionPending(false);\r
- String sizeStr = ToolUtil.getFormatFileSize(size);\r
- packageMeta.setSize(sizeStr);\r
- SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
- String currentTime = sdf1.format(new Date());\r
- packageMeta.setCreateTime(currentTime);\r
- packageMeta.setModifyTime(currentTime);\r
- packageMeta.setOperationalState(EnumOperationalState.Disabled);\r
- packageMeta.setUsageState(EnumUsageState.NotInUse);\r
- packageMeta.setOnBoardState(EnumOnboardState.nonOnBoarded.getValue());\r
- packageMeta.setProcessState(EnumProcessState.normal);\r
- return packageMeta;\r
- }\r
-\r
- public static String getPackagePath(String csarId) {\r
- ArrayList<PackageData> packageList = new ArrayList<PackageData>();\r
- String downloadUri = null;\r
- try {\r
- packageList = PackageManager.getInstance().queryPackageByCsarId(csarId);\r
- downloadUri = packageList.get(0).getDownloadUri();\r
- } catch (CatalogResourceException e) {\r
- LOG.error("Query CSAR package by ID failed ! csarId = " + csarId);\r
- }\r
- return downloadUri;\r
- }\r
-\r
-\r
- public static HashSet<String> instanceConvertToHashSet(ArrayList<InstanceEntity> instancelist) {\r
- HashSet<String> result = new HashSet<String>();\r
- if (instancelist != null) {\r
- for (InstanceEntity instance : instancelist) {\r
- result.add(instance.getServiceTemplateId());\r
- }\r
- }\r
- return result;\r
- }\r
-\r
- public static boolean isExistInstanceCSAR(String csarId) {\r
- // 查询各O(GSO、NFVO、SDNO)的资源实例数据库,查询指定csarId对应的服务模版\r
- ArrayList<ServiceTemplate> templateList = queryAvailableTemplatesByCsar(csarId);\r
- // 调生命周期的接口查询所有实例,查询实例中是否包含指定csarId对应的服务模析ID\r
- HashSet<String> templateSet = instanceConvertToHashSet(LifeCycleServiceConsumer.getInstances());\r
- if (templateList != null && templateList.size() > 0 && templateSet.size() > 0) {\r
- for (ServiceTemplate temp : templateList) {\r
- if (templateSet.contains(temp.getServiceTemplateId())) {\r
- return true;\r
- }\r
- }\r
- }\r
- return false;\r
- }\r
-\r
- public static ArrayList<ServiceTemplate> queryAvailableTemplatesByCsar(String csarId) {\r
- return null;\r
- // ArrayList<ServiceTemplate> resultlist = new ArrayList<ServiceTemplate>();\r
- // String filter = LDAPUtil.getObjectClassFilter(LDAPConstant.OBJECTCLASS_CSAR);\r
- // String result =\r
- // LDAPDataFactory.getInstance().queryData(EnumLDAPData.SERVICETEMPLATE, null, false,\r
- // filter);\r
- // Type type = new TypeToken<ArrayList<ServiceTemplate>>() {}.getType();\r
- // ArrayList<ServiceTemplate> templateList = new Gson().fromJson(result, type);\r
- // for (ServiceTemplate temp : templateList) {\r
- // if (temp.getCsarid().equals(csarId)) {\r
- // resultlist.add(temp);\r
- // }\r
- // }\r
- // return resultlist;\r
- }\r
-\r
- // public static void publishDeletionPendingStatusCometdMessage(String csarid) {\r
- // try {\r
- // Map<String, Object> cometdMessage = new HashMap<String, Object>();\r
- // cometdMessage.put("csarid", csarid);\r
- // cometdMessage.put("status", "deletionPending");\r
- // CometdService.getInstance().publish(CommonConstant.COMETD_CHANNEL_PACKAGE_DELETE,\r
- // cometdMessage);\r
- // } catch (CometdException e) {\r
- // LOG.error("publish delfinish cometdmsg fail.", e);\r
- // }\r
- // }\r
-\r
- /**\r
- * @param ftpUrl\r
- * @return\r
- */\r
- public static Ftp getFtpDetail(String ftpUrl) {\r
- Ftp ftp = new Ftp();\r
- int index1 = ftpUrl.indexOf("ftp://");\r
- int index2 = ftpUrl.indexOf("@");\r
- String userPassSubString = ftpUrl.substring(index1, index2);\r
- int index3 = userPassSubString.indexOf(":");\r
- String userName = userPassSubString.substring(0, index3);\r
- String pass = userPassSubString.substring(index3 + 1);\r
- String subString1 = ftpUrl.substring(index2 + 1);\r
- int index4 = subString1.indexOf("/");\r
- String ipPortSubString = subString1.substring(0, index4);\r
- int index5 = ipPortSubString.indexOf(":");\r
- String ip = ipPortSubString.substring(0, index5);\r
- String port = ipPortSubString.substring(index5 + 1);\r
- int index6 = ftpUrl.lastIndexOf("/");\r
- String path = ftpUrl.substring(0, index6);\r
- ftp.setIpAddr(ip);\r
- ftp.setPath(path);\r
- ftp.setPort(Integer.valueOf(port));\r
- ftp.setPwd(pass);\r
- ftp.setUserName(userName);\r
- return ftp;\r
- }\r
-\r
- /**\r
- * @param ftpUrl\r
- * @return\r
- */\r
- // public static String getFtpDir(String ftpUrl) {\r
- // // TODO Auto-generated method stub\r
- // return null;\r
- // }\r
-\r
- /**\r
- * @param ftpUrl\r
- * @return\r
- */\r
- public static String getPackageName(String ftpUrl) {\r
- int index = ftpUrl.lastIndexOf("/");\r
- String packageName = ftpUrl.substring(index);\r
- return packageName;\r
- }\r
-\r
- public static void downPackageFromFtp(String ftpUrl, String tempDirName) {\r
- Ftp ftp = new Ftp();\r
- ftp = PackageWrapperUtil.getFtpDetail(ftpUrl);\r
- String remoteBaseDir = ftp.getPath();\r
- try {\r
- FtpUtil.startDown(ftp, tempDirName, remoteBaseDir);\r
- } catch (Exception e) {\r
- LOG.error("Down package from ftp failed !");\r
- }\r
- }\r
-\r
- /**\r
- * @param dbResult\r
- * @return\r
- */\r
- public static ArrayList<PackageMeta> packageDataList2PackageMetaList(\r
- ArrayList<PackageData> dbResult) {\r
- ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();\r
- PackageMeta meta = new PackageMeta();\r
- for (int i = 0; i < dbResult.size(); i++) {\r
- PackageData data = dbResult.get(i);\r
- meta = packageData2PackageMeta(data);\r
- metas.add(meta);\r
- }\r
- return metas;\r
- }\r
-\r
- public static EnumOnboardState getEnumByValue(String value) {\r
- if (value == "non-onBoarded") {\r
- return EnumOnboardState.nonOnBoarded;\r
- } else {\r
- return EnumOnboardState.onBoarded;\r
- }\r
- }\r
-\r
- private static PackageMeta packageData2PackageMeta(PackageData packageData) {\r
- PackageMeta meta = new PackageMeta();\r
- meta.setCsarId(packageData.getCsarId());\r
- meta.setCreateTime(packageData.getCreateTime());\r
- meta.setDeletionPending(Boolean.getBoolean(packageData.getDeletionPending()));\r
- String packageUri =\r
- packageData.getDownloadUri() + packageData.getName() + CommonConstant.CSAR_SUFFIX;\r
- String packageUrl = getUrl(packageUri);\r
- meta.setDownloadUri(packageUrl);\r
- meta.setFormat(packageData.getFormat());\r
- meta.setModifyTime(packageData.getModifyTime());\r
- meta.setName(packageData.getName());\r
- meta.setOperationalState(EnumOperationalState.valueOf(packageData.getOperationalState()));\r
- meta.setProvider(packageData.getProvider());\r
- meta.setSize(packageData.getSize());\r
- meta.setType(packageData.getType());\r
- meta.setUsageState(EnumUsageState.valueOf(packageData.getUsageState()));\r
- meta.setVersion(packageData.getVersion());\r
- meta.setOnBoardState(packageData.getOnBoardState());\r
- meta.setProcessState(EnumProcessState.valueOf(packageData.getProcessState()));\r
- return meta;\r
- }\r
-\r
- public static String getUrl(String uri) {\r
- String url = null;\r
- if ((MsbAddrConfig.getMsbAddress().endsWith("/")) && uri.startsWith("/")) {\r
- url = MsbAddrConfig.getMsbAddress() + uri.substring(1);\r
- }\r
- url = MsbAddrConfig.getMsbAddress() + uri;\r
- String urlresult = url.replace("\\", "/");\r
- return urlresult;\r
- }\r
-\r
- public static String getLocalPath(String uri) {\r
- File srcDir = new File(uri);\r
- String localPath = srcDir.getAbsolutePath();\r
- return localPath.replace("\\", "/");\r
- }\r
-\r
- /**\r
- * @param fileLocation\r
- * @return\r
- */\r
- public static PackageBasicInfo getPacageBasicInfo(String fileLocation) {\r
- PackageBasicInfo basicInfo = new PackageBasicInfo();\r
- String unzipDir = ToolUtil.getUnzipDir(fileLocation);\r
- boolean isXmlCsar = false;\r
- try {\r
- String tempfolder = unzipDir;\r
- ArrayList<String> unzipFiles = FileUtil.unzip(fileLocation, tempfolder);\r
- if (unzipFiles.isEmpty()) {\r
- isXmlCsar = true;\r
- }\r
- for (String unzipFile : unzipFiles) {\r
- if (unzipFile.endsWith(CommonConstant.CSAR_META)) {\r
- basicInfo = readCsarMeta(unzipFile);\r
- }\r
- if (ToolUtil.isYamlFile(new File(unzipFile))) {\r
- isXmlCsar = false;\r
- }\r
- }\r
- } catch (IOException e) {\r
- LOG.error("judge package type error !");\r
- }\r
- if (isXmlCsar) {\r
- basicInfo.setFormat(CommonConstant.PACKAGE_XML_FORMAT);\r
- } else {\r
- basicInfo.setFormat(CommonConstant.PACKAGE_YAML_FORMAT);\r
- }\r
- return basicInfo;\r
- }\r
-\r
- /**\r
- * @param unzipFile\r
- * @return\r
- */\r
- private static PackageBasicInfo readCsarMeta(String unzipFile) {\r
- PackageBasicInfo basicInfo = new PackageBasicInfo();\r
- File file = new File(unzipFile);\r
- BufferedReader reader = null;\r
- try {\r
- reader = new BufferedReader(new FileReader(file));\r
- String tempString = null;\r
- while ((tempString = reader.readLine()) != null) {\r
- if (tempString.startsWith(CommonConstant.CSAR_TYPE_META)) {\r
- int count = tempString.indexOf(":") + 1;\r
- basicInfo.setType(EnumType.valueOf(tempString.substring(count)));\r
- }\r
- if (tempString.startsWith(CommonConstant.CSAR_PROVIDER_META)) {\r
- int count = tempString.indexOf(":") + 1;\r
- basicInfo.setProvider(tempString.substring(count));\r
- }\r
- if (tempString.startsWith(CommonConstant.CSAR_VERSION_META)) {\r
- int count = tempString.indexOf(":") + 1;\r
- basicInfo.setVersion(tempString.substring(count));\r
- }\r
- }\r
- reader.close();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- } finally {\r
- if (reader != null) {\r
- try {\r
- reader.close();\r
- } catch (IOException e1) {\r
- }\r
- }\r
- }\r
- return basicInfo;\r
- }\r
-}\r
+/**
+ * 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.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.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 ArrayList<PackageData> getPackageInfoById(String csarId) {
+ ArrayList<PackageData> result = new ArrayList<PackageData>();
+ try {
+ result = PackageManager.getInstance().queryPackageByCsarId(csarId);
+ } 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();
+ 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;
+ }
+ }
+
+ private static PackageMeta packageData2PackageMeta(PackageData packageData) {
+ PackageMeta meta = new PackageMeta();
+ meta.setCsarId(packageData.getCsarId());
+ meta.setCreateTime(packageData.getCreateTime());
+ meta.setDeletionPending(Boolean.getBoolean(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());
+ meta.setProcessState(EnumProcessState.valueOf(packageData.getProcessState()));
+ 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;
+ String urlresult = url.replace("\\", "/");
+ return urlresult;
+ }
+
+ /**
+ * 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 !");
+ }
+ 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.startsWith(CommonConstant.CSAR_TYPE_META)) {
+ int count = tempString.indexOf(":") + 1;
+ basicInfo.setType(EnumType.valueOf(tempString.substring(count)));
+ }
+ if (tempString.startsWith(CommonConstant.CSAR_PROVIDER_META)) {
+ int count = tempString.indexOf(":") + 1;
+ basicInfo.setProvider(tempString.substring(count));
+ }
+ if (tempString.startsWith(CommonConstant.CSAR_VERSION_META)) {
+ int count = tempString.indexOf(":") + 1;
+ basicInfo.setVersion(tempString.substring(count));
+ }
+ }
+ 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;
+ }
+ }
+}
-/**\r
- * Copyright 2016 [ZTE] and others.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.openo.commontosca.catalog.wrapper;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-\r
-import org.glassfish.jersey.media.multipart.FormDataContentDisposition;\r
-import org.junit.After;\r
-import org.junit.AfterClass;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.BeforeClass;\r
-import org.junit.Ignore;\r
-import org.junit.Test;\r
-import org.openo.commontosca.catalog.CatalogAppConfiguration;\r
-import org.openo.commontosca.catalog.common.Config;\r
-import org.openo.commontosca.catalog.common.HttpServerAddrConfig;\r
-import org.openo.commontosca.catalog.common.HttpServerPathConfig;\r
-import org.openo.commontosca.catalog.common.MsbAddrConfig;\r
-import org.openo.commontosca.catalog.db.dao.DaoManager;\r
-import org.openo.commontosca.catalog.db.entity.PackageData;\r
-import org.openo.commontosca.catalog.db.exception.CatalogResourceException;\r
-import org.openo.commontosca.catalog.db.resource.PackageManager;\r
-import org.openo.commontosca.catalog.db.util.H2DbServer;\r
-import org.openo.commontosca.catalog.db.util.HibernateSession;\r
-import org.openo.commontosca.catalog.entity.EnumOnboardState;\r
-import org.openo.commontosca.catalog.entity.EnumOperationalState;\r
-import org.openo.commontosca.catalog.entity.EnumProcessState;\r
-import org.openo.commontosca.catalog.entity.EnumUsageState;\r
-import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse;\r
-import org.openo.commontosca.catalog.entity.response.PackageMeta;\r
-import org.openo.commontosca.catalog.filemanage.entity.FileLink;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.InputStream;\r
-import java.net.URISyntaxException;\r
-import java.util.ArrayList;\r
-\r
-import javax.ws.rs.core.Response;\r
-\r
-public class PackageWrapperTest {\r
- private static String resourcePath;\r
-\r
- static {\r
- MsbAddrConfig.setMsbAddress("http://127.0.0.1:80");\r
- }\r
- \r
- static {\r
- HttpServerAddrConfig.setHttpServerAddress("http://127.0.0.1:8080");\r
- }\r
- \r
- static {\r
- HttpServerPathConfig.setHttpServerPath("../tomcat/webapps/ROOT/");\r
- }\r
-\r
- private static PackageManager manager;\r
-\r
-\r
- /**\r
- * startup db session before class.\r
- * @throws Exception e\r
- */\r
- @BeforeClass\r
- public static void setUpBeforeClass() throws CatalogResourceException {\r
- H2DbServer.startUp();\r
- DaoManager.getInstance().setSessionFactory(HibernateSession.init());\r
- manager = PackageManager.getInstance();\r
- CatalogAppConfiguration configuration = new CatalogAppConfiguration();\r
- Config.setConfigration(configuration);\r
- System.out.println("Set up before class");\r
- }\r
-\r
- /**\r
- * create data before test.\r
- */\r
- @Before\r
- public void setUp() throws Exception {\r
- ArrayList<PackageData> packageList = manager.queryPackage(null, null, null, null, null);\r
- if (packageList != null && packageList.size() > 0) {\r
- for (int i = 0; i < packageList.size(); i++) {\r
- String packageOid = packageList.get(i).getCsarId();\r
- manager.deletePackage(packageOid);\r
- }\r
- }\r
-\r
- // PowerMockito.mockStatic(PackageManager.class);\r
- // PowerMockito.when(manager.addPackage(packageData)).thenReturn(packageData);\r
- // PowerMock.replayAll();\r
- PackageData packageData = new PackageData();\r
- packageData = getPackageData();\r
- manager.addPackage(packageData);\r
- }\r
-\r
- // @Ignore\r
- @Test\r
- public void testUploadPackage() throws Exception {\r
- InputStream ins = null;\r
- Response result = null;\r
- Response result1 = null;\r
- Response result2 = null;\r
- // PackageData packageData = new PackageData();\r
- // packageData = getPackageData();\r
-\r
- FormDataContentDisposition fileDetail =\r
- FormDataContentDisposition.name("fileName").fileName("NanocellGW.csar").build();\r
-\r
- try {\r
- resourcePath = HibernateSession.class.getResource("/").toURI().getPath();\r
- } catch (URISyntaxException e1) {\r
- e1.printStackTrace();\r
- }\r
- final String filename = "NanocellGW.csar";\r
- File packageFile = new File(resourcePath + filename);\r
- try {\r
- ins = new FileInputStream(packageFile);\r
- } catch (FileNotFoundException e2) {\r
- e2.printStackTrace();\r
- }\r
- if (ins != null) {\r
- try {\r
- result = PackageWrapper.getInstance().uploadPackage(ins, fileDetail, null);\r
- } catch (Exception e3) {\r
- e3.printStackTrace();\r
- }\r
- }\r
- assertEquals(200, result.getStatus());\r
- assertNotNull(result.getEntity());\r
-\r
- try {\r
- result1 = PackageWrapper.getInstance().uploadPackage(null, fileDetail, null);\r
- } catch (Exception e4) {\r
- e4.printStackTrace();\r
- }\r
- assertEquals(500, result1.getStatus());\r
-\r
- try {\r
- result2 = PackageWrapper.getInstance().uploadPackage(ins, null, null);\r
- } catch (Exception e5) {\r
- e5.printStackTrace();\r
- }\r
- assertEquals(500, result2.getStatus());\r
- }\r
-\r
- @Test\r
- public void testQueryPackageById() throws Exception {\r
- ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();\r
- metas = getPackageMetaList();\r
- // PackageManager packageManager = mock(PackageManager.class);\r
- // when(packageManager.queryPackageByCsarId(anyString())).thenThrow(new Exception());\r
- // PowerMockito.whenNew(PackageManager.class).withNoArguments().thenReturn(packageManager);\r
- // PowerMockito.mockStatic(PackageManager.class);\r
- // PowerMockito.when(PackageManager.getInstance()).thenReturn(manager);\r
- // PowerMock.replayAll();\r
- // when(manager.queryPackageByCsarId(anyString())).thenThrow(new Exception());\r
- // PowerMockito.whenNew(PackageManager.class).withNoArguments().thenReturn(manager);\r
-\r
- Response result = PackageWrapper.getInstance().queryPackageById("1");\r
- assertEquals(200, result.getStatus());\r
- assertEquals(metas, result.getEntity());\r
-\r
- }\r
-\r
- @Test\r
- public void testQueryPackageByCond() {\r
- ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();\r
- metas = getPackageMetaList();\r
- System.out.println("Test query package by Id");\r
- Response result =\r
- PackageWrapper.getInstance().queryPackageListByCond("NanocellGW", "ZTE", "V1.0", "false",\r
- "NSAR");\r
- assertEquals(200, result.getStatus());\r
- assertEquals(metas, result.getEntity());\r
- }\r
-\r
- @Test\r
- public void testUpdatePackageStatus() {\r
- System.out.println("Test update package status");\r
- Response result =\r
- PackageWrapper.getInstance().updatePackageStatus("1", "Enabled", "NotInUse", "true",\r
- "onBoarding", "true");\r
- assertEquals(200, result.getStatus());\r
- }\r
-\r
- @Test\r
- public void testGetCsarFileUri() {\r
- System.out.println("Test get csar file uri ");\r
- CsarFileUriResponse expectResult = new CsarFileUriResponse();\r
- String csarFileUri =\r
- MsbAddrConfig.getMsbAddress() + "/NSAR/ZTE/NanocellGW/v1.0/NanocellGW/images/segw.img";\r
- String localUri =\r
- HttpServerPathConfig.getHttpServerPath()\r
- + "NSAR/ZTE/NanocellGW/v1.0/NanocellGW/images/segw.img";\r
- File srcDir = new File(localUri);\r
- String localPath = srcDir.getAbsolutePath().replace("\\", "/");\r
-\r
- expectResult.setDownloadUri(csarFileUri);\r
- expectResult.setLocalPath(localPath);\r
- Response result = PackageWrapper.getInstance().getCsarFileUri("1", "/images/segw.img");\r
- assertEquals(200, result.getStatus());\r
- assertEquals(expectResult, result.getEntity());\r
- }\r
-\r
- @Ignore\r
- @Test\r
- public void testGetPlansUri() {\r
- System.out.println("Test get csar plans uri ");\r
- ArrayList<FileLink> expectResult = new ArrayList<FileLink>();\r
- FileLink fileLink1 = new FileLink();\r
- fileLink1.setFileName("init.zip");\r
- fileLink1.setDownloadUri(MsbAddrConfig.getMsbAddress()\r
- + "/NSAR/ZTE/NanocellGW/v1.0/Plans/init.zip");\r
- expectResult.add(fileLink1);\r
- FileLink fileLink2 = new FileLink();\r
- fileLink2.setFileName("delete.zip");\r
- fileLink2.setDownloadUri(MsbAddrConfig.getMsbAddress()\r
- + "/NSAR/ZTE/NanocellGW/v1.0/Plans/delete.zip");\r
- expectResult.add(fileLink2);\r
- Response result = PackageWrapper.getInstance().getCsarPlansUri("1");\r
- assertEquals(200, result.getStatus());\r
- assertEquals(expectResult, result.getEntity());\r
- }\r
-\r
- @Test\r
- public void testDelPackage() {\r
- System.out.println("Test delete package ");\r
- Response result = PackageWrapper.getInstance().delPackage("1");\r
- assertEquals(204, result.getStatus());\r
- try {\r
- Thread.sleep(5000);\r
- } catch (InterruptedException e1) {\r
- e1.printStackTrace();\r
- }\r
- }\r
-\r
- /**\r
- * delete data after test.\r
- */\r
- @After\r
- public void tearDown() throws Exception {\r
- ArrayList<PackageData> packageList = manager.queryPackageByCsarId("1");\r
- if (packageList != null && packageList.size() != 0) {\r
- manager.deletePackage("1");\r
- } else {\r
- return;\r
- }\r
- System.out.println("Tear down");\r
- }\r
-\r
- /**\r
- * destory db session after class.\r
- * @throws Exception e\r
- */\r
- @AfterClass\r
- public static void tearDownAfterClass() {\r
- try {\r
- HibernateSession.destory();\r
- DaoManager.getInstance().setDaoNull();\r
- H2DbServer.shutDown();\r
- } catch (Exception e1) {\r
- Assert.fail("Exception" + e1.getMessage());\r
- }\r
- }\r
-\r
- private PackageData getPackageData() {\r
- PackageData packageData = new PackageData();\r
- packageData.setCsarId("1");\r
- packageData.setCreateTime("2016-06-29 03:33:15");\r
- packageData.setDeletionPending("false");\r
- packageData.setDownloadUri("/NSAR/ZTE/NanocellGW/v1.0/");\r
- packageData.setFormat("yml");\r
- packageData.setModifyTime("2016-06-29 03:33:15");\r
- packageData.setName("NanocellGW");\r
- packageData.setOnBoardState("non-onBoarded");\r
- packageData.setOperationalState("Disabled");\r
- packageData.setProvider("ZTE");\r
- packageData.setSize("0.93M");\r
- packageData.setType("NSAR");\r
- packageData.setUsageState("InUse");\r
- packageData.setVersion("V1.0");\r
- packageData.setProcessState("normal");\r
- return packageData;\r
- }\r
-\r
- private ArrayList<PackageData> getPackageDataList() {\r
- ArrayList<PackageData> packageDataList = new ArrayList<PackageData>();\r
- PackageData packageData = new PackageData();\r
- packageData = getPackageData();\r
- packageDataList.add(packageData);\r
- return packageDataList;\r
- }\r
-\r
- private ArrayList<PackageMeta> getPackageMetaList() {\r
- PackageMeta meta = new PackageMeta();\r
- meta.setCreateTime("2016-06-29 03:33:15");\r
- meta.setCsarId("1");\r
- meta.setDeletionPending(false);\r
- meta.setDownloadUri(MsbAddrConfig.getMsbAddress() \r
- + "/NSAR/ZTE/NanocellGW/v1.0/NanocellGW.csar");\r
- meta.setFormat("yml");\r
- meta.setModifyTime("2016-06-29 03:33:15");\r
- meta.setName("NanocellGW");\r
- meta.setOperationalState(EnumOperationalState.valueOf("Disabled"));\r
- meta.setProvider("ZTE");\r
- meta.setSize("0.93M");\r
- meta.setType("NSAR");\r
- meta.setUsageState(EnumUsageState.valueOf("InUse"));\r
- meta.setVersion("V1.0");\r
- meta.setOnBoardState(EnumOnboardState.nonOnBoarded.getValue());\r
- meta.setProcessState(EnumProcessState.valueOf("normal"));\r
- ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();\r
- metas.add(meta);\r
- return metas;\r
- }\r
-}\r
+/**
+ * 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.wrapper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.openo.commontosca.catalog.CatalogAppConfiguration;
+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.db.dao.DaoManager;
+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.db.util.H2DbServer;
+import org.openo.commontosca.catalog.db.util.HibernateSession;
+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.EnumUsageState;
+import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse;
+import org.openo.commontosca.catalog.entity.response.PackageMeta;
+import org.openo.commontosca.catalog.filemanage.entity.FileLink;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+
+import javax.ws.rs.core.Response;
+
+public class PackageWrapperTest {
+ private static String resourcePath;
+
+ static {
+ MsbAddrConfig.setMsbAddress("http://127.0.0.1:80");
+ }
+
+ static {
+ HttpServerAddrConfig.setHttpServerAddress("http://127.0.0.1:8080");
+ }
+
+ static {
+ HttpServerPathConfig.setHttpServerPath("../tomcat/webapps/ROOT/");
+ }
+
+ private static PackageManager manager;
+
+
+ /**
+ * startup db session before class.
+ * @throws Exception e
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws CatalogResourceException {
+ H2DbServer.startUp();
+ DaoManager.getInstance().setSessionFactory(HibernateSession.init());
+ manager = PackageManager.getInstance();
+ CatalogAppConfiguration configuration = new CatalogAppConfiguration();
+ Config.setConfigration(configuration);
+ System.out.println("Set up before class");
+ }
+
+ /**
+ * create data before test.
+ */
+ @Before
+ public void setUp() throws Exception {
+ ArrayList<PackageData> packageList = manager.queryPackage(null, null, null, null, null);
+ if (packageList != null && packageList.size() > 0) {
+ for (int i = 0; i < packageList.size(); i++) {
+ String packageOid = packageList.get(i).getCsarId();
+ manager.deletePackage(packageOid);
+ }
+ }
+
+ // PowerMockito.mockStatic(PackageManager.class);
+ // PowerMockito.when(manager.addPackage(packageData)).thenReturn(packageData);
+ // PowerMock.replayAll();
+ PackageData packageData = new PackageData();
+ packageData = getPackageData();
+ manager.addPackage(packageData);
+ }
+
+ // @Ignore
+ @Test
+ public void testUploadPackage() throws Exception {
+ InputStream ins = null;
+ Response result = null;
+ Response result1 = null;
+ Response result2 = null;
+ // PackageData packageData = new PackageData();
+ // packageData = getPackageData();
+
+ FormDataContentDisposition fileDetail =
+ FormDataContentDisposition.name("fileName").fileName("NanocellGW.csar").build();
+
+ try {
+ resourcePath = HibernateSession.class.getResource("/").toURI().getPath();
+ } catch (URISyntaxException e1) {
+ e1.printStackTrace();
+ }
+ final String filename = "NanocellGW.csar";
+ File packageFile = new File(resourcePath + filename);
+ try {
+ ins = new FileInputStream(packageFile);
+ } catch (FileNotFoundException e2) {
+ e2.printStackTrace();
+ }
+ if (ins != null) {
+ try {
+ result = PackageWrapper.getInstance().uploadPackage(ins, fileDetail, null);
+ } catch (Exception e3) {
+ e3.printStackTrace();
+ }
+ }
+ assertEquals(200, result.getStatus());
+ assertNotNull(result.getEntity());
+
+ try {
+ result1 = PackageWrapper.getInstance().uploadPackage(null, fileDetail, null);
+ } catch (Exception e4) {
+ e4.printStackTrace();
+ }
+ assertEquals(500, result1.getStatus());
+
+ try {
+ result2 = PackageWrapper.getInstance().uploadPackage(ins, null, null);
+ } catch (Exception e5) {
+ e5.printStackTrace();
+ }
+ assertEquals(500, result2.getStatus());
+ }
+
+ @Test
+ public void testQueryPackageById() throws Exception {
+ ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();
+ metas = getPackageMetaList();
+ // PackageManager packageManager = mock(PackageManager.class);
+ // when(packageManager.queryPackageByCsarId(anyString())).thenThrow(new Exception());
+ // PowerMockito.whenNew(PackageManager.class).withNoArguments().thenReturn(packageManager);
+ // PowerMockito.mockStatic(PackageManager.class);
+ // PowerMockito.when(PackageManager.getInstance()).thenReturn(manager);
+ // PowerMock.replayAll();
+ // when(manager.queryPackageByCsarId(anyString())).thenThrow(new Exception());
+ // PowerMockito.whenNew(PackageManager.class).withNoArguments().thenReturn(manager);
+
+ Response result = PackageWrapper.getInstance().queryPackageById("1");
+ assertEquals(200, result.getStatus());
+ assertEquals(metas, result.getEntity());
+
+ }
+
+ @Test
+ public void testQueryPackageByCond() {
+ ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();
+ metas = getPackageMetaList();
+ System.out.println("Test query package by Id");
+ Response result =
+ PackageWrapper.getInstance().queryPackageListByCond("NanocellGW", "ZTE", "V1.0", "false",
+ "NSAR");
+ assertEquals(200, result.getStatus());
+ assertEquals(metas, result.getEntity());
+ }
+
+ @Test
+ public void testUpdatePackageStatus() {
+ System.out.println("Test update package status");
+ Response result =
+ PackageWrapper.getInstance().updatePackageStatus("1", "Enabled", "NotInUse", "true",
+ "onBoarding", "true");
+ assertEquals(200, result.getStatus());
+ }
+
+ @Test
+ public void testGetCsarFileUri() {
+ System.out.println("Test get csar file uri ");
+ CsarFileUriResponse expectResult = new CsarFileUriResponse();
+ String csarFileUri =
+ MsbAddrConfig.getMsbAddress() + "/NSAR/ZTE/NanocellGW/v1.0/NanocellGW/images/segw.img";
+ String localUri =
+ HttpServerPathConfig.getHttpServerPath()
+ + "NSAR/ZTE/NanocellGW/v1.0/NanocellGW/images/segw.img";
+ File srcDir = new File(localUri);
+ String localPath = srcDir.getAbsolutePath().replace("\\", "/");
+
+ expectResult.setDownloadUri(csarFileUri);
+ expectResult.setLocalPath(localPath);
+ Response result = PackageWrapper.getInstance().getCsarFileUri("1", "/images/segw.img");
+ assertEquals(200, result.getStatus());
+ assertEquals(expectResult, result.getEntity());
+ }
+
+ @Ignore
+ @Test
+ public void testGetPlansUri() {
+ System.out.println("Test get csar plans uri ");
+ ArrayList<FileLink> expectResult = new ArrayList<FileLink>();
+ FileLink fileLink1 = new FileLink();
+ fileLink1.setFileName("init.zip");
+ fileLink1.setDownloadUri(MsbAddrConfig.getMsbAddress()
+ + "/NSAR/ZTE/NanocellGW/v1.0/Plans/init.zip");
+ expectResult.add(fileLink1);
+ FileLink fileLink2 = new FileLink();
+ fileLink2.setFileName("delete.zip");
+ fileLink2.setDownloadUri(MsbAddrConfig.getMsbAddress()
+ + "/NSAR/ZTE/NanocellGW/v1.0/Plans/delete.zip");
+ expectResult.add(fileLink2);
+ Response result = PackageWrapper.getInstance().getCsarPlansUri("1");
+ assertEquals(200, result.getStatus());
+ assertEquals(expectResult, result.getEntity());
+ }
+
+ @Test
+ public void testDelPackage() {
+ System.out.println("Test delete package ");
+ Response result = PackageWrapper.getInstance().delPackage("1");
+ assertEquals(204, result.getStatus());
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+ }
+
+ /**
+ * delete data after test.
+ */
+ @After
+ public void tearDown() throws Exception {
+ ArrayList<PackageData> packageList = manager.queryPackageByCsarId("1");
+ if (packageList != null && packageList.size() != 0) {
+ manager.deletePackage("1");
+ } else {
+ return;
+ }
+ System.out.println("Tear down");
+ }
+
+ /**
+ * destory db session after class.
+ * @throws Exception e
+ */
+ @AfterClass
+ public static void tearDownAfterClass() {
+ try {
+ HibernateSession.destory();
+ DaoManager.getInstance().setDaoNull();
+ H2DbServer.shutDown();
+ } catch (Exception e1) {
+ Assert.fail("Exception" + e1.getMessage());
+ }
+ }
+
+ private PackageData getPackageData() {
+ PackageData packageData = new PackageData();
+ packageData.setCsarId("1");
+ packageData.setCreateTime("2016-06-29 03:33:15");
+ packageData.setDeletionPending("false");
+ packageData.setDownloadUri("/NSAR/ZTE/NanocellGW/v1.0/");
+ packageData.setFormat("yml");
+ packageData.setModifyTime("2016-06-29 03:33:15");
+ packageData.setName("NanocellGW");
+ packageData.setOnBoardState("non-onBoarded");
+ packageData.setOperationalState("Disabled");
+ packageData.setProvider("ZTE");
+ packageData.setSize("0.93M");
+ packageData.setType("NSAR");
+ packageData.setUsageState("InUse");
+ packageData.setVersion("V1.0");
+ packageData.setProcessState("normal");
+ return packageData;
+ }
+
+ private ArrayList<PackageData> getPackageDataList() {
+ ArrayList<PackageData> packageDataList = new ArrayList<PackageData>();
+ PackageData packageData = new PackageData();
+ packageData = getPackageData();
+ packageDataList.add(packageData);
+ return packageDataList;
+ }
+
+ private ArrayList<PackageMeta> getPackageMetaList() {
+ PackageMeta meta = new PackageMeta();
+ meta.setCreateTime("2016-06-29 03:33:15");
+ meta.setCsarId("1");
+ meta.setDeletionPending(false);
+ meta.setDownloadUri(MsbAddrConfig.getMsbAddress()
+ + "/NSAR/ZTE/NanocellGW/v1.0/NanocellGW.csar");
+ meta.setFormat("yml");
+ meta.setModifyTime("2016-06-29 03:33:15");
+ meta.setName("NanocellGW");
+ meta.setOperationalState(EnumOperationalState.valueOf("Disabled"));
+ meta.setProvider("ZTE");
+ meta.setSize("0.93M");
+ meta.setType("NSAR");
+ meta.setUsageState(EnumUsageState.valueOf("InUse"));
+ meta.setVersion("V1.0");
+ meta.setOnBoardState(EnumOnboardState.nonOnBoarded.getValue());
+ meta.setProcessState(EnumProcessState.valueOf("normal"));
+ ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();
+ metas.add(meta);
+ return metas;
+ }
+}
-<!--\r
-\r
- Copyright 2016 [ZTE] and others.\r
-\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-\r
--->\r
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
- <parent>\r
- <groupId>org.openo.common-tosca.catalog</groupId>\r
- <artifactId>distribution</artifactId>\r
- <version>1.0.0-SNAPSHOT</version>\r
- </parent>\r
- \r
- <modelVersion>4.0.0</modelVersion>\r
- <artifactId>catalog-standalone</artifactId>\r
- <name>openo/commontosca/catalog/distribution/catalog-standalone</name>\r
- <packaging>pom</packaging>\r
-\r
- <properties>\r
- <packagename>openo-catalog</packagename>\r
- </properties>\r
-\r
- <build>\r
- <plugins>\r
- <plugin>\r
- <artifactId>maven-resources-plugin</artifactId>\r
- <executions>\r
- <execution>\r
- <id>copy-resources</id>\r
- <phase>process-resources</phase>\r
- <goals>\r
- <goal>copy-resources</goal>\r
- </goals>\r
- <configuration>\r
- <outputDirectory>${basedir}/target/assembly/</outputDirectory>\r
- <resources>\r
- <resource>\r
- <directory>src/main/assembly/</directory>\r
- <filtering>false</filtering>\r
- <includes>\r
- <include>**/*</include>\r
- </includes>\r
- </resource>\r
- </resources>\r
- <overwrite>true</overwrite>\r
- </configuration>\r
- </execution>\r
- </executions>\r
- </plugin>\r
- <plugin>\r
- <groupId>org.apache.maven.plugins</groupId>\r
- <artifactId>maven-dependency-plugin</artifactId>\r
- <executions>\r
- <execution>\r
- <id>copy-jar</id>\r
- <goals>\r
- <goal>copy</goal>\r
- </goals>\r
- <phase>prepare-package</phase>\r
- <configuration>\r
- <artifactItems>\r
- <artifactItem>\r
- <groupId>org.openo.common-tosca.catalog</groupId>\r
- <artifactId>catalog-mgr</artifactId>\r
- <type>jar</type>\r
- <overWrite>true</overWrite>\r
- <outputDirectory>target/assembly/</outputDirectory>\r
- <destFileName>catalog-service.jar</destFileName>\r
- </artifactItem>\r
- </artifactItems>\r
- </configuration>\r
- </execution>\r
- </executions>\r
- </plugin>\r
- <plugin>\r
- <groupId>org.apache.maven.plugins</groupId>\r
- <artifactId>maven-antrun-plugin</artifactId>\r
- <executions>\r
- <execution>\r
- <id>zip</id>\r
- <phase>package</phase>\r
- <goals>\r
- <goal>run</goal>\r
- </goals>\r
- <configuration>\r
- <tasks name="${project.artifactId}">\r
- <zip destfile="target/${packagename}-${project.version}.zip" update="true">\r
- <zipfileset dir="target/assembly" includes="**" />\r
- </zip>\r
- </tasks>\r
- </configuration>\r
- </execution>\r
- </executions>\r
- </plugin>\r
- <plugin>\r
- <groupId>org.codehaus.mojo</groupId>\r
- <artifactId>build-helper-maven-plugin</artifactId>\r
- <executions>\r
- <execution>\r
- <id>attach-artifacts</id>\r
- <phase>package</phase>\r
- <goals>\r
- <goal>attach-artifact</goal>\r
- </goals>\r
- <configuration>\r
- <artifacts>\r
- <artifact>\r
- <file>target/${packagename}-${project.version}.zip</file>\r
- <type>zip</type>\r
- </artifact>\r
- </artifacts>\r
- </configuration>\r
- </execution>\r
- </executions>\r
- </plugin>\r
- </plugins>\r
- </build>\r
-\r
- <dependencies>\r
- <dependency>\r
- <groupId>org.openo.common-tosca.catalog</groupId>\r
- <artifactId>catalog-mgr</artifactId>\r
- <version>${project.version}</version>\r
- </dependency>\r
- </dependencies> \r
-</project>\r
-\r
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.openo.common-tosca.catalog</groupId>
+ <artifactId>distribution</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>catalog-standalone</artifactId>
+ <name>openo/commontosca/catalog/distribution/catalog-standalone</name>
+ <packaging>pom</packaging>
+
+ <properties>
+ <packagename>openo-catalog</packagename>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-resources</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/target/assembly/</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/assembly/</directory>
+ <filtering>false</filtering>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ </resources>
+ <overwrite>true</overwrite>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-jar</id>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <phase>prepare-package</phase>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.openo.common-tosca.catalog</groupId>
+ <artifactId>catalog-mgr</artifactId>
+ <type>jar</type>
+ <overWrite>true</overWrite>
+ <outputDirectory>target/assembly/</outputDirectory>
+ <destFileName>catalog-service.jar</destFileName>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>zip</id>
+ <phase>package</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks name="${project.artifactId}">
+ <zip destfile="target/${packagename}-${project.version}.zip" update="true">
+ <zipfileset dir="target/assembly" includes="**" />
+ </zip>
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>target/${packagename}-${project.version}.zip</file>
+ <type>zip</type>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openo.common-tosca.catalog</groupId>
+ <artifactId>catalog-mgr</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
+
-<?xml version='1.0' encoding='utf-8'?>\r
-<!--\r
-\r
- Copyright 2016 [ZTE] and others.\r
-\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-\r
--->\r
-<!-- Note: A "Server" is not itself a "Container", so you may not\r
- define subcomponents such as "Valves" at this level.\r
- Documentation at /docs/config/server.html\r
- -->\r
-<Server port="8005" shutdown="SHUTDOWN">\r
- <Listener className="org.apache.catalina.startup.VersionLoggerListener" />\r
- <!-- Security listener. Documentation at /docs/config/listeners.html\r
- <Listener className="org.apache.catalina.security.SecurityListener" />\r
- -->\r
- <!--APR library loader. Documentation at /docs/apr.html -->\r
- <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />\r
- <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->\r
- <Listener className="org.apache.catalina.core.JasperListener" />\r
- <!-- Prevent memory leaks due to use of particular java/javax APIs-->\r
- <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />\r
- <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />\r
- <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />\r
-\r
- <!-- Global JNDI resources\r
- Documentation at /docs/jndi-resources-howto.html\r
- -->\r
- <GlobalNamingResources>\r
- <!-- Editable user database that can also be used by\r
- UserDatabaseRealm to authenticate users\r
- -->\r
- <Resource name="UserDatabase" auth="Container"\r
- type="org.apache.catalina.UserDatabase"\r
- description="User database that can be updated and saved"\r
- factory="org.apache.catalina.users.MemoryUserDatabaseFactory"\r
- pathname="conf/tomcat-users.xml" />\r
- </GlobalNamingResources>\r
-\r
- <!-- A "Service" is a collection of one or more "Connectors" that share\r
- a single "Container" Note: A "Service" is not itself a "Container",\r
- so you may not define subcomponents such as "Valves" at this level.\r
- Documentation at /docs/config/service.html\r
- -->\r
- <Service name="Catalina">\r
-\r
- <!--The connectors can use a shared executor, you can define one or more named thread pools-->\r
- <!--\r
- <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"\r
- maxThreads="150" minSpareThreads="4"/>\r
- -->\r
-\r
-\r
- <!-- A "Connector" represents an endpoint by which requests are received\r
- and responses are returned. Documentation at :\r
- Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)\r
- Java AJP Connector: /docs/config/ajp.html\r
- APR (HTTP/AJP) Connector: /docs/apr.html\r
- Define a non-SSL HTTP/1.1 Connector on port 8080\r
- -->\r
- <Connector port="8201" protocol="HTTP/1.1"\r
- connectionTimeout="20000"\r
- redirectPort="8443" />\r
- <!-- A "Connector" using the shared thread pool-->\r
- <!--\r
- <Connector executor="tomcatThreadPool"\r
- port="8080" protocol="HTTP/1.1"\r
- connectionTimeout="20000"\r
- redirectPort="8443" />\r
- -->\r
- <!-- Define a SSL HTTP/1.1 Connector on port 8443\r
- This connector uses the BIO implementation that requires the JSSE\r
- style configuration. When using the APR/native implementation, the\r
- OpenSSL style configuration is required as described in the APR/native\r
- documentation -->\r
- <!--\r
- <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"\r
- maxThreads="150" SSLEnabled="true" scheme="https" secure="true"\r
- clientAuth="false" sslProtocol="TLS" />\r
- -->\r
-\r
- <!-- Define an AJP 1.3 Connector on port 8009 -->\r
- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />\r
-\r
-\r
- <!-- An Engine represents the entry point (within Catalina) that processes\r
- every request. The Engine implementation for Tomcat stand alone\r
- analyzes the HTTP headers included with the request, and passes them\r
- on to the appropriate Host (virtual host).\r
- Documentation at /docs/config/engine.html -->\r
-\r
- <!-- You should set jvmRoute to support load-balancing via AJP ie :\r
- <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">\r
- -->\r
- <Engine name="Catalina" defaultHost="localhost">\r
-\r
- <!--For clustering, please take a look at documentation at:\r
- /docs/cluster-howto.html (simple how to)\r
- /docs/config/cluster.html (reference documentation) -->\r
- <!--\r
- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>\r
- -->\r
-\r
- <!-- Use the LockOutRealm to prevent attempts to guess user passwords\r
- via a brute-force attack -->\r
- <Realm className="org.apache.catalina.realm.LockOutRealm">\r
- <!-- This Realm uses the UserDatabase configured in the global JNDI\r
- resources under the key "UserDatabase". Any edits\r
- that are performed against this UserDatabase are immediately\r
- available for use by the Realm. -->\r
- <Realm className="org.apache.catalina.realm.UserDatabaseRealm"\r
- resourceName="UserDatabase"/>\r
- </Realm>\r
-\r
- <Host name="localhost" appBase="webapps"\r
- unpackWARs="true" autoDeploy="true">\r
-\r
- <!-- SingleSignOn valve, share authentication between web applications\r
- Documentation at: /docs/config/valve.html -->\r
- <!--\r
- <Valve className="org.apache.catalina.authenticator.SingleSignOn" />\r
- -->\r
-\r
- <!-- Access log processes all example.\r
- Documentation at: /docs/config/valve.html\r
- Note: The pattern used is equivalent to using pattern="common" -->\r
- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"\r
- prefix="localhost_access_log." suffix=".txt"\r
- pattern="%h %l %u %t "%r" %s %b" />\r
-\r
- </Host>\r
- </Engine>\r
- </Service>\r
-</Server>\r
+<?xml version='1.0' encoding='utf-8'?>
+<!--
+
+ 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.
+
+-->
+<!-- Note: A "Server" is not itself a "Container", so you may not
+ define subcomponents such as "Valves" at this level.
+ Documentation at /docs/config/server.html
+ -->
+<Server port="8005" shutdown="SHUTDOWN">
+ <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
+ <!-- Security listener. Documentation at /docs/config/listeners.html
+ <Listener className="org.apache.catalina.security.SecurityListener" />
+ -->
+ <!--APR library loader. Documentation at /docs/apr.html -->
+ <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
+ <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
+ <Listener className="org.apache.catalina.core.JasperListener" />
+ <!-- Prevent memory leaks due to use of particular java/javax APIs-->
+ <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
+ <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
+ <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
+
+ <!-- Global JNDI resources
+ Documentation at /docs/jndi-resources-howto.html
+ -->
+ <GlobalNamingResources>
+ <!-- Editable user database that can also be used by
+ UserDatabaseRealm to authenticate users
+ -->
+ <Resource name="UserDatabase" auth="Container"
+ type="org.apache.catalina.UserDatabase"
+ description="User database that can be updated and saved"
+ factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
+ pathname="conf/tomcat-users.xml" />
+ </GlobalNamingResources>
+
+ <!-- A "Service" is a collection of one or more "Connectors" that share
+ a single "Container" Note: A "Service" is not itself a "Container",
+ so you may not define subcomponents such as "Valves" at this level.
+ Documentation at /docs/config/service.html
+ -->
+ <Service name="Catalina">
+
+ <!--The connectors can use a shared executor, you can define one or more named thread pools-->
+ <!--
+ <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
+ maxThreads="150" minSpareThreads="4"/>
+ -->
+
+
+ <!-- A "Connector" represents an endpoint by which requests are received
+ and responses are returned. Documentation at :
+ Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
+ Java AJP Connector: /docs/config/ajp.html
+ APR (HTTP/AJP) Connector: /docs/apr.html
+ Define a non-SSL HTTP/1.1 Connector on port 8080
+ -->
+ <Connector port="8201" protocol="HTTP/1.1"
+ connectionTimeout="20000"
+ redirectPort="8443" />
+ <!-- A "Connector" using the shared thread pool-->
+ <!--
+ <Connector executor="tomcatThreadPool"
+ port="8080" protocol="HTTP/1.1"
+ connectionTimeout="20000"
+ redirectPort="8443" />
+ -->
+ <!-- Define a SSL HTTP/1.1 Connector on port 8443
+ This connector uses the BIO implementation that requires the JSSE
+ style configuration. When using the APR/native implementation, the
+ OpenSSL style configuration is required as described in the APR/native
+ documentation -->
+ <!--
+ <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
+ maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
+ clientAuth="false" sslProtocol="TLS" />
+ -->
+
+ <!-- Define an AJP 1.3 Connector on port 8009 -->
+ <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
+
+
+ <!-- An Engine represents the entry point (within Catalina) that processes
+ every request. The Engine implementation for Tomcat stand alone
+ analyzes the HTTP headers included with the request, and passes them
+ on to the appropriate Host (virtual host).
+ Documentation at /docs/config/engine.html -->
+
+ <!-- You should set jvmRoute to support load-balancing via AJP ie :
+ <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
+ -->
+ <Engine name="Catalina" defaultHost="localhost">
+
+ <!--For clustering, please take a look at documentation at:
+ /docs/cluster-howto.html (simple how to)
+ /docs/config/cluster.html (reference documentation) -->
+ <!--
+ <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
+ -->
+
+ <!-- Use the LockOutRealm to prevent attempts to guess user passwords
+ via a brute-force attack -->
+ <Realm className="org.apache.catalina.realm.LockOutRealm">
+ <!-- This Realm uses the UserDatabase configured in the global JNDI
+ resources under the key "UserDatabase". Any edits
+ that are performed against this UserDatabase are immediately
+ available for use by the Realm. -->
+ <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
+ resourceName="UserDatabase"/>
+ </Realm>
+
+ <Host name="localhost" appBase="webapps"
+ unpackWARs="true" autoDeploy="true">
+
+ <!-- SingleSignOn valve, share authentication between web applications
+ Documentation at: /docs/config/valve.html -->
+ <!--
+ <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
+ -->
+
+ <!-- Access log processes all example.
+ Documentation at: /docs/config/valve.html
+ Note: The pattern used is equivalent to using pattern="common" -->
+ <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
+ prefix="localhost_access_log." suffix=".txt"
+ pattern="%h %l %u %t "%r" %s %b" />
+
+ </Host>
+ </Engine>
+ </Service>
+</Server>
-<!--\r
-\r
- Copyright 2016 [ZTE] and others.\r
-\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-\r
--->\r
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
- <parent>\r
- <groupId>org.openo.common-tosca.catalog</groupId>\r
- <artifactId>catalogparent</artifactId>\r
- <version>1.0.0-SNAPSHOT</version>\r
- <relativePath>catalog-parent/catalogparent</relativePath>\r
- </parent> \r
-\r
- <modelVersion>4.0.0</modelVersion>\r
- <artifactId>catalog-root</artifactId>\r
- <name>openo/commontosca/catalog/catalog-root</name>\r
- <packaging>pom</packaging>\r
-\r
- <modules>\r
- <module>catalog-parent</module>\r
- <module>catalog-core</module>\r
- </modules>\r
-\r
- <build>\r
- <plugins>\r
- <plugin>\r
- <groupId>com.mycila</groupId>\r
- <artifactId>license-maven-plugin</artifactId>\r
- </plugin>\r
- </plugins>\r
- </build>\r
-</project>\r
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.openo.common-tosca.catalog</groupId>
+ <artifactId>catalogparent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>catalog-parent/catalogparent</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>catalog-root</artifactId>
+ <name>openo/commontosca/catalog/catalog-root</name>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>catalog-parent</module>
+ <module>catalog-core</module>
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.mycila</groupId>
+ <artifactId>license-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>