Package org.apache.stratos.cloud.controller.interfaces

Examples of org.apache.stratos.cloud.controller.interfaces.Iaas


    @Override
        public void run() {

      for (IaasProvider iaasProvider : cartridge.getIaases()) {
        try {
          Iaas iaas = (Iaas) Class.forName(iaasProvider.getClassName()).newInstance();
          iaas.buildComputeServiceAndTemplate(iaasProvider);
          iaasProvider.setIaas(iaas);
         
        } catch (Exception e) {
          rename();
          handleException(e.getMessage(), e);
View Full Code Here


            addToPayload(payload, "MEMBER_ID", memberID);
            addToPayload(payload, "LB_CLUSTER_ID", memberContext.getLbClusterId());
            addToPayload(payload, "NETWORK_PARTITION_ID", memberContext.getNetworkPartitionId());
            addToPayload(payload, "PARTITION_ID", partitionId);

            Iaas iaas = iaasProvider.getIaas();
            if(ctxt.isVolumeRequired()){
                addToPayload(payload, "PERSISTENCE_MAPPING", getPersistencePayload(cartridge, iaas).toString());
            }
           
            if (log.isDebugEnabled()) {
                log.debug("Payload: " + payload.toString());
            }
            // reloading the payload with memberID
            iaasProvider.setPayload(payload.toString().getBytes());
           
            if (iaas == null) {
                if(log.isDebugEnabled()) {
                    log.debug("Iaas is null of Iaas Provider: "+type+". Trying to build IaaS...");
                }
                try {
                    iaas = CloudControllerUtil.getIaas(iaasProvider);
                } catch (InvalidIaasProviderException e) {
                    String msg ="Instance start up failed. "+memberContext.toString()+
                            "Unable to build Iaas of this IaasProvider [Provider] : " + type+". Cause: "+e.getMessage();
                    log.error(msg, e);
                    throw new InvalidIaasProviderException(msg, e);
                }
               
            }
           
            iaas.setDynamicPayload();
            // get the pre built ComputeService from provider or region or zone or host
            computeService = iaasProvider.getComputeService();
            template = iaasProvider.getTemplate();
                       
            if (template == null) {
                String msg =
                             "Failed to start an instance. " +
                                     memberContext.toString() +
                                     ". Reason : Jclouds Template is null for iaas provider [type]: "+iaasProvider.getType();
                log.error(msg);
                throw new InvalidIaasProviderException(msg);
            }

            // generate the group id from domain name and sub domain
            // name.
            // Should have lower-case ASCII letters, numbers, or dashes.
            // Should have a length between 3-15
            String str = clusterId.length() > 10 ? clusterId.substring(0, 10) : clusterId.substring(0, clusterId.length());
            String group = str.replaceAll("[^a-z0-9-]", "");
           
            if(ctxt.isVolumeRequired()) {
              if (ctxt.getVolumes() != null) {
                for (Volume volume : ctxt.getVolumes()) {
           
                  if (volume.getId() == null) {
                    // create a new volume
                    createVolumeAndSetInClusterContext(volume, iaasProvider);
                  }
          }
              }
            }
           
            NodeMetadata node;

//            create and start a node
            Set<? extends NodeMetadata> nodes =
                                                computeService.createNodesInGroup(group, 1,
                                                                                  template);

            node = nodes.iterator().next();
            //Start allocating ip as a new job

            ThreadExecutor exec = ThreadExecutor.getInstance();
            exec.execute(new IpAllocator(memberContext, iaasProvider, cartridgeType, node));


            // node id
            String nodeId = node.getId();
            if (nodeId == null) {
                String msg = "Node id of the starting instance is null.\n" + memberContext.toString();
                log.fatal(msg);
                throw new IllegalStateException(msg);
            }
                memberContext.setNodeId(nodeId);
                if(log.isDebugEnabled()) {
                    log.debug("Node id was set. "+memberContext.toString());
                }
               
                // attach volumes
      if (ctxt.isVolumeRequired()) {
        // remove region prefix
        String instanceId = nodeId.indexOf('/') != -1 ? nodeId
            .substring(nodeId.indexOf('/') + 1, nodeId.length())
            : nodeId;
        memberContext.setInstanceId(instanceId);
        if (ctxt.getVolumes() != null) {
          for (Volume volume : ctxt.getVolumes()) {
            try {
              iaas.attachVolume(instanceId, volume.getId(),
                  volume.getDevice());
            } catch (Exception e) {
              // continue without throwing an exception, since
              // there is an instance already running
              log.error("Attaching Volume to Instance [ "
View Full Code Here

  private void createVolumeAndSetInClusterContext(Volume volume,
      IaasProvider iaasProvider) {

    // iaas cannot be null at this state #startInstance method
    Iaas iaas = iaasProvider.getIaas();
   
    int sizeGB = volume.getSize();
    String volumeId = iaas.createVolume(sizeGB);
    volume.setId(volumeId);
    volume.setIaasType(iaasProvider.getType());
  }
View Full Code Here

     * @param nodeId
     * @return will return the IaaSProvider
     */
  private IaasProvider terminate(IaasProvider iaasProvider,
      String nodeId, MemberContext ctxt) {
      Iaas iaas = iaasProvider.getIaas();
      if (iaas == null) {
         
          try {
              iaas = CloudControllerUtil.getIaas(iaasProvider);
          } catch (InvalidIaasProviderException e) {
              String msg =
                      "Instance termination failed. " +ctxt.toString()  +
                      ". Cause: Unable to build Iaas of this " + iaasProvider.toString();
              log.error(msg, e);
              throw new CloudControllerException(msg, e);
          }
         
      }
     
      //detach volumes if any
      detachVolume(iaasProvider, ctxt);
     
    // destroy the node
    iaasProvider.getComputeService().destroyNode(nodeId);

    // release allocated IP address
    if (ctxt.getAllocatedIpAddress() != null) {
            iaas.releaseAddress(ctxt.getAllocatedIpAddress());
    }
   
    log.info("Member is terminated: "+ctxt.toString());
    return iaasProvider;
  }
View Full Code Here

        try {
          String volumeId = volume.getId();
          if (volumeId == null) {
            return;
          }
          Iaas iaas = iaasProvider.getIaas();
          iaas.detachVolume(ctxt.getInstanceId(), volumeId);
        } catch (ResourceNotFoundException ignore) {
          if(log.isDebugEnabled()) {
            log.debug(ignore);
          }
        }
View Full Code Here

                     Cartridge cartridge = dataHolder.getCartridge(ctxt.getCartridgeType());
                     if(cartridge != null && cartridge.getIaases() != null && ctxt.getVolumes() != null) {
                         for (Volume volume : ctxt.getVolumes()) {
                            if(volume.getId() != null) {
                                String iaasType = volume.getIaasType();
                                Iaas iaas = dataHolder.getIaasProvider(iaasType).getIaas();
                                if(iaas != null) {
                                    try {
                                    // delete the volume
                                    iaas.deleteVolume(volume.getId());
                                    } catch(Exception ignore) {
                                        if(log.isDebugEnabled()) {
                                            log.debug(ignore);
                                        }
                                    }
View Full Code Here

                                 "is null for Partition Provider: "+provider;
            log.error(msg);
            throw new InvalidPartitionException(msg);
        }
       
        Iaas iaas = iaasProvider.getIaas();
       
        if (iaas == null) {
           
          try {
                iaas = CloudControllerUtil.getIaas(iaasProvider);
            } catch (InvalidIaasProviderException e) {
                String msg =
                        "Invalid Partition - " + partition.toString() +
                        ". Cause: Unable to build Iaas of this IaasProvider [Provider] : " + provider+". "+e.getMessage();
                log.error(msg, e);
                throw new InvalidPartitionException(msg, e);
            }
           
        }

        PartitionValidator validator = iaas.getPartitionValidator();
        validator.setIaasProvider(iaasProvider);
        validator.validate(partition.getId(),
                           CloudControllerUtil.toJavaUtilProperties(partition.getProperties()));
       
        return true;
View Full Code Here

                      if (pre_defined_ip != null) {
                        if (isValidIpAddress(pre_defined_ip)) {
                          if(log.isDebugEnabled()) {
                            log.debug("CloudControllerServiceImpl:IpAllocator:pre_defined_ip: invoking associatePredefinedAddress" + pre_defined_ip);
                          }
                          Iaas iaas = iaasProvider.getIaas();
                          ip = iaas.associatePredefinedAddress(node, pre_defined_ip);
              
                          if (ip == null || "".equals(ip) || !pre_defined_ip.equals(ip)) {
                            // throw exception and stop instance creation
                               String msg = "Error occurred while allocating predefined floating ip address: " + pre_defined_ip +
                                      " / allocated ip:" + ip +
                                        " - terminating node:"  + memberContext.toString();
                                log.error(msg);
                            // terminate instance
                                terminate(iaasProvider,
                                  node.getId(), memberContext);
                                throw new CloudControllerException(msg);
                          }
                        } else {
                          String msg = "Invalid floating ip address configured: " + pre_defined_ip + 
                                 " - terminating node:"  + memberContext.toString();
                          log.error(msg);
                          // terminate instance
                          terminate(iaasProvider,
                            node.getId(), memberContext);
                          throw new CloudControllerException(msg);
                        }
                         
                        } else {
                          if(log.isDebugEnabled()) {
                            log.debug("CloudControllerServiceImpl:IpAllocator:no (valid) predefined floating ip configured, " + pre_defined_ip
                              + ", selecting available one from pool");
                          }
                          Iaas iaas = iaasProvider.getIaas();
                            // allocate an IP address - manual IP assigning mode
                            ip = iaas.associateAddress(node);
                           
                if (ip != null) {
                  memberContext.setAllocatedIpAddress(ip);
                  log.info("Allocated an ip address: "
                      + memberContext.toString());
View Full Code Here

    return carInfo;
  }
   
    public static Iaas setIaas(IaasProvider iaasProvider) throws InvalidIaasProviderException {

      Iaas iaas = loadIaas(iaasProvider);

    try {
      iaas.buildComputeServiceAndTemplate();
      iaasProvider.setIaas(iaas);
      return iaas;
    } catch (Exception e) {
      String msg = "Unable to build the jclouds object for iaas "
          + "of type: " + iaasProvider.getType();
View Full Code Here

      }
    }
   
    public static Iaas setDefaultIaas(IaasProvider iaasProvider) throws InvalidIaasProviderException {

    Iaas iaas = loadIaas(iaasProvider);

    try {
      ComputeServiceBuilderUtil.buildDefaultComputeService(iaasProvider);
      iaasProvider.setIaas(iaas);
      return iaas;
View Full Code Here

TOP

Related Classes of org.apache.stratos.cloud.controller.interfaces.Iaas

Copyright © 2018 www.massapicom. 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.