Exemplo n.º 1
0
  public void setIaasProvidersList() {

    List<IaasProvider> iaasProviders = FasterLookUpDataHolder.getInstance().getIaasProviders();

    if (iaasProviders == null) {
      FasterLookUpDataHolder.getInstance()
          .setIaasProviders((iaasProviders = new ArrayList<IaasProvider>()));
    }

    List<OMNode> nodeList = getMatchingNodes(CloudControllerConstants.IAAS_PROVIDER_XPATH);

    // this is a valid scenario. User can have 0..1 iaas provider elements
    // in cloud-controller xml.
    if (nodeList == null || nodeList.isEmpty()) {
      return;
    }

    for (OMNode node : nodeList) {
      iaasProviders.add(getIaasProvider(node, iaasProviders));
    }
  }
Exemplo n.º 2
0
  public void setTopologySyncRelatedData() {

    String eltStr = CloudControllerConstants.TOPOLOGY_SYNC_ELEMENT;
    // get topologySync element
    OMElement element =
        getElement(documentElement, eltStr, CloudControllerConstants.TOPOLOGY_SYNC_XPATH);

    if (element == null) {
      return;
    }

    // get enable attribute
    boolean isEnable =
        Boolean.parseBoolean(
            element.getAttributeValue(new QName(CloudControllerConstants.ENABLE_ATTR)));

    FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
    dataHolder.setEnableTopologySync(isEnable);

    if (isEnable) {
      // get MB server info
      OMElement childElement =
          getFirstChildElement(element, CloudControllerConstants.MB_SERVER_ELEMENT);

      if (childElement != null) {
        // set MB server IP
        dataHolder.setMBServerUrl(childElement.getText());
      }

      // set cron
      childElement = getFirstChildElement(element, CloudControllerConstants.CRON_ELEMENT);
      if (childElement != null) {
        dataHolder.setTopologySynchronizerCron(childElement.getText());
      }
    }
  }
Exemplo n.º 3
0
  public List<ServiceContext> getServiceContexts() {

    List<ServiceContext> serviceContextList = new ArrayList<ServiceContext>();

    // services can be found from this XPATH
    String xpath = CloudControllerConstants.SERVICES_ELEMENT_XPATH;
    List<?> serviceNodes = getMatchingNodes(xpath, documentElement);

    if (serviceNodes == null || serviceNodes.isEmpty()) {
      // or from this XPATH
      xpath = CloudControllerConstants.SERVICE_ELEMENT_XPATH;
      serviceNodes = getMatchingNodes(xpath, documentElement);
    }

    if (serviceNodes == null || serviceNodes.isEmpty()) {
      log.warn("No service found in this configuration file : " + xmlSource.getPath());
      return serviceContextList;
    }

    for (Object obj : serviceNodes) {
      ServiceContext serviceCtxt = new ServiceContext();

      // set the definition file
      serviceCtxt.setFile(xmlSource);

      if (obj instanceof OMNode) {
        OMNode serviceNode = (OMNode) obj;

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

          OMElement node = (OMElement) serviceNode;

          if (node.getAttribute(new QName(CloudControllerConstants.SERVICE_DOMAIN_ATTR)) == null) {
            String msg =
                "Essential '"
                    + CloudControllerConstants.SERVICE_DOMAIN_ATTR
                    + "' "
                    + "attribute of '"
                    + CloudControllerConstants.SERVICE_ELEMENT
                    + "' element cannot be found in "
                    + xmlSource;

            handleException(msg);
          }

          // set domain name
          serviceCtxt.setDomainName(
              node.getAttribute(new QName(CloudControllerConstants.SERVICE_DOMAIN_ATTR))
                  .getAttributeValue());

          // set sub domain
          serviceCtxt.setSubDomainName(
              node.getAttribute(new QName(CloudControllerConstants.SERVICE_SUB_DOMAIN_ATTR))
                  .getAttributeValue());

          // set tenant range
          serviceCtxt.setTenantRange(
              node.getAttribute(new QName(CloudControllerConstants.SERVICE_TENANT_RANGE_ATTR))
                  .getAttributeValue());

          OMNode cartridgeNode =
              getFirstMatchingNode(xpath + CloudControllerConstants.CARTRIDGE_ELEMENT_XPATH, node);

          if (cartridgeNode != null && cartridgeNode.getType() == OMNode.ELEMENT_NODE) {

            OMElement cartridgeElt = (OMElement) cartridgeNode;

            String type =
                cartridgeElt
                    .getAttribute(new QName(CloudControllerConstants.TYPE_ATTR))
                    .getAttributeValue();

            if ("".equals(type)) {
              String msg =
                  "Essential '"
                      + CloudControllerConstants.TYPE_ATTR
                      + "' "
                      + " attribute of '"
                      + CloudControllerConstants.CARTRIDGE_ELEMENT
                      + "' of '"
                      + CloudControllerConstants.SERVICE_ELEMENT
                      + "' element cannot be found in "
                      + xmlSource;

              handleException(msg);
            }

            // set Cartridge type
            serviceCtxt.setCartridgeType(type);
          }
          if (serviceCtxt.getCartridgeType() == null) {
            String msg =
                "Essential '"
                    + CloudControllerConstants.CARTRIDGE_ELEMENT
                    + "' element"
                    + " has not specified in "
                    + xmlSource;
            handleException(msg);
          }

          // load payload
          loadPayload(
              getMatchingNodes(xpath + CloudControllerConstants.PAYLOAD_ELEMENT_XPATH, node),
              serviceCtxt);

          // load host name
          loadHostName(
              getMatchingNodes(xpath + CloudControllerConstants.HOST_ELEMENT_XPATH, node),
              serviceCtxt);

          // load properties
          loadProperties(node, serviceCtxt.getProperties());
        }
      }

      FasterLookUpDataHolder.getInstance().addServiceContext(serviceCtxt);
      // add each domain specific template to list
      serviceContextList.add(serviceCtxt);
    }

    return serviceContextList;
  }
