Examples of IaasProvider


Examples of org.apache.stratos.cloud.controller.pojo.IaasProvider

public class IaasProviderConfigParser {
    private static final Log log = LogFactory.getLog(IaasProviderConfigParser.class);

    public static IaasProvider getIaasProvider(final String fileName, final OMElement elt, final OMNode item, List<IaasProvider> iaases) {

        IaasProvider iaas = null;

        if (item.getType() == OMNode.ELEMENT_NODE) {

            OMElement iaasElt = (OMElement) item;

            if (iaases != null) {
                // check whether this is a reference to a predefined IaaS.
                for (IaasProvider iaasProvider : iaases) {
                    if (iaasProvider.getType()
                            .equals(iaasElt.getAttribute(new QName(
                                    CloudControllerConstants.TYPE_ATTR))
                                    .getAttributeValue())) {
                        iaas = new IaasProvider(iaasProvider);
                        break;
                    }
                }
            }

            if (iaas == null) {
                iaas = new IaasProvider();
            }

            if (iaas.getType() == null) {
                iaas.setType(iaasElt.getAttribute(new QName(CloudControllerConstants.TYPE_ATTR))
                        .getAttributeValue());
            }

            if ("".equals(iaas.getType())) {
                String msg =
                        "'" + CloudControllerConstants.IAAS_PROVIDER_ELEMENT + "' element's '" +
                                CloudControllerConstants.TYPE_ATTR +
                                "' attribute should be specified!";

                handleException(msg);

            }

            // this is not mandatory
            String name =
                    (iaasElt.getAttribute(new QName(CloudControllerConstants.NAME_ATTR)) == null)
                            ? iaas.getName()
                            : iaasElt.getAttributeValue(new QName(
                            CloudControllerConstants.NAME_ATTR));

            iaas.setName(name);

            String xpath = CloudControllerConstants.IAAS_PROVIDER_ELEMENT_XPATH;

            // load other elements
            loadClassName(fileName, iaas, iaasElt);
            loadProvider(fileName, iaas, iaasElt);
            loadProperties(fileName, iaasElt, iaas.getProperties());
            loadTemplate(fileName, iaas, iaasElt);
            loadIdentity(fileName, elt, iaas, iaasElt);
            loadCredentials(fileName, elt, iaas, iaasElt, xpath);
        }
View Full Code Here

Examples of org.apache.stratos.cloud.controller.pojo.IaasProvider

  }

  @Override
  public void buildComputeServiceAndTemplate() {

    IaasProvider iaasInfo = getIaasProvider();
   
    // builds and sets Compute Service
    ComputeServiceBuilderUtil.buildDefaultComputeService(iaasInfo);

    // builds and sets Template
View Full Code Here

Examples of org.apache.stratos.cloud.controller.pojo.IaasProvider

    buildTemplate();

  }

