ffaba08d18cf290f332f6744a17a6e23b0df7e4a
[msb/java-sdk.git] / example / src / main / java / org / onap / msb / sdk / httpclient / server / MsbHelper.java
1 /*******************************************************************************
2  * Copyright 2017 ZTE, Inc. 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  * 
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * 
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  ******************************************************************************/
14 package org.onap.msb.sdk.httpclient.server;
15
16 import java.net.InetAddress;
17 import java.util.HashSet;
18 import java.util.Set;
19
20 import org.jvnet.hk2.annotations.Service;
21 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
22 import org.onap.msb.sdk.discovery.entity.Node;
23 import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient;
24
25 /**
26  * @author hu.rui
27  *
28  */
29 @Service
30 public class MsbHelper {
31
32   private MSBServiceWrapperClient msbClient;
33
34
35
36   public MsbHelper(MSBServiceWrapperClient msbClient) {
37     super();
38     this.msbClient = msbClient;
39   }
40
41
42
43   public void registerMsb() throws Exception {
44
45
46     MicroServiceInfo msinfo = new MicroServiceInfo();
47
48     msinfo.setServiceName("animals");
49     msinfo.setVersion("v1");
50     msinfo.setUrl("/api/rpc/v1");
51     msinfo.setProtocol("REST");
52     msinfo.setVisualRange("0|1");
53
54     Set<Node> nodes = new HashSet<>();
55     Node node1 = new Node();
56     node1.setIp(InetAddress.getLocalHost().getHostAddress());
57     node1.setPort("9090");
58     nodes.add(node1);
59     msinfo.setNodes(nodes);
60     msbClient.registerMicroServiceInfo(msinfo, false);
61
62   }
63
64
65
66 }