Exemplo n.º 4
0
  /** @return a List of {@link Cartridge}s. */
  public List<Cartridge> getCartridgesList() {

    FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();

    List<IaasProvider> iaasProviders = dataHolder.getIaasProviders();

    if (iaasProviders == null) {
      dataHolder.setIaasProviders((iaasProviders = new ArrayList<IaasProvider>()));
    }

    List<Cartridge> cartridges = new ArrayList<Cartridge>();

    String xpath = CloudControllerConstants.CARTRIDGES_ELEMENT_XPATH;

    // cartridges can be found from this XPATH
    List<?> cartridgeNodes = getMatchingNodes(xpath, documentElement);

    if (cartridgeNodes == null || cartridgeNodes.isEmpty()) {
      // or from this XPATH
      xpath = CloudControllerConstants.CARTRIDGE_ELEMENT_XPATH;
      cartridgeNodes = getMatchingNodes(xpath, documentElement);
    }

    if (cartridgeNodes == null || cartridgeNodes.isEmpty()) {
      log.warn("No cartridge found in this configuration file : " + xmlSource.getPath());
      return cartridges;
    }

    for (Object obj : cartridgeNodes) {

      if (obj instanceof OMNode) {
        OMNode cartridgeNode = (OMNode) obj;

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

          OMElement cartridgeElement = (OMElement) cartridgeNode;

          // retrieve Attributes of a Cartridge definition
          String type =
              cartridgeElement.getAttributeValue(new QName(CloudControllerConstants.TYPE_ATTR));
          String host =
              cartridgeElement.getAttributeValue(new QName(CloudControllerConstants.HOST_ATTR));
          String provider =
              cartridgeElement.getAttributeValue(new QName(CloudControllerConstants.PROVIDER_ATTR));

          String version =
              cartridgeElement.getAttributeValue(new QName(CloudControllerConstants.VERSION_ATTR));

          boolean multiTenant =
              Boolean.valueOf(
                  cartridgeElement.getAttributeValue(
                      new QName(CloudControllerConstants.MULTI_TENANT_ATTR)));

          Cartridge aCartridge;

          if ((aCartridge = dataHolder.getCartridge(type)) == null) {

            aCartridge = new Cartridge(type, host, provider, version, multiTenant);
          }

          // read displayName
          Iterator<?> itName =
              cartridgeElement.getChildrenWithName(
                  new QName(CloudControllerConstants.DISPLAY_NAME_ELEMENT));

          if (itName.hasNext()) {
            OMElement name = (OMElement) itName.next();

            aCartridge.setDisplayName(name.getText());
          }

          // read description
          Iterator<?> it =
              cartridgeElement.getChildrenWithName(
                  new QName(CloudControllerConstants.DESCRIPTION_ELEMENT));

          if (it.hasNext()) {
            OMElement desc = (OMElement) it.next();

            aCartridge.setDescription(desc.getText());
          }

          // load properties of this cartridge
          loadProperties(cartridgeElement, aCartridge.getProperties());

          // retrieve the list of IaaS providers
          List<?> iaasProviderNodes =
              getMatchingNodes(
                  xpath + CloudControllerConstants.IAAS_PROVIDER_ELEMENT_XPATH, cartridgeElement);

          getIaasProviders(
              iaasProviders, cartridgeElement.toString(), aCartridge, iaasProviderNodes);

          // load dirs
          List<?> deploymentNodes =
              getMatchingNodes(
                  xpath + CloudControllerConstants.DEPLOYMENT_ELEMENT_XPATH, cartridgeElement);
          setDeploymentDirs(cartridgeElement.toString(), aCartridge, deploymentNodes);

          // load port mappings
          List<?> portMappingNodes =
              getMatchingNodes(
                  xpath + CloudControllerConstants.PORT_MAPPING_ELEMENT_XPATH, cartridgeElement);
          getPortMappings(cartridgeElement.toString(), aCartridge, portMappingNodes);

          // load appTypes
          List<?> appTypesNodes =
              getMatchingNodes(
                  xpath + CloudControllerConstants.APP_TYPES_ELEMENT_XPATH, cartridgeElement);
          getAppTypes(cartridgeElement.toString(), aCartridge, appTypesNodes);

          cartridges.add(aCartridge);

          if (dataHolder.getCartridge(type) == null) {
            dataHolder.addCartridge(aCartridge);
          }
        }
      }
    }

    return cartridges;
  }
