use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class AbstractOpenStackResourceBuilder method checkResources.
protected List<CloudResourceStatus> checkResources(ResourceType type, OpenStackContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
List<CloudResourceStatus> result = new ArrayList<>();
for (CloudResource resource : resources) {
LOGGER.info("Check {} resource: {}", type, resource);
try {
boolean finished = checkStatus(context, auth, resource);
ResourceStatus successStatus = context.isBuild() ? ResourceStatus.CREATED : ResourceStatus.DELETED;
result.add(new CloudResourceStatus(resource, finished ? successStatus : ResourceStatus.IN_PROGRESS));
if (finished) {
if (successStatus == ResourceStatus.CREATED) {
LOGGER.info("Creation of {} was successful", resource);
} else {
LOGGER.info("Deletion of {} was successful", resource);
}
}
} catch (OS4JException ex) {
throw new OpenStackResourceException("Error during status check", type, resource.getName(), ex);
}
}
return result;
}
use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class OpenStackSubnetResourceBuilder method build.
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) {
try {
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String subnetId = neutronView.isExistingSubnet() ? neutronView.getCustomSubnetId() : context.getParameter(SUBNET_ID, String.class);
if (!neutronView.isExistingSubnet()) {
OSClient<?> osClient = createOSClient(auth);
NeutronNetworkView networkView = new NeutronNetworkView(network);
Subnet subnet = Builders.subnet().name(resource.getName()).networkId(context.getParameter(OpenStackConstants.NETWORK_ID, String.class)).tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)).ipVersion(IPVersionType.V4).cidr(networkView.getSubnetCIDR()).enableDHCP(true).build();
subnetId = osClient.networking().subnet().create(subnet).getId();
}
context.putParameter(SUBNET_ID, subnetId);
return createPersistedResource(resource, subnetId);
} catch (OS4JException ex) {
throw new OpenStackResourceException("Subnet creation failed", resourceType(), resource.getName(), ex);
}
}
use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class OpenStackSubnetResourceBuilder method delete.
@Override
public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) {
try {
NeutronNetworkView neutronView = new NeutronNetworkView(network);
if (!neutronView.isExistingSubnet()) {
OSClient<?> osClient = createOSClient(auth);
ActionResponse response = osClient.networking().subnet().delete(resource.getReference());
return checkDeleteResponse(response, resourceType(), auth, resource, "Subnet deletion failed");
}
return null;
} catch (OS4JException ex) {
throw new OpenStackResourceException("Subnet deletion failed", resourceType(), resource.getName(), ex);
}
}
use of org.openstack4j.api.exceptions.OS4JException in project openstack4j by ContainX.
the class BaseOpenStackService method builder.
@SuppressWarnings("rawtypes")
private <R> Invocation<R> builder(Class<R> returnType, String path, HttpMethod method) {
OSClientSession ses = OSClientSession.getCurrent();
if (ses == null) {
throw new OS4JException("Unable to retrieve current session. Please verify thread has a current session available.");
}
RequestBuilder<R> req = HttpRequest.builder(returnType).endpointTokenProvider(ses).config(ses.getConfig()).method(method).path(path);
Map headers = ses.getHeaders();
if (headers != null && headers.size() > 0) {
return new Invocation<R>(req, serviceType, endpointFunc).headers(headers);
} else {
return new Invocation<R>(req, serviceType, endpointFunc);
}
}
use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class OpenStackAttachedDiskResourceBuilder method delete.
@Override
public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) {
try {
OSClient<?> osClient = createOSClient(auth);
ActionResponse response = osClient.blockStorage().volumes().delete(resource.getReference());
return checkDeleteResponse(response, resourceType(), auth, resource, "Volume deletion failed");
} catch (OS4JException ex) {
throw new OpenStackResourceException("Volume deletion failed", resourceType(), resource.getName(), ex);
}
}
Aggregations