Search in sources :

Example 6 with OS4JException

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;
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) OS4JException(org.openstack4j.api.exceptions.OS4JException)

Example 7 with OS4JException

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);
    }
}
Also used : OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) Subnet(org.openstack4j.model.network.Subnet) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView) OS4JException(org.openstack4j.api.exceptions.OS4JException)

Example 8 with OS4JException

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);
    }
}
Also used : OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView) OS4JException(org.openstack4j.api.exceptions.OS4JException) ActionResponse(org.openstack4j.model.common.ActionResponse)

Example 9 with OS4JException

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);
    }
}
Also used : OS4JException(org.openstack4j.api.exceptions.OS4JException) Map(java.util.Map)

Example 10 with OS4JException

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);
    }
}
Also used : OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) OS4JException(org.openstack4j.api.exceptions.OS4JException) ActionResponse(org.openstack4j.model.common.ActionResponse)

Aggregations

OS4JException (org.openstack4j.api.exceptions.OS4JException)17 OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)15 ActionResponse (org.openstack4j.model.common.ActionResponse)8 NeutronNetworkView (com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)7 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)5 ArrayList (java.util.ArrayList)2 Server (org.openstack4j.model.compute.Server)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)1 ResourceStatus (com.sequenceiq.cloudbreak.cloud.model.ResourceStatus)1 SecurityRule (com.sequenceiq.cloudbreak.cloud.model.SecurityRule)1 CinderVolumeView (com.sequenceiq.cloudbreak.cloud.openstack.view.CinderVolumeView)1 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)1 NovaInstanceView (com.sequenceiq.cloudbreak.cloud.openstack.view.NovaInstanceView)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)1 ComputeSecurityGroupService (org.openstack4j.api.compute.ComputeSecurityGroupService)1 BlockDeviceMappingCreate (org.openstack4j.model.compute.BlockDeviceMappingCreate)1 FloatingIP (org.openstack4j.model.compute.FloatingIP)1