  public void buildTemplate() {
    IaasProvider iaasInfo = getIaasProvider();
   
    if (iaasInfo.getComputeService() == null) {
      String msg = "Compute service is null for IaaS provider: "
          + iaasInfo.getName();
      log.fatal(msg);
      throw new CloudControllerException(msg);
    }

    TemplateBuilder templateBuilder = iaasInfo.getComputeService()
        .templateBuilder();

    // set image id specified
    templateBuilder.imageId(iaasInfo.getImage());

    // build the Template
    Template template = templateBuilder.build();

    // if you wish to auto assign IPs, instance spawning call should be
    // blocking, but if you
    // wish to assign IPs manually, it can be non-blocking.
    // is auto-assign-ip mode or manual-assign-ip mode? - default mode is
    // non-blocking
    boolean blockUntilRunning = Boolean.parseBoolean(iaasInfo
        .getProperty("autoAssignIp"));
    template.getOptions().as(TemplateOptions.class)
        .blockUntilRunning(blockUntilRunning);

    // this is required in order to avoid creation of additional security
    // groups by Jclouds.
    template.getOptions().as(TemplateOptions.class)
        .inboundPorts(22, 80, 8080, 443, 8243);

    template.getOptions().as(VCloudTemplateOptions.class)
        .ipAddressAllocationMode(IpAddressAllocationMode.POOL);

    // set Template
    iaasInfo.setTemplate(template);
  }
View Full Code Here

Examples of org.apache.stratos.cloud.controller.pojo.IaasProvider

  }

  @Override
  public void setDynamicPayload() {
    // in vCloud case we need to run a script
    IaasProvider iaasInfo = getIaasProvider();

    if (iaasInfo.getTemplate() == null || iaasInfo.getPayload() == null) {
      if (log.isDebugEnabled()) {
        log.debug("Payload for vCloud not found");
      }
      return;
    }

    String shellType = iaasInfo.getProperty(SHELL_TYPE);

    if (shellType == null || shellType.isEmpty()) {
      if (log.isDebugEnabled()) {
        log.debug("Shell Type for vCloud Customization script not found from properties");
      }
      return;
    }

    if (log.isDebugEnabled()) {
      log.debug(String.format("Shell Type '%s' will be used for vCloud Customization script", shellType));
    }

    // Payload is a String value
    String payload = new String(iaasInfo.getPayload());

    if (log.isDebugEnabled()) {
      log.debug(String.format("Payload '%s' will be used for vCloud Customization script", payload));
    }

    Template template = iaasInfo.getTemplate();

    File scriptPath = new File(CarbonUtils.getCarbonConfigDirPath(), SCRIPTS_PATH);

    File customizationScriptFile = new File(new File(scriptPath, shellType), CUSTOMIZATION_SCRIPT);
View Full Code Here

Examples of org.apache.stratos.cloud.controller.pojo.IaasProvider

    buildTemplate();

  }

  public void buildTemplate() {
    IaasProvider iaasInfo = getIaasProvider();
    if (iaasInfo.getComputeService() == null) {
      String msg = "Compute service is null for IaaS provider: "
          + iaasInfo.getName();
      log.fatal(msg);
      throw new CloudControllerException(msg);
    }

    TemplateBuilder templateBuilder = iaasInfo.getComputeService()
        .templateBuilder();

    // set image id specified
    templateBuilder.imageId(iaasInfo.getImage());

        if(!(iaasInfo instanceof IaasProvider)) {
           templateBuilder.locationId(iaasInfo.getType());
        }

        if(iaasInfo.getProperty(CloudControllerConstants.AVAILABILITY_ZONE) != null) {
            Set<? extends Location> locations = iaasInfo.getComputeService().listAssignableLocations();
            for(Location location : locations) {
                if(location.getScope().toString().equalsIgnoreCase(CloudControllerConstants.ZONE_ELEMENT) &&
                        location.getId().equals(iaasInfo.getProperty(CloudControllerConstants.AVAILABILITY_ZONE))) {
                    templateBuilder.locationId(location.getId());
                    log.info("ZONE has been set as " + iaasInfo.getProperty(CloudControllerConstants.AVAILABILITY_ZONE)
                            + " with id: " + location.getId());
                    break;
                }
            }
        }

    if (iaasInfo.getProperty(CloudControllerConstants.INSTANCE_TYPE) != null) {
      // set instance type eg: m1.large
      templateBuilder.hardwareId(iaasInfo.getProperty(CloudControllerConstants.INSTANCE_TYPE));
    }

    // build the Template
    Template template = templateBuilder.build();

        if(iaasInfo.getProperty(CloudControllerConstants.AVAILABILITY_ZONE) != null) {
            if(!template.getLocation().getId().equals(iaasInfo.getProperty(CloudControllerConstants.AVAILABILITY_ZONE))) {
                log.warn("couldn't find assignable ZONE of id :" +
                        iaasInfo.getProperty(CloudControllerConstants.AVAILABILITY_ZONE) + " in the IaaS. " +
                        "Hence using the default location as " + template.getLocation().getScope().toString() +
                        " with the id " + template.getLocation().getId());
            }
        }

    // if you wish to auto assign IPs, instance spawning call should be
    // blocking, but if you
    // wish to assign IPs manually, it can be non-blocking.
    // is auto-assign-ip mode or manual-assign-ip mode?
    boolean blockUntilRunning = Boolean.parseBoolean(iaasInfo
        .getProperty(CloudControllerConstants.AUTO_ASSIGN_IP));
    template.getOptions().as(TemplateOptions.class)
        .blockUntilRunning(blockUntilRunning);

    // this is required in order to avoid creation of additional security
    // groups by jclouds.
    template.getOptions().as(TemplateOptions.class)
        .inboundPorts(new int[] {});

    // set EC2 specific options


        if (iaasInfo.getProperty(CloudControllerConstants.ASSOCIATE_PUBLIC_IP_ADDRESS) != null) {
              boolean associatePublicIp =  Boolean.parseBoolean(iaasInfo.getProperty(
                      CloudControllerConstants.ASSOCIATE_PUBLIC_IP_ADDRESS));
            if(associatePublicIp){
                  template.getOptions().as(AWSEC2TemplateOptions.class)
                      .associatePublicIpAddress();
              }
        }

    if (iaasInfo.getProperty(CloudControllerConstants.SUBNET_ID) != null) {
      template.getOptions().as(AWSEC2TemplateOptions.class)
          .subnetId(iaasInfo.getProperty(CloudControllerConstants.SUBNET_ID));
    }

    if (iaasInfo.getProperty(CloudControllerConstants.AVAILABILITY_ZONE) != null) {
      template.getOptions().as(AWSEC2TemplateOptions.class)
          .placementGroup(iaasInfo.getProperty(CloudControllerConstants.AVAILABILITY_ZONE));
    }

        // security group names
    if (iaasInfo.getProperty(CloudControllerConstants.SECURITY_GROUPS) != null) {
      template.getOptions()
          .as(AWSEC2TemplateOptions.class)
          .securityGroups(iaasInfo.getProperty(CloudControllerConstants.SECURITY_GROUPS).split(
                            CloudControllerConstants.ENTRY_SEPARATOR));

    }

        // ability to define tags
        if (iaasInfo.getProperty(CloudControllerConstants.TAGS) != null) {
            template.getOptions()
                    .as(AWSEC2TemplateOptions.class)
                    .tags(Arrays.asList(iaasInfo.getProperty(CloudControllerConstants.TAGS)
                                        .split(CloudControllerConstants.ENTRY_SEPARATOR)));

        }

        // ability to define tags with Key-value pairs
        Map<String, String> keyValuePairTagsMap = new HashMap<String, String>();

        for (String propertyKey : iaasInfo.getProperties().keySet()){
            if(propertyKey.startsWith(CloudControllerConstants.TAGS_AS_KEY_VALUE_PAIRS_PREFIX)) {
                keyValuePairTagsMap.put(propertyKey.substring(CloudControllerConstants.TAGS_AS_KEY_VALUE_PAIRS_PREFIX.length()),
                        iaasInfo.getProperties().get(propertyKey));
                template.getOptions()
                    .as(AWSEC2TemplateOptions.class)
                    .userMetadata(keyValuePairTagsMap);
            }

        }
       

        if (iaasInfo.getProperty(CloudControllerConstants.SECURITY_GROUP_IDS) != null) {
            template.getOptions()
                    .as(AWSEC2TemplateOptions.class)
                    .securityGroupIds(iaasInfo.getProperty(CloudControllerConstants.SECURITY_GROUP_IDS)
                                        .split(CloudControllerConstants.ENTRY_SEPARATOR));

        }


    if (iaasInfo.getProperty(CloudControllerConstants.KEY_PAIR) != null) {
      template.getOptions().as(AWSEC2TemplateOptions.class)
          .keyPair(iaasInfo.getProperty(CloudControllerConstants.KEY_PAIR));
    }



        if (iaasInfo.getNetworkInterfaces() != null) {
            List<String> networks = new ArrayList<String>(iaasInfo.getNetworkInterfaces().length);
            for (NetworkInterface ni:iaasInfo.getNetworkInterfaces()) {
                networks.add(ni.getNetworkUuid());
            }
            template.getOptions().as(AWSEC2TemplateOptions.class).networks(networks);
        }

    // set Template
    iaasInfo.setTemplate(template);
  }
