add msb config 21/19021/1
authorLuji7 <lu.ji3@zte.com.cn>
Mon, 16 Oct 2017 08:54:07 +0000 (16:54 +0800)
committerLuji7 <lu.ji3@zte.com.cn>
Mon, 16 Oct 2017 08:54:14 +0000 (16:54 +0800)
Change-Id: Ib42e8275d7111b88a531f697e54e8061ef6231c1
Issue-Id: USECASEUI-36
Signed-off-by: Luji7 <lu.ji3@zte.com.cn>
pom.xml
server/pom.xml
server/src/main/java/org/onap/usecaseui/server/UsecaseuiServerApplication.java
server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceTemplateService.java
server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java
server/src/main/resources/application.properties

diff --git a/pom.xml b/pom.xml
index ff99452..027cd8c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <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>
             <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>
index d0f308f..7472daa 100644 (file)
             <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>
             <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>
+
         <dependency>
             <groupId>org.powermock</groupId>
             <artifactId>powermock-api-mockito</artifactId>
index c12bb24..3bdbeb9 100644 (file)
  */
 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();
+            }
+        }
        }
        
 }
index 6f91a75..c2644f8 100644 (file)
@@ -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;
         }
     }
index 66c01de..83ba466 100644 (file)
@@ -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;
index c4f7d62..c384bf0 100644 (file)
@@ -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