Exemplo n.º 5
0
  public void setDataPublisherRelatedData() {

    String eltStr = CloudControllerConstants.DATA_PUBLISHER_ELEMENT;
    // get dataPublisher element
    OMElement element =
        getElement(documentElement, eltStr, CloudControllerConstants.DATA_PUBLISHER_XPATH);

    if (element == null) {
      return;
    }

    FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
    // get enable attribute
    boolean isEnable =
        Boolean.parseBoolean(
            element.getAttributeValue(new QName(CloudControllerConstants.ENABLE_ATTR)));
    dataHolder.setEnableBAMDataPublisher(isEnable);

    if (isEnable) {
      // get bam server info
      OMElement childElement =
          getFirstChildElement(element, CloudControllerConstants.BAM_SERVER_ELEMENT);
      OMElement elt;

      if (childElement != null) {
        // set bam user name
        elt =
            getFirstChildElement(
                childElement, CloudControllerConstants.BAM_SERVER_ADMIN_USERNAME_ELEMENT);
        if (elt != null) {
          dataHolder.setBamUsername(elt.getText());
        }
        // set bam password
        elt =
            getFirstChildElement(
                childElement, CloudControllerConstants.BAM_SERVER_ADMIN_PASSWORD_ELEMENT);
        if (elt != null) {
          String password = resolveSecret(elt);
          if (password == null) {
            plainTextWarn(CloudControllerConstants.BAM_SERVER_ADMIN_PASSWORD_ELEMENT);
            password = elt.getText();
          }

          if (password != null) {
            dataHolder.setBamPassword(password);
          }
        }
      }

      // set cron
      childElement = getFirstChildElement(element, CloudControllerConstants.CRON_ELEMENT);
      if (childElement != null) {
        dataHolder.setDataPublisherCron(childElement.getText());
      }

      // set cassandra info
      childElement = getFirstChildElement(element, CloudControllerConstants.CASSANDRA_INFO_ELEMENT);

      if (childElement != null) {
        // set connection url
        elt = getFirstChildElement(childElement, CloudControllerConstants.CONNECTION_URL_ELEMENT);
        if (elt != null) {
          dataHolder.setCassandraConnUrl(elt.getText());
        }

        // set user name
        elt = getFirstChildElement(childElement, CloudControllerConstants.USER_NAME_ELEMENT);
        if (elt != null) {
          dataHolder.setCassandraUser(elt.getText());
        }
        // set password
        elt = getFirstChildElement(childElement, CloudControllerConstants.PASSWORD_ELEMENT);
        if (elt != null) {
          String password = resolveSecret(elt);
          if (password == null) {
            plainTextWarn(CloudControllerConstants.PASSWORD_ELEMENT);
            password = elt.getText();
          }

          if (password != null) {
            dataHolder.setCassandraPassword(password);
          }
        }
      }
    }
  }
