From b62894d19d14d276661b1adb7ca4bdf5f99e287b Mon Sep 17 00:00:00 2001 From: vdeshmukh Date: Thu, 15 Sep 2016 15:47:46 -0700 Subject: [PATCH 1/4] Added Tacker Vnf - Attributes create method.. * Added missing `Tacker Vnf` `static create()` method for setting `Vnf Attributes`.. --- .../tacker/domain/VnfAttributes.java | 94 ++++++++++++------- 1 file changed, 59 insertions(+), 35 deletions(-) diff --git a/core/src/main/java/org/openstack4j/openstack/tacker/domain/VnfAttributes.java b/core/src/main/java/org/openstack4j/openstack/tacker/domain/VnfAttributes.java index 1693b8278..c5db5776b 100644 --- a/core/src/main/java/org/openstack4j/openstack/tacker/domain/VnfAttributes.java +++ b/core/src/main/java/org/openstack4j/openstack/tacker/domain/VnfAttributes.java @@ -29,6 +29,65 @@ public class VnfAttributes { @JsonProperty("failure_policy") private String failurePolicy; + public static VnfAttributes create() { + return new VnfAttributes(); + } + + /** + * serviceType to Set.. + * + * @param serviceType the serviceType to set + * @return VnfAttributes + */ + public VnfAttributes serviceType(String serviceType) { + this.serviceType = serviceType; + return this; + } + + /** + * paramValues to Set.. + * + * @param paramValues the paramValues to set + * @return VnfAttributes + */ + public VnfAttributes paramValues(String paramValues) { + this.paramValues = paramValues; + return this; + } + + /** + * heatTemplate to Set.. + * + * @param heatTemplate the heatTemplate to set + * @return VnfAttributes + */ + public VnfAttributes heatTemplate(String heatTemplate) { + this.heatTemplate = heatTemplate; + return this; + } + + /** + * monitoringPolicy to Set.. + * + * @param monitoringPolicy the monitoringPolicy to set + * @return VnfAttributes + */ + public VnfAttributes monitoringPolicy(String monitoringPolicy) { + this.monitoringPolicy = monitoringPolicy; + return this; + } + + /** + * failurePolicy to Set.. + * + * @param failurePolicy the failurePolicy to set + * @return VnfAttributes + */ + public VnfAttributes failurePolicy(String failurePolicy) { + this.failurePolicy = failurePolicy; + return this; + } + @Override public String toString() { return Objects.toStringHelper(this).omitNullValues() @@ -47,13 +106,6 @@ public String getServiceType() { return serviceType; } - /** - * @param serviceType the serviceType to set - */ - public void setServiceType(String serviceType) { - this.serviceType = serviceType; - } - /** * @return the paramValues */ @@ -61,13 +113,6 @@ public String getParamValues() { return paramValues; } - /** - * @param paramValues the paramValues to set - */ - public void setParamValues(String paramValues) { - this.paramValues = paramValues; - } - /** * @return the heatTemplate */ @@ -75,13 +120,6 @@ public String getHeatTemplate() { return heatTemplate; } - /** - * @param heatTemplate the heatTemplate to set - */ - public void setHeatTemplate(String heatTemplate) { - this.heatTemplate = heatTemplate; - } - /** * @return the monitoringPolicy */ @@ -89,24 +127,10 @@ public String getMonitoringPolicy() { return monitoringPolicy; } - /** - * @param monitoringPolicy the monitoringPolicy to set - */ - public void setMonitoringPolicy(String monitoringPolicy) { - this.monitoringPolicy = monitoringPolicy; - } - /** * @return the failurePolicy */ public String getFailurePolicy() { return failurePolicy; } - - /** - * @param failurePolicy the failurePolicy to set - */ - public void setFailurePolicy(String failurePolicy) { - this.failurePolicy = failurePolicy; - } } From 6bae0051cba868c0a23935597c4844dd39b1891d Mon Sep 17 00:00:00 2001 From: vdeshmukh Date: Thu, 15 Sep 2016 18:32:18 -0700 Subject: [PATCH 2/4] TackerError propagation support is now added.. * `TackerError` is now propagated.. * Currently `propagating` for `register - vim` call on status `500`.. * Currently there is no way to propagate `404` status as well.. --- .../transport/functions/ParseActionResponseFromJsonMap.java | 6 ++++++ .../openstack/tacker/internal/VimServiceImpl.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/openstack4j/core/transport/functions/ParseActionResponseFromJsonMap.java b/core/src/main/java/org/openstack4j/core/transport/functions/ParseActionResponseFromJsonMap.java index 47697c58a..f5f895ba1 100644 --- a/core/src/main/java/org/openstack4j/core/transport/functions/ParseActionResponseFromJsonMap.java +++ b/core/src/main/java/org/openstack4j/core/transport/functions/ParseActionResponseFromJsonMap.java @@ -17,6 +17,7 @@ public class ParseActionResponseFromJsonMap implements Function map) { String msg = String.valueOf(map.get(COMPUTE_FAULT)); return ActionResponse.actionFailed(msg, response.getStatus()); } + if (inner.containsKey(TACKER_ERROR)) { + /** For 'TackerError' Error Message Propagation.. */ + String msg = String.valueOf(inner.get(TACKER_ERROR)); + return ActionResponse.actionFailed(msg, response.getStatus()); + } } } diff --git a/core/src/main/java/org/openstack4j/openstack/tacker/internal/VimServiceImpl.java b/core/src/main/java/org/openstack4j/openstack/tacker/internal/VimServiceImpl.java index eb4c1adf2..788cf748a 100644 --- a/core/src/main/java/org/openstack4j/openstack/tacker/internal/VimServiceImpl.java +++ b/core/src/main/java/org/openstack4j/openstack/tacker/internal/VimServiceImpl.java @@ -66,7 +66,7 @@ public ActionResponse delete(String vimId) { */ @Override public Vim register(Vim vim) { - return post(TackerVim.class, uri("/vims")).entity(vim).execute(ExecutionOptions.create(PropagateOnStatus.on(404))); + return post(TackerVim.class, uri("/vims")).entity(vim).execute(ExecutionOptions.create(PropagateOnStatus.on(500))); } /** From 0969c8588879ae76ec112bea71397a8d8f1be9e6 Mon Sep 17 00:00:00 2001 From: vdeshmukh Date: Thu, 15 Sep 2016 18:53:22 -0700 Subject: [PATCH 3/4] Tacker Create Error Propagation.. * Added `500` status error propagation for `Vnf` and `Vnfd` Create call.. --- .../openstack4j/openstack/tacker/internal/VnfServiceImpl.java | 2 +- .../openstack4j/openstack/tacker/internal/VnfdServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/openstack4j/openstack/tacker/internal/VnfServiceImpl.java b/core/src/main/java/org/openstack4j/openstack/tacker/internal/VnfServiceImpl.java index 3bae66dcf..aa1b662aa 100644 --- a/core/src/main/java/org/openstack4j/openstack/tacker/internal/VnfServiceImpl.java +++ b/core/src/main/java/org/openstack4j/openstack/tacker/internal/VnfServiceImpl.java @@ -67,7 +67,7 @@ public ActionResponse delete(String vnfId) { */ @Override public Vnf create(Vnf vnf) { - return post(TackerVnf.class, uri("/vnfs")).entity(vnf).execute(ExecutionOptions.create(PropagateOnStatus.on(404))); + return post(TackerVnf.class, uri("/vnfs")).entity(vnf).execute(ExecutionOptions.create(PropagateOnStatus.on(500))); } /** diff --git a/core/src/main/java/org/openstack4j/openstack/tacker/internal/VnfdServiceImpl.java b/core/src/main/java/org/openstack4j/openstack/tacker/internal/VnfdServiceImpl.java index 5989d4d16..9e6afd63e 100644 --- a/core/src/main/java/org/openstack4j/openstack/tacker/internal/VnfdServiceImpl.java +++ b/core/src/main/java/org/openstack4j/openstack/tacker/internal/VnfdServiceImpl.java @@ -63,6 +63,6 @@ public ActionResponse delete(String vnfdId) { @Override public Vnfd create(Vnfd vnfd) { - return post(TackerVnfd.class, uri("/vnfds")).entity(vnfd).execute(ExecutionOptions.create(PropagateOnStatus.on(404))); + return post(TackerVnfd.class, uri("/vnfds")).entity(vnfd).execute(ExecutionOptions.create(PropagateOnStatus.on(500))); } } From 6160624e2fd1879139a477cb7682e097aad2a682 Mon Sep 17 00:00:00 2001 From: vdeshmukh Date: Mon, 19 Sep 2016 16:12:08 -0700 Subject: [PATCH 4/4] Added Test Case for Vim Register.. * Added `testRegisterVimWithTackerError` method for `simulating` an `TackerError`.. --- .../api/tacker/v1/TackerVimTests.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core-test/src/main/java/org/openstack4j/api/tacker/v1/TackerVimTests.java b/core-test/src/main/java/org/openstack4j/api/tacker/v1/TackerVimTests.java index 145fb4793..1086ef33b 100644 --- a/core-test/src/main/java/org/openstack4j/api/tacker/v1/TackerVimTests.java +++ b/core-test/src/main/java/org/openstack4j/api/tacker/v1/TackerVimTests.java @@ -10,10 +10,12 @@ import org.openstack4j.api.AbstractTest; import org.openstack4j.api.Builders; +import org.openstack4j.api.exceptions.ServerResponseException; import org.openstack4j.model.common.ActionResponse; import org.openstack4j.model.tacker.Vim; import org.openstack4j.openstack.tacker.domain.AuthCredentials; import org.openstack4j.openstack.tacker.domain.VimProject; +import org.testng.Assert; import org.testng.annotations.Test; import com.google.common.base.Preconditions; @@ -80,6 +82,36 @@ public void testRegisterVim() throws IOException { assertEquals("test-vim", vim.getName()); } + @Test(expectedExceptions = ServerResponseException.class) + public void testRegisterVimWithTackerError() throws IOException { + String jsonResponse = "{\"TackerError\": {" + + "\"message\": \"'project_domain_name' is missing.\", " + + "\"code\": 500}}"; + + respondWith(500, jsonResponse); + + VimProject vimProject = VimProject.create().name("admin"); + + AuthCredentials authCredentials = AuthCredentials.create() + .username("admin") + .password("password") + .userDomainName("default"); + + Vim vim = Builders.tacker().vim() + .name("test-vim") + .description("test-vim-description") + .authUrl("http://openstack.os4j.com:35357/v3") + .isDefault(Boolean.TRUE) + .type("openstack") + .vimProject(vimProject) + .authCredentials(authCredentials) + .build(); + + vim = osv3().tacker().vim().register(vim); + System.out.println("THROWING EXCEPTIONNNNNNNNN"); + Assert.fail("Exception should have been thrown."); + } + public void testDeleteVim() throws IOException { respondWith(200); ActionResponse result = osv3().tacker().vim().delete("bad2f397-7436-4fc7-8043-726e173c5d30");