From 9252e604db14785fe5382e33cedffbdd2759091d Mon Sep 17 00:00:00 2001 From: HuabingZhao Date: Fri, 18 Aug 2017 16:18:01 +0800 Subject: Modify Example code Issue-Id: MSB-23 Change-Id: I03a05b27987015725234d31ccbef2b979be40f92 Signed-off-by: HuabingZhao --- .../sdk/example/client/AnimalServiceClient.java | 33 +++++++ .../onap/msb/sdk/example/client/ExampleClient.java | 49 ++++++++++ .../org/onap/msb/sdk/example/common/Animal.java | 69 ++++++++++++++ .../org/onap/msb/sdk/example/server/Config.java | 24 +++++ .../onap/msb/sdk/example/server/ExampleApp.java | 54 +++++++++++ .../org/onap/msb/sdk/example/server/MsbHelper.java | 62 ++++++++++++ .../example/server/resources/AnimalResource.java | 38 ++++++++ .../sdk/httpclient/client/AnimalServiceClient.java | 34 ------- .../msb/sdk/httpclient/client/ExampleClient.java | 47 ---------- .../org/onap/msb/sdk/httpclient/common/Animal.java | 69 -------------- .../org/onap/msb/sdk/httpclient/server/Config.java | 24 ----- .../onap/msb/sdk/httpclient/server/ExampleApp.java | 51 ---------- .../onap/msb/sdk/httpclient/server/MsbHelper.java | 66 ------------- .../server/resources/AnimalResource.java | 38 -------- .../org/onap/msb/sdk/discovery/entity/Node.java | 104 --------------------- .../org/onap/msb/sdk/discovery/entity/Service.java | 96 ++++++++++--------- 16 files changed, 379 insertions(+), 479 deletions(-) create mode 100644 example/src/main/java/org/onap/msb/sdk/example/client/AnimalServiceClient.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/client/ExampleClient.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/common/Animal.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/server/Config.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/server/ExampleApp.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/server/MsbHelper.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/server/resources/AnimalResource.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/client/AnimalServiceClient.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/client/ExampleClient.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/common/Animal.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/server/Config.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/server/ExampleApp.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/server/MsbHelper.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/server/resources/AnimalResource.java diff --git a/example/src/main/java/org/onap/msb/sdk/example/client/AnimalServiceClient.java b/example/src/main/java/org/onap/msb/sdk/example/client/AnimalServiceClient.java new file mode 100644 index 0000000..8600241 --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/client/AnimalServiceClient.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ +package org.onap.msb.sdk.example.client; + +import org.onap.msb.sdk.example.common.Animal; +import org.onap.msb.sdk.httpclient.annotaion.ServiceHttpEndPoint; + +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Path; + +/** + * @author hu.rui + * + */ + +@ServiceHttpEndPoint(serviceName = "animals", serviceVersion = "v1") +public interface AnimalServiceClient { + + @GET("animals/{name}") + Call queryAnimal1(@Path("name") String name); +} diff --git a/example/src/main/java/org/onap/msb/sdk/example/client/ExampleClient.java b/example/src/main/java/org/onap/msb/sdk/example/client/ExampleClient.java new file mode 100644 index 0000000..59263f1 --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/client/ExampleClient.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ +/** + * + */ +package org.onap.msb.sdk.example.client; + +import java.io.IOException; + +import org.onap.msb.sdk.example.common.Animal; +import org.onap.msb.sdk.httpclient.RetrofitServiceCreater; +import org.onap.msb.sdk.httpclient.conf.HttpClientConf; +import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; + + +public class ExampleClient { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + String MSB_IP="127.0.0.1"; + int MSB_Port=10081; + + HttpClientConf globalHttpClientConf = new HttpClientConf(); + MSBServiceWrapperClient msbClient = new MSBServiceWrapperClient(MSB_IP, MSB_Port); + + RetrofitServiceCreater retrofitServiceCreater = + new RetrofitServiceCreater(globalHttpClientConf, msbClient); + + AnimalServiceClient implProxy = + retrofitServiceCreater.createRetrofitService(AnimalServiceClient.class); + Animal animal = implProxy.queryAnimal1("panda").execute().body(); + System.out.println("animal:" + animal); + } + +} diff --git a/example/src/main/java/org/onap/msb/sdk/example/common/Animal.java b/example/src/main/java/org/onap/msb/sdk/example/common/Animal.java new file mode 100644 index 0000000..03572ce --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/common/Animal.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ +package org.onap.msb.sdk.example.common; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Animal implements Serializable { + + private static final long serialVersionUID = -717235590728668809L; + + @JsonProperty + private String type; + + @JsonProperty + private String name; + + @JsonProperty + private int age; + + public Animal() {} + + public Animal(String type, String name, int age) { + this.type = type; + this.name = name; + this.age = age; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + @Override + public String toString() { + return "Animal{" + "type='" + type + '\'' + ", name='" + name + '\'' + ", age=" + age + '}'; + } +} diff --git a/example/src/main/java/org/onap/msb/sdk/example/server/Config.java b/example/src/main/java/org/onap/msb/sdk/example/server/Config.java new file mode 100644 index 0000000..446e2c1 --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/server/Config.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ +package org.onap.msb.sdk.example.server; + +import io.dropwizard.Configuration; + +public class Config extends Configuration { + + + +} + + diff --git a/example/src/main/java/org/onap/msb/sdk/example/server/ExampleApp.java b/example/src/main/java/org/onap/msb/sdk/example/server/ExampleApp.java new file mode 100644 index 0000000..b93875f --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/server/ExampleApp.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ +package org.onap.msb.sdk.example.server; + +import org.onap.msb.sdk.example.server.resources.AnimalResource; +import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; + +import io.dropwizard.Application; +import io.dropwizard.setup.Environment; + + +public class ExampleApp extends Application { + + private static final String CONFIGURATION_FILE = "example.yml"; + + public static void main(String[] args) throws Exception { + + String configFile = null; + if (args.length > 1) { + configFile = args[0]; + } else { + configFile = ExampleApp.class.getClassLoader().getResource(CONFIGURATION_FILE).getFile(); + } + args = new String[] {"server", configFile}; + new ExampleApp().run(args); + } + + @Override + public void run(Config configuration, Environment environment) throws Exception { + + String MSB_IP="127.0.0.1"; + int MSB_Port=10081; + + environment.jersey().register(new AnimalResource()); + + MSBServiceWrapperClient msbClient = new MSBServiceWrapperClient(MSB_IP, MSB_Port); + + MsbHelper helper = new MsbHelper(msbClient); + helper.registerMsb(); + + } + +} diff --git a/example/src/main/java/org/onap/msb/sdk/example/server/MsbHelper.java b/example/src/main/java/org/onap/msb/sdk/example/server/MsbHelper.java new file mode 100644 index 0000000..7b0c79d --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/server/MsbHelper.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ +package org.onap.msb.sdk.example.server; + +import java.net.InetAddress; +import java.util.HashSet; +import java.util.Set; + +import org.jvnet.hk2.annotations.Service; +import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; +import org.onap.msb.sdk.discovery.entity.Node; +import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; + +/** + * @author hu.rui + * + */ +@Service +public class MsbHelper { + + private MSBServiceWrapperClient msbClient; + + + + public MsbHelper(MSBServiceWrapperClient msbClient) { + super(); + this.msbClient = msbClient; + } + + + + public void registerMsb() throws Exception { + + + MicroServiceInfo msinfo = new MicroServiceInfo(); + + msinfo.setServiceName("animals"); + msinfo.setVersion("v1"); + msinfo.setUrl("/api/rpc/v1"); + msinfo.setProtocol("REST"); + msinfo.setVisualRange("0|1"); + + Set nodes = new HashSet<>(); + Node node1 = new Node(); + node1.setIp(InetAddress.getLocalHost().getHostAddress()); + node1.setPort("9090"); + nodes.add(node1); + msinfo.setNodes(nodes); + msbClient.registerMicroServiceInfo(msinfo, false); + } +} diff --git a/example/src/main/java/org/onap/msb/sdk/example/server/resources/AnimalResource.java b/example/src/main/java/org/onap/msb/sdk/example/server/resources/AnimalResource.java new file mode 100644 index 0000000..ce7115f --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/server/resources/AnimalResource.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ +package org.onap.msb.sdk.example.server.resources; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.onap.msb.sdk.example.common.Animal; + + +@Path("/animals") +public class AnimalResource { + + + @GET + @Path("/{name}") + @Produces(MediaType.APPLICATION_JSON) + public Response queryJson(@PathParam("name") String name) { + return Response.ok(new Animal("animal", name, Math.abs((int) System.currentTimeMillis() % 10))) + .build(); + } + +} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/client/AnimalServiceClient.java b/example/src/main/java/org/onap/msb/sdk/httpclient/client/AnimalServiceClient.java deleted file mode 100644 index 22101ad..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/client/AnimalServiceClient.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - ******************************************************************************/ -package org.onap.msb.sdk.httpclient.client; - -import org.onap.msb.sdk.httpclient.annotaion.ServiceHttpEndPoint; -import org.onap.msb.sdk.httpclient.common.Animal; - -import retrofit2.Call; -import retrofit2.http.GET; -import retrofit2.http.Path; - -/** - * @author hu.rui - * - */ - -@ServiceHttpEndPoint(serviceName = "animals", serviceVersion = "v1", nameSpace = "javaAF") -public interface AnimalServiceClient { - - @GET("animals/{name}") - Call queryAnimal(@Path("name") String name); - -} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/client/ExampleClient.java b/example/src/main/java/org/onap/msb/sdk/httpclient/client/ExampleClient.java deleted file mode 100644 index 570078b..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/client/ExampleClient.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - ******************************************************************************/ -/** - * - */ -package org.onap.msb.sdk.httpclient.client; - -import java.io.IOException; - -import org.onap.msb.sdk.httpclient.RetrofitServiceCreater; -import org.onap.msb.sdk.httpclient.common.Animal; -import org.onap.msb.sdk.httpclient.conf.HttpClientConf; -import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; - - -public class ExampleClient { - - /** - * @param args - * @throws IOException - */ - public static void main(String[] args) throws IOException { - - HttpClientConf globalHttpClientConf = new HttpClientConf(); - MSBServiceWrapperClient msbClient = new MSBServiceWrapperClient("127.0.0.1", 10081); - - RetrofitServiceCreater retrofitServiceCreater = - new RetrofitServiceCreater(globalHttpClientConf, msbClient); - - AnimalServiceClient implProxy = - retrofitServiceCreater.createRetrofitService(AnimalServiceClient.class); - Animal animal = implProxy.queryAnimal("example").execute().body(); - System.out.println("animal:" + animal); - } - -} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/common/Animal.java b/example/src/main/java/org/onap/msb/sdk/httpclient/common/Animal.java deleted file mode 100644 index 092a2f7..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/common/Animal.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - ******************************************************************************/ -package org.onap.msb.sdk.httpclient.common; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Animal implements Serializable { - - private static final long serialVersionUID = -717235590728668809L; - - @JsonProperty - private String type; - - @JsonProperty - private String name; - - @JsonProperty - private int age; - - public Animal() {} - - public Animal(String type, String name, int age) { - this.type = type; - this.name = name; - this.age = age; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - @Override - public String toString() { - return "Animal{" + "type='" + type + '\'' + ", name='" + name + '\'' + ", age=" + age + '}'; - } -} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/server/Config.java b/example/src/main/java/org/onap/msb/sdk/httpclient/server/Config.java deleted file mode 100644 index 4dbb6eb..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/server/Config.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - ******************************************************************************/ -package org.onap.msb.sdk.httpclient.server; - -import io.dropwizard.Configuration; - -public class Config extends Configuration { - - - -} - - diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/server/ExampleApp.java b/example/src/main/java/org/onap/msb/sdk/httpclient/server/ExampleApp.java deleted file mode 100644 index 03c052a..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/server/ExampleApp.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - ******************************************************************************/ -package org.onap.msb.sdk.httpclient.server; - -import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; -import org.onap.msb.sdk.httpclient.server.resources.AnimalResource; - -import io.dropwizard.Application; -import io.dropwizard.setup.Environment; - - -public class ExampleApp extends Application { - - private static final String CONFIGURATION_FILE = "example.yml"; - - public static void main(String[] args) throws Exception { - - String configFile = null; - if (args.length > 1) { - configFile = args[0]; - } else { - configFile = ExampleApp.class.getClassLoader().getResource(CONFIGURATION_FILE).getFile(); - } - args = new String[] {"server", configFile}; - new ExampleApp().run(args); - } - - @Override - public void run(Config configuration, Environment environment) throws Exception { - - environment.jersey().register(new AnimalResource()); - - MSBServiceWrapperClient msbClient = new MSBServiceWrapperClient("127.0.0.1", 10081); - - MsbHelper helper = new MsbHelper(msbClient); - helper.registerMsb(); - - } - -} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/server/MsbHelper.java b/example/src/main/java/org/onap/msb/sdk/httpclient/server/MsbHelper.java deleted file mode 100644 index ffaba08..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/server/MsbHelper.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - ******************************************************************************/ -package org.onap.msb.sdk.httpclient.server; - -import java.net.InetAddress; -import java.util.HashSet; -import java.util.Set; - -import org.jvnet.hk2.annotations.Service; -import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; -import org.onap.msb.sdk.discovery.entity.Node; -import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; - -/** - * @author hu.rui - * - */ -@Service -public class MsbHelper { - - private MSBServiceWrapperClient msbClient; - - - - public MsbHelper(MSBServiceWrapperClient msbClient) { - super(); - this.msbClient = msbClient; - } - - - - public void registerMsb() throws Exception { - - - MicroServiceInfo msinfo = new MicroServiceInfo(); - - msinfo.setServiceName("animals"); - msinfo.setVersion("v1"); - msinfo.setUrl("/api/rpc/v1"); - msinfo.setProtocol("REST"); - msinfo.setVisualRange("0|1"); - - Set nodes = new HashSet<>(); - Node node1 = new Node(); - node1.setIp(InetAddress.getLocalHost().getHostAddress()); - node1.setPort("9090"); - nodes.add(node1); - msinfo.setNodes(nodes); - msbClient.registerMicroServiceInfo(msinfo, false); - - } - - - -} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/server/resources/AnimalResource.java b/example/src/main/java/org/onap/msb/sdk/httpclient/server/resources/AnimalResource.java deleted file mode 100644 index 7a51c0f..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/server/resources/AnimalResource.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - ******************************************************************************/ -package org.onap.msb.sdk.httpclient.server.resources; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.onap.msb.sdk.httpclient.common.Animal; - - -@Path("/animals") -public class AnimalResource { - - - @GET - @Path("/{name}") - @Produces(MediaType.APPLICATION_JSON) - public Response query(@PathParam("name") String name) { - return Response.ok(new Animal("animal", name, (int) System.currentTimeMillis() % 10)).build(); - } - - -} diff --git a/src/main/java/org/onap/msb/sdk/discovery/entity/Node.java b/src/main/java/org/onap/msb/sdk/discovery/entity/Node.java index c28f232..1bdeab8 100644 --- a/src/main/java/org/onap/msb/sdk/discovery/entity/Node.java +++ b/src/main/java/org/onap/msb/sdk/discovery/entity/Node.java @@ -27,34 +27,6 @@ public class Node implements Serializable { private String ttl = ""; - // 负载均衡策略参数 - private String lb_server_params = ""; - - // 健康检查参数 - private String checkType = ""; - private String checkUrl = ""; - private String checkInterval = ""; - private String checkTimeOut = ""; - - private String ha_role = ""; - - - public String getHa_role() { - return ha_role; - } - - - /** - * @Title setHa_role - * @Description TODO(实例主备状态,取值范围:active,standby) - * @param ha_role - * @return void - */ - public void setHa_role(String ha_role) { - this.ha_role = ha_role; - } - - public String getIp() { return ip; @@ -80,7 +52,6 @@ public class Node implements Serializable { this.ttl = ttl; } - @Override public String toString() { // TODO Auto-generated method stub @@ -88,79 +59,4 @@ public class Node implements Serializable { .toString(); } - public String getLb_server_params() { - return lb_server_params; - } - - /** - * @Title setLb_server_params - * @Description TODO(针对协议为TCP或UDP的服务实例配置负载均衡参数)
- * 支持的server参数设置:
- * 1. weight: server的权重,不显式设置默认为1
- * 2. - * max_fails:在fail_timeout设置的时间间隔内,允许失败尝试的次数,不显式设置默认为1.比如fail_timeout=30s,max_fails=6,那表示在30s内如果6次连接失败,那认定该server为unavailable - *
- * 3. fail_timeout:判定server为unavailable的时间间隔。如果不显式设置,默认设置为10s - * @param lb_server_params (示例:weight=5,max_fails=3,fail_timeout=30s) - * @return void - */ - public void setLb_server_params(String lb_server_params) { - this.lb_server_params = lb_server_params; - } - - public String getCheckType() { - return checkType; - } - - /** - * @Title setCheckType - * @Description TODO(健康检查类型,可选范围:TTL,HTTP,TCP)
- * 1.HTTP保活由"MSB"每隔checkInterval时间向"服务提供方"发送 GET请求。如果请求返回任何2xx状态码,检测成功。
- * 2.TCP保活原理同HTTP,协议不同。
- * 3.TTL保活由"服务提供方"向"MSB"发送HTTP请求以保持联通状态,在checkInterval设置的时间间隔内未能收到保活请求,服务发现将此服务状态设置为无效。 - * @param checkType - * @return void - */ - public void setCheckType(String checkType) { - this.checkType = checkType; - } - - public String getCheckUrl() { - return checkUrl; - } - - /** - * @Title setCheckUrl - * @Description TODO(健康检查类型为HTTP或TCP,填写检查URL) - * @param checkUrl - * @return void - */ - public void setCheckUrl(String checkUrl) { - this.checkUrl = checkUrl; - } - - public String getCheckInterval() { - return checkInterval; - } - - /** - * @Title setCheckInterval - * @Description TODO(健康检查轮询时间,单位:秒) - * @param checkInterval - * @return void - */ - public void setCheckInterval(String checkInterval) { - this.checkInterval = checkInterval; - } - - - public String getCheckTimeOut() { - return checkTimeOut; - } - - - public void setCheckTimeOut(String checkTimeOut) { - this.checkTimeOut = checkTimeOut; - } - } diff --git a/src/main/java/org/onap/msb/sdk/discovery/entity/Service.java b/src/main/java/org/onap/msb/sdk/discovery/entity/Service.java index a89ded9..306e59b 100644 --- a/src/main/java/org/onap/msb/sdk/discovery/entity/Service.java +++ b/src/main/java/org/onap/msb/sdk/discovery/entity/Service.java @@ -22,54 +22,52 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class Service implements Serializable { private static final long serialVersionUID = 1L; - // 服务名[必填] + private String serviceName; - // 版本号 ( 格式:v(小写)+数字) + private String version = ""; - // 服务url (格式:url地址以/开头,不能以/结尾) + private String url = ""; - // 服务对应协议,比如REST、UI、HTTP、MQ、FTP、SNMP、TCP、UDP + + //REST、UI private String protocol = ""; - // 服务的可见范围 0:系统间 1:系统内 + //0: External 1: Internal private String visualRange = "1"; - // 负载均衡策略类型 private String lb_policy = ""; - - private String host = ""; - private String path = ""; private Set nodes; - // 服务自身属性的键值对 private List metadata; - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - public String getPath() { return path; } + /** + * The customized publish path of this service. + * If this parameter is specified when registering the service, the service will be published to api gateway under this path. + * Otherwise, the service will be published to api gateway using a fixed format: api/{serviceName} /{version}. + * Do not specific a path unless you know what you're doing. + * @param path + */ public void setPath(String path) { this.path = path; } + /** + * Load balancing method used when MSB routes the service requests. Currently, Round robin and IP hash are supported. + * @return + */ public String getLb_policy() { return lb_policy; } /** - * @Title setLb_policy - * @Description TODO(针对协议为TCP或UDP的服务选择负载均衡策略) - * @param lb_policy (可选策略:round-robin,ip_hash) + * Load balancing method used when MSB routes the service requests. Currently, Round robin and IP hash are supported. + * @param lb_policy (round-robin,ip_hash) * @return void */ public void setLb_policy(String lb_policy) { @@ -80,23 +78,19 @@ public class Service implements Serializable { return metadata; } - /** - * @Title setMetadata - * @Description TODO(配置服务特有的附加属性键值对) - * @param metadata - * @return void - */ public void setMetadata(List metadata) { this.metadata = metadata; } + /** + * The service instance nodes + */ public Set getNodes() { return nodes; } /** - * @Title setNodes - * @Description TODO(配置服务的服务器实例列表) + * The service instance nodes * @param nodes * @return void */ @@ -104,43 +98,47 @@ public class Service implements Serializable { this.nodes = nodes; } + /** + * An unique name of the service, it should be constant so the service consumer can access the service. + */ public String getServiceName() { return serviceName; } /** - * - * @Title setServiceName - * @Description TODO(服务名[必填]) + * An unique name of the service, it should be constant so the service consumer can access the service. * @param serviceName - * @return void */ public void setServiceName(String serviceName) { this.serviceName = serviceName; } + /** + * Service version. Only the major version of service is used in the URI. + * @return + */ public String getVersion() { return version; } /** - * - * @Title setVersion - * @Description TODO(版本号 ( 格式:v(小写)+数字)) + * Service version. Only the major version of service is used in the URI. * @param version - * @return void */ public void setVersion(String version) { this.version = version; } + /** + * The actual URL of the service to be registered. + * @return + */ public String getUrl() { return url; } /** - * @Title setUrl - * @Description TODO(目标服务URL地址 (格式:url地址以/开头,不能以/结尾)) + * The actual URL of the service to be registered. * @param url * @return void */ @@ -148,30 +146,36 @@ public class Service implements Serializable { this.url = url; } + /** + * supported protocols: 'REST', 'UI' + * @return + */ public String getProtocol() { return protocol; } /** - * @Title setProtocol - * @Description TODO(服务对应协议,比如REST、MQ、FTP、SNMP[必填]) + * supported protocols: 'REST', 'UI' * @param protocol - * @return void */ public void setProtocol(String protocol) { this.protocol = protocol; } - + /** + * Visibility of the service. + * External(can be accessed by external systems):0 + * Internal(can only be accessed by ONAP microservices):1 + */ public String getVisualRange() { return visualRange; } /** - * @Title setVisualRange - * @Description TODO(服务的可见范围 系统间:0 系统内:1 ,多个可见范围用 "|"分隔,如"0|1" ) + * Visibility of the service. + * External(can be accessed by external systems):0 + * Internal(can only be accessed by ONAP microservices):1 * @param visualRange - * @return void */ public void setVisualRange(String visualRange) { this.visualRange = visualRange; -- cgit 1.2.3-korg