From 100674aa613c38a2567ff0becb0e4679e1d5c757 Mon Sep 17 00:00:00 2001 From: Luji7 Date: Mon, 16 Oct 2017 16:54:07 +0800 Subject: [PATCH] add msb config Change-Id: Ib42e8275d7111b88a531f697e54e8061ef6231c1 Issue-Id: USECASEUI-36 Signed-off-by: Luji7 --- pom.xml | 10 ++++-- server/pom.xml | 10 ++++-- .../server/UsecaseuiServerApplication.java | 36 ++++++++++++++++++++++ .../lcm/impl/DefaultServiceTemplateService.java | 13 ++++---- .../usecaseui/server/util/RestfulServices.java | 11 ++++++- server/src/main/resources/application.properties | 4 +-- 6 files changed, 70 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index ff99452a..027cd8c3 100644 --- a/pom.xml +++ b/pom.xml @@ -80,10 +80,10 @@ org.springframework.boot spring-boot-starter-jersey - + org.springframework.boot spring-boot-starter-web @@ -200,6 +200,12 @@ 23.0 + + org.onap.msb.java-sdk + msb-java-sdk + 1.0.0-SNAPSHOT + + org.jmockit 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 @@ org.springframework.boot spring-boot-starter-jersey - + org.springframework.boot spring-boot-starter-web @@ -201,6 +201,12 @@ 23.0 + + org.onap.msb.java-sdk + msb-java-sdk + 1.0.0-SNAPSHOT + + org.powermock powermock-api-mockito 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 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 create(Class 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 -- 2.16.6