View Full Code Here

Examples of org.apache.stratos.cloud.controller.pojo.IaasProvider

    iaasInfo.setTemplate(template);
  }

  @Override
  public void setDynamicPayload() {
    IaasProvider iaasInfo = getIaasProvider();
    if (iaasInfo.getTemplate() != null && iaasInfo.getPayload() != null) {

      iaasInfo.getTemplate().getOptions().as(AWSEC2TemplateOptions.class)
          .userData(iaasInfo.getPayload());
    }

  }
View Full Code Here

Examples of org.apache.stratos.cloud.controller.pojo.IaasProvider

  @Override
  public synchronized boolean createKeyPairFromPublicKey(String region, String keyPairName,
      String publicKey) {
   
    IaasProvider iaasInfo = getIaasProvider();

    String ec2Msg = " ec2. Region: " + region + " - Key Pair Name: ";

    ComputeServiceContext context = iaasInfo.getComputeService()
        .getContext();
   
    AWSKeyPairApi keyPairApi = context.unwrapApi(AWSEC2Api.class).getKeyPairApiForRegion(region).get();

    KeyPair keyPair = keyPairApi.importKeyPairInRegion(region, keyPairName, publicKey);
   
    if (keyPair != null) {

      iaasInfo.getTemplate().getOptions().as(AWSEC2TemplateOptions.class)
          .keyPair(keyPair.getKeyName());

      log.info(SUCCESSFUL_LOG_LINE + ec2Msg + keyPair.getKeyName());
      return true;
    }
View Full Code Here

Examples of org.apache.stratos.cloud.controller.pojo.IaasProvider

  }

  @Override
  public synchronized String associateAddress(NodeMetadata node) {

    IaasProvider iaasInfo = getIaasProvider();
   
    ComputeServiceContext context = iaasInfo.getComputeService()
        .getContext();
   
    ElasticIPAddressApi elasticIPAddressApi = context.unwrapApi(AWSEC2Api.class).getElasticIPAddressApi().get();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
   
View Full Code Here

Examples of org.apache.stratos.cloud.controller.pojo.IaasProvider

  }

  @Override
  public synchronized void releaseAddress(String ip) {

    IaasProvider iaasInfo = getIaasProvider();
   
    ComputeServiceContext context = iaasInfo.getComputeService()
        .getContext();
    ElasticIPAddressApi elasticIPAddressApi = context.unwrapApi(AWSEC2Api.class).getElasticIPAddressApi().get();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);

    elasticIPAddressApi.disassociateAddressInRegion(
View Full Code Here

Examples of org.apache.stratos.cloud.controller.pojo.IaasProvider

  }

    @Override
    public boolean isValidRegion(String region) throws InvalidRegionException {
     
      IaasProvider iaasInfo = getIaasProvider();
     
        if (region == null || iaasInfo == null) {
            String msg =
                         "Region or IaaSProvider is null: region: " + region + " - IaaSProvider: " +
                                 iaasInfo;
            log.error(msg);
            throw new InvalidRegionException(msg);
        }
       
        ComputeServiceContext context = iaasInfo.getComputeService().getContext();
        Set<String> regions = context.unwrapApi(AWSEC2Api.class).getConfiguredRegions();
        for (String configuredRegion : regions) {
            if (region.equalsIgnoreCase(configuredRegion)) {
                if (log.isDebugEnabled()) {
                    log.debug("Found a matching region: " + region);
                }
                return true;
            }
        }
        String msg = "Invalid region: " + region +" in the iaas: "+iaasInfo.getType();
        log.error(msg);
        throw new InvalidRegionException(msg);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.