Added license header and other review comments
[msb/java-sdk.git] / example-spring-boot / src / main / java / org / onap / msb / sdk / example / springboot / common / MsbHelper.java
1 /*******************************************************************************
2  * Copyright 2017 Infosys Limited and others.
3  *------------------------------------------------------------------------------
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  * Unless required by applicable law or agreed to in writing, software distributed under the License
8  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
9  * or implied. See the License for the specific language governing permissions and limitations under
10  * the License.
11  ******************************************************************************/
12 package org.onap.msb.sdk.example.springboot.common;
13
14 import java.net.InetAddress;
15 import java.util.HashSet;
16 import java.util.Set;
17
18 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
19 import org.onap.msb.sdk.discovery.entity.Node;
20 import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
21
22 public class MsbHelper {
23
24   private MSBServiceClient msbClient;
25
26   public MsbHelper(MSBServiceClient msbClient) {
27     super();
28     this.msbClient = msbClient;
29   }
30
31   public void registerMsb() throws Exception {
32
33
34     MicroServiceInfo msinfo = new MicroServiceInfo();
35
36     msinfo.setServiceName("employee");
37     msinfo.setVersion("v1");
38     msinfo.setUrl("/api/v1");
39     msinfo.setProtocol("REST");
40     msinfo.setVisualRange("0|1");
41     
42     Set<Node> nodes = new HashSet<>();
43     Node node1 = new Node();
44     node1.setIp(InetAddress.getLocalHost().getHostAddress());
45     node1.setPort("8080");
46     nodes.add(node1);
47     msinfo.setNodes(nodes);
48     msbClient.registerMicroServiceInfo(msinfo, false);
49   }
50 }