Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2013-2014 Dell, Inc ==================================================================== 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.dasein.cloud.azure.compute;
 
 
 import  javax.annotation.Nonnull;
Created by Vlad_Munthiu on 7/23/2014.
 
 public class AzureAffinityGroupSupport implements AffinityGroupSupport {
     private Azure provider;
 
     static private final Logger logger = Logger.getLogger(AzureAffinityGroupSupport.class);
 
     public static final String RESOURCE_AFFINITYGROUPS = "/affinitygroups";
     public static final String RESOURCE_AFFINITYGROUP = "/affinitygroups/%s";
 
     public AzureAffinityGroupSupport(@Nonnull Azure provider) { this. = provider; }
    
Creates an affinity group in the cloud

Parameters:
options the options used when creating the affinity group
Returns:
the provider ID of the affinity group
Throws:
org.dasein.cloud.InternalException an error occurred within the Dasein Cloud implementation creating the affinity group
org.dasein.cloud.CloudException an error occurred within the service provider creating the affinity group
 
     @Nonnull
     @Override
     public AffinityGroup create(@Nonnull AffinityGroupCreateOptions optionsthrows InternalExceptionCloudException {
 
         if(options == null && options.getName() == null)
             throw new InternalException("Cannot create AffinityGroup. Create options or affinity group name cannot be null.");
 
         CreateAffinityGroupModel createAffinityGroupModel = new CreateAffinityGroupModel();
         createAffinityGroupModel.setName(options.getName());
         createAffinityGroupModel.setDescription(options.getDescription());
         createAffinityGroupModel.setLocation(.getContext().getRegionId());
         createAffinityGroupModel.setLabel(new String(Base64.encodeBase64(options.getName().getBytes())));
 
         AzureMethod azureMethod = new AzureMethod(this.);
 
         try {
             azureMethod.post(createAffinityGroupModel);
         }
         catch (JAXBException e)
         {
             .error(e.getMessage());
             throw new InternalException(e);
         }
 
         return AffinityGroup.getInstance(createAffinityGroupModel.getName(),
                 createAffinityGroupModel.getName(),
                 createAffinityGroupModel.getDescription(),
                 createAffinityGroupModel.getLocation(), null);
     }

    
Deletes the affinity group from the cloud if the affinity group is not empty this method should error

Parameters:
affinityGroupId the ID of the affinity group to be deleted
Throws:
org.dasein.cloud.InternalException an error occurred within the Dasein Cloud implementation deleting the affinity group
org.dasein.cloud.CloudException an error occurred within the service provider deleting the affinity group
 
     @Override
     public void delete(@Nonnull String affinityGroupIdthrows InternalExceptionCloudException {
        if(affinityGroupId == null || affinityGroupId.isEmpty())
            throw new InternalException("Cannot delete affinity group. Please specify the id for the affinity group to remove");
        AzureMethod method = new AzureMethod(this.);
        method.invoke("DELETE"this..getContext().getAccountNumber(), String.format(affinityGroupId), null);
    }

    
Retrieves the details of the specified Affinity Group from the cloud

Parameters:
affinityGroupId the ID of the affinity group to be retrieved
Returns:
the Dasein AffinityGroup object
Throws:
org.dasein.cloud.InternalException an error occurred within the Dasein Cloud implementation retrieving the affinity group
org.dasein.cloud.CloudException an error occurred within the service provider retrieving the affinity group
    @Nonnull
    @Override
    public AffinityGroup get(@Nonnull String affinityGroupIdthrows InternalExceptionCloudException {
        if(affinityGroupId == null || affinityGroupId.isEmpty())
            throw new InternalException("Please specify the id for the affinity group you want to retrieve.");
        AzureMethod method = new AzureMethod(this.);
        final AffinityGroupModel affinityGroupModel = method.get(AffinityGroupModel.class, String.format(affinityGroupId));
        //TODO see if name is enough to be used as an id
        return AffinityGroup.getInstance(affinityGroupModel.getName(),affinityGroupModel.getName(),affinityGroupModel.getDescription(), affinityGroupModel.getLocation(), null);
    }

    
Lists all of the affinity groups visible to the current account

Parameters:
options Filtering options for the list
Returns:
All the affinity groups visible to current account
Throws:
org.dasein.cloud.InternalException an error occurred within the Dasein Cloud implementation listing the affinity groups
org.dasein.cloud.CloudException an error occurred within the service provider listing the affinity groups
    @Nonnull
    @Override
    public Iterable<AffinityGrouplist(@Nonnull AffinityGroupFilterOptions optionsthrows InternalExceptionCloudException {
        AzureMethod method = new AzureMethod(this.);
        final AffinityGroupsModel affinityGroupsModel = method.get(AffinityGroupsModel.class);
        ArrayList<AffinityGroupaffinityGroups = new ArrayList<AffinityGroup>();
        for(AffinityGroupModel affinityGroupModel : affinityGroupsModel.getAffinityGroups())
        {
            //TODO see if name is enough to be used as an id
            AffinityGroup affinityGroup = AffinityGroup.getInstance(affinityGroupModel.getName(),affinityGroupModel.getName(),affinityGroupModel.getDescription(), affinityGroupModel.getLocation(), null);
            if(options != null && options.matches(affinityGroup))
                affinityGroups.add(affinityGroup);
        }
        return affinityGroups;
    }

    
Modifies details of the specified affinity group

Parameters:
affinityGroupId the ID of the affinity group to be modified
options the options containing the modified data
Returns:
the newly modified Dasein AffinityGroup object
Throws:
org.dasein.cloud.InternalException an error occurred within the Dasein Cloud implementation modifying the affinity group
org.dasein.cloud.CloudException an error occurred within the service provider modifying the affinity group
    @Override
    public AffinityGroup modify(@Nonnull String affinityGroupId, @Nonnull AffinityGroupCreateOptions optionsthrows InternalExceptionCloudException {
        if(affinityGroupId == null|| affinityGroupId.isEmpty())
            throw new InternalException("Cannot modify an affinity group: affinityGroupId cannot be null or empty");
        if(options == null && options.getDescription() == null)
            throw new InternalException("Cannot create AffinityGroup. Create options or affinity group description cannot be null.");
        UpdateAffinityGroupModel updateAffinityGroupModel = new UpdateAffinityGroupModel();
        updateAffinityGroupModel.setDescription(options.getDescription());
        AzureMethod method = new AzureMethod(this.);
        try {
            method.put(String.format(affinityGroupId), updateAffinityGroupModel);
        }
        catch (JAXBException e)
        {
            .error(e.getMessage());
            throw new InternalException(e);
        }
        return get(affinityGroupId);
    }

    
Maps the specified Dasein Cloud service action to an identifier specific to an underlying cloud. If there is no mapping that makes any sense, the method will return an empty array.

Parameters:
action the Dasein Cloud service action
Returns:
a list of cloud-specific IDs (e.g. iam:ListGroups) representing an action with this cloud provider
    @Nonnull
    @Override
    public String[] mapServiceAction(@Nonnull ServiceAction action) {
        return new String[0];
    }
New to GrepCode? Check out our FAQ X