Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Tacker Vnf - Attributes & TackerError Propagation.. #814

Merged
merged 4 commits into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ParseActionResponseFromJsonMap implements Function<Map<String, Obje
private static final String KEY_MESSAGE = "message";
private static final String NEUTRON_ERROR = "NeutronError";
private static final String COMPUTE_FAULT = "computeFault";
private static final String TACKER_ERROR = "TackerError";
private HttpResponse response;

public ParseActionResponseFromJsonMap(HttpResponse response) {
Expand Down Expand Up @@ -52,6 +53,11 @@ public ActionResponse apply(Map<String, Object> 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());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -47,66 +106,31 @@ public String getServiceType() {
return serviceType;
}

/**
* @param serviceType the serviceType to set
*/
public void setServiceType(String serviceType) {
this.serviceType = serviceType;
}

/**
* @return the paramValues
*/
public String getParamValues() {
return paramValues;
}

/**
* @param paramValues the paramValues to set
*/
public void setParamValues(String paramValues) {
this.paramValues = paramValues;
}

/**
* @return the heatTemplate
*/
public String getHeatTemplate() {
return heatTemplate;
}

/**
* @param heatTemplate the heatTemplate to set
*/
public void setHeatTemplate(String heatTemplate) {
this.heatTemplate = heatTemplate;
}

/**
* @return the monitoringPolicy
*/
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.<TackerVim>create(PropagateOnStatus.on(404)));
return post(TackerVim.class, uri("/vims")).entity(vim).execute(ExecutionOptions.<TackerVim>create(PropagateOnStatus.on(500)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<TackerVnf>create(PropagateOnStatus.on(404)));
return post(TackerVnf.class, uri("/vnfs")).entity(vnf).execute(ExecutionOptions.<TackerVnf>create(PropagateOnStatus.on(500)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<TackerVnfd>create(PropagateOnStatus.on(404)));
return post(TackerVnfd.class, uri("/vnfds")).entity(vnfd).execute(ExecutionOptions.<TackerVnfd>create(PropagateOnStatus.on(500)));
}
}