Package org.apache.stratos.adc.mgt.dto

Examples of org.apache.stratos.adc.mgt.dto.Cartridge


                        int maxAttempts = Integer.parseInt(System.getProperty(CartridgeConstants.MAX_ATTEMPTS, "50"));
                        int i = 0;

                        while (i < maxAttempts) {
                            i++;
                            Cartridge c = null;
                            try {
                                c = getCartridgeInfo(dataCartridgeAlias, tenantDomain);
                            } catch (NotSubscribedException e) {
                                // This cannot happen here.
                            }
                            if (c != null) {
                                if (!c.getStatus().equals("ACTIVE")) {
                                    try {
                                        Thread.sleep(3000);
                                    } catch (InterruptedException ignore) {
                                    }
                                } else {
                                    mySQLPassword = c.getPassword();
                                    mySQLHostName = c.getIp();
                                    break;
                                }
                            }
                        }
                        log.info(" MYSQL Cartridge info retrieved ");
View Full Code Here


          throw new ADCException("An error occurred in subscribing process");
        }
    }

    public static Cartridge populateCartridgeInfo(CartridgeInfo cartridgeInfo, CartridgeSubscription sub, String[] ips, String tenantDomain) throws ADCException {
      Cartridge cartridge = new Cartridge();
        if (ips != null && ips.length > 0) {
      if (log.isDebugEnabled()) {
        log.debug("Found IPs: " + Arrays.toString(ips) + " for " + cartridgeInfo.getType() + ", "
            + sub.getAlias());
      }
      if (CartridgeConstants.DATA_CARTRIDGE_PROVIDER.equals(sub.getProvider())) {
        // FIXME Temporary fix for SPI-301
        cartridge.setIp(ips[ips.length - 1]);
        if (sub.getDataCartridge() != null) {
          if (log.isDebugEnabled()) {
            log.debug("Data Cartridge Info: " + sub.getDataCartridge().getUserName());
          }
          cartridge.setPassword(sub.getDataCartridge().getPassword());
          cartridge.setDbUserName(sub.getDataCartridge().getUserName());
        }
      }
      if (cartridgeInfo.getMultiTenant()) { // TODO refactor logic for carbon cartridges.
        cartridge.setStatus(CartridgeConstants.ACTIVE);
        cartridge.setActiveInstances(ips.length);
      } else {
        Map<String, String> instanceIpMap;
        try {
          instanceIpMap = PersistenceManager.getCartridgeInstanceInfo(ips, sub.getClusterDomain(),
              sub.getClusterSubdomain());
          cartridge.setActiveInstances(Collections.frequency(instanceIpMap.values(),
              CartridgeConstants.ACTIVE));
          cartridge.setStatus(checkCartridgeStatus(instanceIpMap));
        } catch (Exception e) {
          throw new ADCException("Error checking cartridge status");
        }

                if(cartridgeInfo.getProvider().equalsIgnoreCase(CartridgeConstants.PROVIDER_NAME_WSO2)) {

                    List<Member> members = getMemberInstances(sub.getClusterDomain(), sub.getClusterSubdomain());
                    if(members != null) {
                        int activeInstancesCount = 0;
                        for (Member member : members) {
                            if (member != null && member.isActive() && member.getDomain().equals(sub.getClusterDomain())) {
                                cartridge.setStatus(CartridgeConstants.ACTIVE);
                                activeInstancesCount ++;
                            }
                        }
                        cartridge.setActiveInstances(activeInstancesCount);
                    }
                }
      }
        } else {
            log.warn("IPs have not returned through Topology Management for " + sub.getAlias());
            cartridge.setStatus(CartridgeConstants.SUBSCRIBED);
        }
        cartridge.setDisplayName(cartridgeInfo.getDisplayName());
        cartridge.setDescription(cartridgeInfo.getDescription());
        cartridge.setVersion(cartridgeInfo.getVersion());
        cartridge.setMultiTenant(cartridgeInfo.getMultiTenant());

        List<String> accessURLs = new ArrayList<String>();

        if (cartridgeInfo.getPortMappings() != null) {
            for (org.apache.stratos.cloud.controller.util.xsd.PortMapping portMapping : cartridgeInfo
                    .getPortMappings()) {
                if (portMapping != null) {
          try {
            int port = Integer.parseInt(portMapping.getProxyPort());
                    String protocol = portMapping.getProtocol();

                    if ("http".equals(protocol) && port == 80) {
                        port = -1;
                    } else if ("https".equals(protocol) && port == 443) {
                        port = -1;
                    }
                   
                    String file = "";
                    if (CartridgeConstants.PROVIDER_NAME_WSO2.equals(cartridgeInfo.getProvider()) && !cartridgeInfo.getMultiTenant()) {
                      // Carbon Private Jet Cartridges
                      file = "/t/" + tenantDomain;
                    }
                   
                    URL serverURL = new URL(protocol, sub.getHostName(), port, file);
            accessURLs.add(serverURL.toExternalForm());
          } catch (MalformedURLException e) {
            if (log.isErrorEnabled()) {
              log.error("Error getting access URL for " + cartridgeInfo.getType(), e);
            }
          } catch (NumberFormatException e) {
            if (log.isErrorEnabled()) {
              log.error("Error getting port of access URL for " + cartridgeInfo.getType(), e);
            }
          }
                }
            }
        }

        cartridge.setAccessURLs(accessURLs.toArray(new String[accessURLs.size()]));

        cartridge.setCartridgeAlias(sub.getAlias());
        cartridge.setCartridgeType(sub.getCartridge());
        cartridge.setHostName(sub.getHostName());
        cartridge.setPolicy(sub.getPolicy());
        Policy policy = PolicyHolder.getInstance().getPolicy(sub.getPolicy());
        if (policy != null) {
          cartridge.setPolicyDescription(policy.getDescription());
        }
        cartridge.setProvider(sub.getProvider());
        cartridge.setMappedDomain(sub.getMappedDomain());

        if (sub.getRepository() != null) {
            cartridge.setRepoURL(convertRepoURL(sub.getRepository().getRepoName()));
        }
        return cartridge;
    }
