Package org.apache.stratos.cloud.controller.runtime

Examples of org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder


  /**
   * @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);
          }
        }
      }
    }

View Full Code Here


    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);
          }
        }
      }

    }
View Full Code Here

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

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

    if (isEnable) {
      TopologyConfig topologyConfig = new TopologyConfig();
      // load properties
      loadProperties(element, topologyConfig.getProperties());

      dataHolder.setTopologyConfig(topologyConfig);
    }
   

  }
View Full Code Here

    if (obj != null) {
      try {
        Object dataObj = Deserializer
            .deserializeFromByteArray((byte[]) obj);
        if (dataObj instanceof FasterLookUpDataHolder) {
          FasterLookUpDataHolder serializedObj = (FasterLookUpDataHolder) dataObj;
          FasterLookUpDataHolder currentData = FasterLookUpDataHolder
              .getInstance();

          // assign necessary data
          currentData.setNodeIdToServiceContextMap(serializedObj
              .getNodeIdToServiceContextMap());

          // traverse through current Service Contexts
          for (ServiceContext ctxt : currentData.getServiceCtxtList()) {
            // traverse through serialized Service Contexts
            for (ServiceContext serializedCtxt : serializedObj
                .getServiceCtxtList()) {
              // if a matching Service Context found
              if (ctxt.equals(serializedCtxt)) {
                // persisted node ids of this Service Context
                List<Object> nodeIds = serializedObj
                    .getNodeIdsOfServiceCtxt(serializedCtxt);
                for (Object nodeIdObj : nodeIds) {
                  String nodeId = (String) nodeIdObj;

                  // assign persisted data
                  currentData.addNodeId(nodeId, ctxt);

                }

                ctxt.setIaasContextMap(serializedCtxt
                    .getIaasCtxts());
View Full Code Here

        if (element == null) {
            log.debug("No data publisher config found in "+FILE_NAME);
            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 =
                    AxiomXpathParserUtil.getFirstChildElement(element,
                            CloudControllerConstants.BAM_SERVER_ELEMENT);
            OMElement elt;

            DataPublisherConfig config = new DataPublisherConfig();
            dataHolder.setDataPubConfig(config);
           
            if (childElement != null) {
                // set bam user name
                elt =
                        AxiomXpathParserUtil.getFirstChildElement(childElement,
View Full Code Here

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

        FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();

        dataHolder.setEnableTopologySync(isEnable);
        if (!isEnable) {
            if (log.isWarnEnabled()) {
                log.warn("Topology synchronization is disabled!");
            }
        }

        if (isEnable) {
            TopologyConfig topologyConfig = new TopologyConfig();
            // load properties
            IaasProviderConfigParser.loadProperties(FILE_NAME, element, topologyConfig.getProperties());

            dataHolder.setTopologyConfig(topologyConfig);
        }
    }
View Full Code Here

    if (obj != null) {
      try {
        Object dataObj = Deserializer
            .deserializeFromByteArray((byte[]) obj);
        if (dataObj instanceof FasterLookUpDataHolder) {
          FasterLookUpDataHolder serializedObj = (FasterLookUpDataHolder) dataObj;
          FasterLookUpDataHolder currentData = FasterLookUpDataHolder
              .getInstance();

          // assign necessary data
          currentData.setClusterIdToContext(serializedObj.getClusterIdToContext());
          currentData.setMemberIdToContext(serializedObj.getMemberIdToContext());
          currentData.setClusterIdToMemberContext(serializedObj.getClusterIdToMemberContext());
          currentData.setCartridges(serializedObj.getCartridges());

          if(log.isDebugEnabled()) {
             
              log.debug("Cloud Controller Data is retrieved from registry.");
          }
View Full Code Here

    }

    public final void testMemberContextOperations() throws Exception {
     
     
      FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
      Thread t1 = new Thread(new MemberAdder(dataHolder));
      t1.start();
      t1.join();
      assertEquals(2, dataHolder.getMemberContextsOfClusterId("123").size());
      Thread t2 = new Thread(new MemberRemover(dataHolder));
      t2.start();
      t2.join();
      assertEquals(1, dataHolder.getMemberContextsOfClusterId("123").size());
     
    }
View Full Code Here

    public void undeploy(String file) throws DeploymentException {

        if (file.contains(FILE_NAME)) {
            // reset
            FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
            dataHolder.setSerializationDir("");

            // grab the entry from Map
            if (fileToIaasProviderListMap.containsKey(file)) {
                // remove 'em
                dataHolder.getIaasProviders().removeAll(fileToIaasProviderListMap.get(file));

                log.info("Successfully undeployed the cloud-controller XML file specified at " +
                         file);
            }

            dataHolder.setDataPubConfig(null);
            dataHolder.setTopologyConfig(null);

        }

    }
View Full Code Here

TOP

Related Classes of org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder

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.