diff options
author | Luji7 <lu.ji3@zte.com.cn> | 2017-10-16 16:54:07 +0800 |
---|---|---|
committer | Luji7 <lu.ji3@zte.com.cn> | 2017-10-16 16:54:14 +0800 |
commit | 100674aa613c38a2567ff0becb0e4679e1d5c757 (patch) | |
tree | e05a087d8dab7c43d0a10acbea8034aa8e11d252 | |
parent | 6a8d64d01cb22c8d804342ad653e73c595c6a436 (diff) |
add msb config
Change-Id: Ib42e8275d7111b88a531f697e54e8061ef6231c1
Issue-Id: USECASEUI-36
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
6 files changed, 70 insertions, 14 deletions
@@ -80,10 +80,10 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jersey</artifactId> </dependency> - <dependency> + <!--dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> - </dependency> + </dependency--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> @@ -200,6 +200,12 @@ <version>23.0</version> </dependency> + <dependency> + <groupId>org.onap.msb.java-sdk</groupId> + <artifactId>msb-java-sdk</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <!-- UT coverage dependency start --> <dependency> <groupId>org.jmockit</groupId> diff --git a/server/pom.xml b/server/pom.xml index d0f308fb..7472daa8 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -75,10 +75,10 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jersey</artifactId> </dependency> - <dependency> + <!--dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> - </dependency> + </dependency--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> @@ -202,6 +202,12 @@ </dependency> <dependency> + <groupId>org.onap.msb.java-sdk</groupId> + <artifactId>msb-java-sdk</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + + <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> <version>1.5.4</version> diff --git a/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java b/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java index c12bb24e..3bdbeb9a 100644 --- a/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java +++ b/server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java @@ -15,12 +15,22 @@ */ package org.onap.usecaseui.server; +import org.onap.msb.sdk.discovery.common.RouteException; +import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; +import org.onap.msb.sdk.discovery.entity.Node; +import org.onap.msb.sdk.httpclient.msb.MSBServiceClient; +import org.onap.usecaseui.server.util.RestfulServices; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.client.RestTemplate; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.HashSet; +import java.util.Set; + @SpringBootApplication @ComponentScan(basePackages = "org.onap.usecaseui.server") public class UsecaseuiServerApplication { @@ -32,6 +42,32 @@ public class UsecaseuiServerApplication { public static void main(String[] args) { SpringApplication.run(UsecaseuiServerApplication.class, args); + String msbUrl = RestfulServices.getMsbAddress(); + if (msbUrl.contains(":")) { + String[] ipAndPort = msbUrl.split(":"); + MSBServiceClient msbClient = new MSBServiceClient(ipAndPort[0], Integer.parseInt(ipAndPort[1])); + + MicroServiceInfo msinfo = new MicroServiceInfo(); + msinfo.setServiceName("usecase-ui-server"); + msinfo.setVersion("v1"); + msinfo.setUrl("/api/usecaseui/server/v1"); + msinfo.setProtocol("REST"); + msinfo.setVisualRange("0|1"); + + try { + Set<Node> nodes = new HashSet<>(); + Node node1 = new Node(); + node1.setIp(InetAddress.getLocalHost().getHostAddress()); + node1.setPort("8082"); + nodes.add(node1); + msinfo.setNodes(nodes); + msbClient.registerMicroServiceInfo(msinfo, false); + } catch (UnknownHostException e) { + e.printStackTrace(); + } catch (RouteException e) { + e.printStackTrace(); + } + } } } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java index 6f91a75a..c2644f82 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java @@ -80,12 +80,9 @@ public class DefaultServiceTemplateService implements ServiceTemplateService { } private ServiceTemplateInput fetchServiceTemplate(String uuid, String toscaModelPath) { - String rootPath = "http://localhost";// get from msb - String templateUrl = String.format("%s/%s", rootPath, toscaModelPath); - - String toPath = String.format("temp/%s.csar", uuid); + String toPath = String.format("/home/uui/%s.csar", uuid); try { - downloadFile(templateUrl, toPath); + downloadFile(toscaModelPath, toPath); return extractTemplate(toPath); } catch (IOException e) { throw new SDCCatalogException("download csar file failed!", e); @@ -94,12 +91,14 @@ public class DefaultServiceTemplateService implements ServiceTemplateService { } } - protected void downloadFile(String templateUrl, String toPath) throws IOException { + protected void downloadFile(String toscaModelPath, String toPath) throws IOException { try { + String msbUrl = RestfulServices.getMsbAddress(); + String templateUrl = String.format("http://%s/%s", msbUrl, toscaModelPath); ResponseBody body = sdcCatalog.downloadCsar(templateUrl).execute().body(); Files.write(body.bytes(),new File(toPath)); } catch (IOException e) { - logger.error(String.format("Download %s failed!", templateUrl)); + logger.error(String.format("Download %s failed!", toscaModelPath)); throw e; } } diff --git a/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java b/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java index 66c01de1..83ba466c 100644 --- a/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java +++ b/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java @@ -27,13 +27,22 @@ import java.io.IOException; public class RestfulServices { public static <T> T create(Class<T> clazz) { + String msbUrl = getMsbAddress(); Retrofit retrofit = new Retrofit.Builder() - .baseUrl("http://localhost") + .baseUrl("http://" + msbUrl) .addConverterFactory(JacksonConverterFactory.create()) .build(); return retrofit.create(clazz); } + public static String getMsbAddress() { + String msbAddress = System.getenv("MSB_ADDR"); + if (msbAddress == null) { + return ""; + } + return msbAddress; + } + public static RequestBody extractBody(HttpServletRequest request) throws IOException { int len = request.getContentLength(); ServletInputStream inStream = null; diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties index c4f7d620..c384bf01 100644 --- a/server/src/main/resources/application.properties +++ b/server/src/main/resources/application.properties @@ -29,5 +29,5 @@ spring.jpa.show-sql=false spring.jpa.properties.hibernate.format_sql=false ## Basic Authentication Properties -security.user.name=usecase -security.user.password=usecase
\ No newline at end of file +# security.user.name=usecase +# security.user.password=usecase
\ No newline at end of file |