View Full Code Here

         
          if (!cartridgeMatches(cartridgeInfo, searchPattern)) {
            continue;
          }
         
          Cartridge cartridge = new Cartridge();
          cartridge.setCartridgeType(cartridgeType);
          cartridge.setProvider(cartridgeInfo.getProvider());
          cartridge.setDisplayName(cartridgeInfo.getDisplayName());
          cartridge.setDescription(cartridgeInfo.getDescription());
          cartridge.setVersion(cartridgeInfo.getVersion());
          cartridge.setMultiTenant(cartridgeInfo.getMultiTenant());
          cartridge.setStatus(CartridgeConstants.NOT_SUBSCRIBED);
          cartridge.setCartridgeAlias("-");
          cartridge.setActiveInstances(0);
          cartridges.add(cartridge);
         
          if (cartridgeInfo.getMultiTenant() && !allowMultipleSubscription) {
            // If the cartridge is multi-tenant. We should not let users
            // subscribe twice.
            if (PersistenceManager.isAlreadySubscribed(cartridgeType,
                ApplicationManagementUtil.getTenantId(getConfigContext()))) {
              if (log.isDebugEnabled()) {
                log.debug("Already subscribed to " + cartridgeType
                    + ". This multi-tenant cartridge will not be available to subscribe");
              }
              cartridge.setStatus(CartridgeConstants.SUBSCRIBED);
            }
          }
        }
      } else {
        if (log.isDebugEnabled()) {
View Full Code Here

            continue;
          }
          TopologyManagementService topologyMgtService = DataHolder.getTopologyMgtService();
          String[] ips = topologyMgtService.getActiveIPs(subscription.getCartridge(),
              subscription.getClusterDomain(), subscription.getClusterSubdomain());
          Cartridge cartridge = ApplicationManagementUtil.populateCartridgeInfo(cartridgeInfo, subscription, ips, tenantDomain);
          cartridges.add(cartridge);
        }
      } else {
        if (log.isDebugEnabled()) {
          log.debug("There are no subscribed cartridges");
View Full Code Here

TOP

Related Classes of org.apache.stratos.adc.mgt.dto.Cartridge

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.