Exemplo n.º 6
0
  @SuppressWarnings("unchecked")
  public static Cartridge toCartridge(CartridgeConfig config) {
    if (config == null) {
      return null;
    }
    Cartridge cartridge = new Cartridge();

    // populate cartridge
    cartridge.setType(config.getType());
    cartridge.setDisplayName(config.getDisplayName());
    cartridge.setDescription(config.getDescription());
    cartridge.setHostName(config.getHostName());
    String[] deploymentDirs = config.getDeploymentDirs();
    if ((deploymentDirs != null) && (deploymentDirs.length > 0)) {
      cartridge.setDeploymentDirs(Arrays.asList(deploymentDirs));
    }
    cartridge.setProvider(config.getProvider());
    cartridge.setVersion(config.getVersion());
    cartridge.setBaseDir(config.getBaseDir());

    if (config.getPortMappings() != null) {
      cartridge.setPortMappings(Arrays.asList(config.getPortMappings()));
    }

    if (config.getPersistence() != null) {
      cartridge.setPersistence(config.getPersistence());
    }
    cartridge.setMultiTenant(config.isMultiTenant());
    cartridge.setDefaultAutoscalingPolicy(config.getDefaultAutoscalingPolicy());
    cartridge.setDefaultDeploymentPolicy(config.getDefaultDeploymentPolicy());
    cartridge.setServiceGroup(config.getServiceGroup());
    org.apache.stratos.cloud.controller.pojo.Properties props = config.getProperties();
    if (props != null) {
      for (Property prop : props.getProperties()) {
        cartridge.addProperty(prop.getName(), prop.getValue());
      }
    }

    // populate LB config
    cartridge.setLbConfig(config.getLbConfig());

    List<IaasProvider> iaases = FasterLookUpDataHolder.getInstance().getIaasProviders();

    // populate IaaSes
    IaasConfig[] iaasConfigs = config.getIaasConfigs();
    if (iaasConfigs != null) {
      for (IaasConfig iaasConfig : iaasConfigs) {
        if (iaasConfig != null) {
          IaasProvider iaasProvider = null;
          if (iaases != null) {
            // check whether this is a reference to a predefined IaaS.
            for (IaasProvider iaas : iaases) {
              if (iaas.getType().equals(iaasConfig.getType())) {
                iaasProvider = new IaasProvider(iaas);
                break;
              }
            }
          }

          if (iaasProvider == null) {
            iaasProvider = new IaasProvider();
            iaasProvider.setType(iaasConfig.getType());
          }

          String className = iaasConfig.getClassName();
          if (className != null) {
            iaasProvider.setClassName(className);
          }

          String name = iaasConfig.getName();
          if (name != null) {
            iaasProvider.setName(name);
          }

          String identity = iaasConfig.getIdentity();
          if (identity != null) {
            iaasProvider.setIdentity(identity);
          }

          String credential = iaasConfig.getCredential();
          if (credential != null) {
            iaasProvider.setCredential(credential);
          }

          String provider = iaasConfig.getProvider();
          if (provider != null) {
            iaasProvider.setProvider(provider);
          }
          String imageId = iaasConfig.getImageId();
          if (imageId != null) {
            iaasProvider.setImage(imageId);
          }

          byte[] payload = iaasConfig.getPayload();
          if (payload != null) {
            iaasProvider.setPayload(payload);
          }

          org.apache.stratos.cloud.controller.pojo.Properties props1 = iaasConfig.getProperties();
          if (props1 != null) {
            for (Property prop : props1.getProperties()) {
              iaasProvider.addProperty(prop.getName(), prop.getValue());
            }
          }

          NetworkInterfaces networkInterfaces = iaasConfig.getNetworkInterfaces();
          if (networkInterfaces != null && networkInterfaces.getNetworkInterfaces() != null) {
            iaasProvider.setNetworkInterfaces(networkInterfaces.getNetworkInterfaces());
          }

          cartridge.addIaasProvider(iaasProvider);
        }
      }
    }

    return cartridge;
  }