<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>
<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>
*/
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 {
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();
+ }
+ }
}
}
}
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);
}
}
- 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;
}
}
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;
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