Examples of ADCException


Examples of org.apache.stratos.adc.mgt.exception.ADCException

      log.error(message);
      throw e;
    } catch (Exception e) {
      String message = "Error getting info for " + cartridgeType;
      log.error(message, e);
      throw new ADCException(message, e);
    }

    validateCartridgeAlias(cartName, cartridgeType);
   

        if (cartridgeType.equals(CartridgeConstants.MYSQL_CARTRIDGE_NAME)) {
         
          autoScalingPolicy = PolicyHolder.getInstance().getDefaultPolicy();
         
          if (autoScalingPolicy == null) {
            throw new PolicyException("Could not load default auto-scaling policy.");
          }
          if (log.isDebugEnabled()) {
          log.debug("Selected Policy: " + new Gson().toJson(autoScalingPolicy));
        }
         
            dataCartridge = new DataCartridge();
            mysqlPassword = generatePassword();
            dataCartridge.setPassword(mysqlPassword);
            dataCartridge.setDataCartridgeType(cartridgeType);
            dataCartridge.setUserName(CartridgeConstants.MYSQL_DEFAULT_USER);
            clusterDomain = getDynamicClusterDomain(cartridgeType, cartName, cartridgeInfo);

            registerService(cartridgeType,
                    clusterDomain,
                    clusterSubDomain,
                    createPayload(cartridgeInfo, cartName, autoScalingPolicy, repoURL, mysqlPassword, "localhost", payloadZipFileName, tenantId, tenantDomain),
                    "*",
                    cartName + "." + cartridgeInfo.getHostName(),
                    setRegisterServiceProperties(autoScalingPolicy, tenantId,cartName));
            deletePayloadFile(payloadZipFileName);
        } else {
         
      if (!new Boolean(System.getProperty(CartridgeConstants.FEATURE_INTERNAL_REPO_ENABLED))) {
        if (log.isDebugEnabled()) {
          log.debug("Internal repo feature is not enabled.");
        }

        if (repoURL == null || repoURL.trim().length() == 0) {
          throw new RepositoryRequiredException("External repository required for subscription");
        }
      }

      if (repoURL != null && repoURL.trim().length() > 0) {
        if (log.isDebugEnabled()) {
          log.debug("Repo URL entered: " + repoURL);
        }
        // Validate Remote Repository.
        validateRepository(repoURL, repoUsername, repoPassword, privateRepo,
            new Boolean(System.getProperty(CartridgeConstants.FEATURE_EXTERNAL_REPO_VAIDATION_ENABLED)));
      }

            try {
                repository = manageRepository(repoURL, repoUsername, repoPassword, cartName, cartridgeInfo, username,
                        tenantDomain);
            } catch (Exception e) {
                log.error(e.getMessage());
                throw new ADCException(e);
            }
         
            // TODO: Check logic here
            if (!cartridgeInfo.getMultiTenant()) {
             
            if (policy != null && policy.trim().length() > 0) {
              autoScalingPolicy = PolicyHolder.getInstance().getPolicy(policy);
            } else {
              autoScalingPolicy = PolicyHolder.getInstance().getDefaultPolicy();
            }
            if (autoScalingPolicy == null) {
              throw new PolicyException("Could not load auto-scaling policy.");
            }
            if (log.isDebugEnabled()) {
              log.debug("Selected Policy: " + new Gson().toJson(autoScalingPolicy));
            }

                if (cartridgeInfo.getProvider().equalsIgnoreCase(CartridgeConstants.PROVIDER_NAME_WSO2)) { //carbon cartridge private jet mode

                    clusterDomain = getDynamicClusterDomain(cartridgeType, cartName, cartridgeInfo);
                    registerService(cartridgeType,
                            clusterDomain,
                            clusterSubDomain,
                            createCarbonPayload(cartridgeInfo, cartName, alias, payloadZipFileName, tenantDomain, false),
                            Integer.toString(tenantId),
                            cartName + "." + cartridgeInfo.getHostName(),
                            setRegisterServiceProperties(autoScalingPolicy,tenantId,cartName));
                    deletePayloadFile(payloadZipFileName);

                } else {
                    clusterDomain = getDynamicClusterDomain(cartridgeType, cartName, cartridgeInfo);

                    String mySQLPassword = null;
                    String mySQLHostName = null;

                    if (dataCartridgeType != null && dataCartridgeType.trim().length() > 0 && dataCartridgeAlias != null
                            && dataCartridgeAlias.trim().length() > 0) {
                        if (log.isInfoEnabled()) {
                            log.info("Retrieving Data Cartridge info for connect ... Alias : " + dataCartridgeAlias
                                    + ", Type: " + dataCartridgeType);
                        }

                        //TODO: Optimize following logic. Same logic is used in MySQLPasswordConfigurer
                        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 ");
                    }

                    registerService(cartridgeType,
                            clusterDomain,
                            clusterSubDomain,
                            createPayload(cartridgeInfo, cartName, autoScalingPolicy, repoURL, mySQLPassword,
                                    mySQLHostName, payloadZipFileName, tenantId, tenantDomain), "*",
                            cartName + "." + cartridgeInfo.getHostName(),
                            setRegisterServiceProperties(autoScalingPolicy,tenantId,cartName));
                    deletePayloadFile(payloadZipFileName);
                }

            } else {
             
              boolean allowMultipleSubscription = new Boolean(
            System.getProperty(CartridgeConstants.FEATURE_MULTI_TENANT_MULTIPLE_SUBSCRIPTION_ENABLED));

        if (!allowMultipleSubscription) {
          // If the cartridge is multi-tenant. We should not let users
          // subscribe twice.
          boolean subscribed;
          try {
            subscribed = PersistenceManager.isAlreadySubscribed(cartridgeType, tenantId);
          } catch (Exception e) {
            String msg = "Error checking whether the cartridge type " + cartridgeType
                + " is already subscribed";
            log.error(msg, e);
            throw new ADCException(msg, e);
          }
         
          if (subscribed) {
            String msg = "Already subscribed to " + cartridgeType
                + ". This multi-tenant cartridge will not be available to subscribe";
            if (log.isDebugEnabled()) {
              log.debug(msg);
            }
            throw new AlreadySubscribedException(msg, cartridgeType);
          }
        }

                TopologyManagementService topologyService = DataHolder.getTopologyMgtService();
                DomainContext[] domainContexts = topologyService.getDomainsAndSubdomains(cartridgeType, tenantId);
                log.info("Retrieved " + domainContexts.length + " domain and corresponding subdomain pairs");

                if (domainContexts.length > 0) {
                                          if(domainContexts.length > 2) {
                                              if(log.isDebugEnabled())
                                                  log.debug("Too many domain sub domain pairs");
                                         }
                 
                                          for (int i = 0 ; i < domainContexts.length ; i++) {
                                              if(domainContexts[i].getSubDomain().equalsIgnoreCase("mgt")) {
                                                  mgtClusterDomain = domainContexts[i].getDomain();
                                                  mgtClusterSubDomain = domainContexts[i].getSubDomain();
                                              }
                                            else
                                            {
                                                clusterDomain = domainContexts[i].getDomain();
                                                clusterSubDomain = domainContexts[i].getSubDomain();
                                            }
                                        }
                } else {
                  String msg = "Domain contexts not found for " + cartridgeType + " and tenant id " + tenantId;
                    log.warn(msg);
                    throw new ADCException(msg);
                }
            }
        }

        subscription =
                createCartridgeSubscription(cartridgeInfo, autoScalingPolicy,
                        cartridgeType, cartName, tenantId, tenantDomain,
                        repository, clusterDomain, clusterSubDomain,
                        mgtClusterDomain, mgtClusterSubDomain, dataCartridge);

        try {
      PersistenceManager.persistSubscription(subscription);
    } catch (Exception e) {
      throw new ADCException("Error Saving Subscription", e);
    }
        addDNSEntry(alias, cartridgeType);
        return createSubscriptionResponse(subscription, repository);

    }
View Full Code Here

Examples of org.apache.stratos.adc.mgt.exception.ADCException

                    mySQLPwd, mySQLHost, payloadZipFileName, tenantId, tenantDomain);
            dataSource = new FileDataSource(payloadFile);
        } catch (Exception e) {
            String msg = "Exception : " + e.getMessage();
            log.error(msg, e);
            throw new ADCException("Subscribe failed ", e);
        }
        return new DataHandler(dataSource);
    }
View Full Code Here

Examples of org.apache.stratos.adc.mgt.exception.ADCException

            dataSource = new FileDataSource(payloadFile);

        } catch (Exception e) {
            String msg = "Exception : " + e.getMessage();
            log.error(msg, e);
            throw new ADCException("Subscribe failed ", e);
        }

        return new DataHandler(dataSource);
    }
View Full Code Here

Examples of org.apache.stratos.adc.mgt.exception.ADCException

    try {     
      isAliasTaken = PersistenceManager.isAliasAlreadyTaken(alias, cartridgeType);     
    } catch (Exception e) {
      String msg = "Exception : " + e.getMessage();
      log.error(msg, e);
      throw new ADCException("Error when checking alias is already taken", e);
    }
   
    if (isAliasTaken) {
      String msg = "The alias " + alias + " is already taken. Please try again with a different alias.";
      log.error(msg);
View Full Code Here

Examples of org.apache.stratos.adc.mgt.exception.ADCException

      localRepo = new FileRepository(f);
      if (log.isDebugEnabled()) {
        log.debug("Local File Repo: " + f.getAbsoluteFile());
      }
    } catch (IOException e) {
      throw new ADCException("Error creating local file repo", e);
    }

    Git git = new Git(localRepo);
    LsRemoteCommand cmd = git.lsRemote().setRemote(repoURL);
    if (credentialsProvider != null) {
      cmd.setCredentialsProvider(credentialsProvider);
    }
    try {
      Collection<Ref> collection = cmd.call();
      List<String> refNames = new ArrayList<String>();
      if (collection != null) {
        for (Ref ref : collection) {
          if (log.isDebugEnabled()) {
            log.debug(repoURL + ": " + ref.getName());
          }
          refNames.add(ref.getName());
        }
      }
      repositoryInformation.setRefName(refNames.toArray(new String[refNames.size()]));
    } catch (InvalidRemoteException e) {
      throw new InvalidRepositoryException("Provided repository url is not valid", e);
    } catch (TransportException e) {
      throw new RepositoryTransportException("Transport error when checking remote repository", e);
    } catch (GitAPIException e) {
      throw new ADCException("Git API error when checking remote repository", e);
    }
    return repositoryInformation;
  }
View Full Code Here

Examples of org.apache.stratos.adc.mgt.exception.ADCException

    public static Cartridge getCartridgeInfo(String alias, String tenantDomain) throws ADCException, NotSubscribedException {
        log.info("Alias: " + alias);
        if (alias == null) {
            String msg = "Provided alias is empty";
            log.error(msg);
            throw new ADCException("Alias you provided is empty.");
        }

        CartridgeSubscription sub;
        try {
            sub = PersistenceManager.getSubscription(tenantDomain, alias);
        } catch (Exception e) {
            String message = "Cannot get subscription info for " + tenantDomain + " and alias " + alias;
            log.error(message, e);
            throw new ADCException(message, e);
        }
        if (sub == null) {
            String msg = "Info request for not subscribed cartridge";
            log.error(msg);
            throw new NotSubscribedException("You have not subscribed for " + alias, alias);
        }

        log.info("Cluster domain : " + sub.getClusterDomain() + " cartridge: " + sub.getCartridge());
       
        CartridgeInfo cartridgeInfo = null;
        try {
            cartridgeInfo = getServiceClient().getCartridgeInfo(sub.getCartridge());
        } catch (Exception e) {
            throw new ADCException("Cannot get cartridge info: " + sub.getCartridge(), e);
        }

        TopologyManagementService topologyMgtService = DataHolder.getTopologyMgtService();

        String[] ips =
View Full Code Here

Examples of org.apache.stratos.adc.mgt.exception.ADCException

            String msg = "Exception is occurred in register service operation. Reason :" + e.getMessage();
            log.error(msg, e);
            throw new UnregisteredCartridgeException("Not a registered cartridge " + cartridgeType, cartridgeType, e);
        } catch (RemoteException e) {
          log.error("Remote Error", e);
          throw new ADCException("An error occurred in subscribing process");
        }
    }
View Full Code Here

Examples of org.apache.stratos.adc.mgt.exception.ADCException

              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());
View Full Code Here

Examples of org.apache.stratos.manager.exception.ADCException

        String clusterId = null;
    try {
      clusterId = AutoscalerServiceClient.getServiceClient().getDefaultLBClusterId(getDeploymentPolicyName());
    } catch (Exception e) {     
      log.error("Error occurred in retrieving default LB cluster id" + e.getMessage());
      throw new ADCException(e);
    }

        if (clusterId != null) {
            //set the cluster id to Cluster object
          cluster.setClusterDomain(clusterId);
            if (log.isDebugEnabled()) {
                log.debug("Set existing default LB cluster id " + clusterId);
            }
            defaultLBExists = true;

            //get the hostname for this cluster and set it
            ClusterContext clusterContext;
            try {
                clusterContext = CloudControllerServiceClient.getServiceClient().getClusterContext(clusterId);

            } catch (RemoteException e) {
                log.error("Error occurred in retrieving Cluster Context for default LB ", e);
                throw new ADCException(e);
            }

            if (clusterContext != null) {
                cluster.setHostName(clusterContext.getHostName());
                if (log.isDebugEnabled()) {
View Full Code Here

Examples of org.apache.stratos.manager.exception.ADCException

        try {
            clusterId = AutoscalerServiceClient.getServiceClient().getServiceLBClusterId(getLoadBalancedServiceType(), getDeploymentPolicyName());

        } catch (Exception e) {
            log.error("Error occurred in retrieving Service LB cluster id" + e.getMessage());
            throw new ADCException(e);
        }

        if (clusterId != null) {

            //set the cluster id to Cluster object
            cluster.setClusterDomain(clusterId);
            if (log.isDebugEnabled()) {
                log.debug("Set existing Service LB cluster id " + clusterId);
            }
            serviceLbExists = true;

            //get the hostname for this cluster and set it
            ClusterContext clusterContext;
            try {
                clusterContext = CloudControllerServiceClient.getServiceClient().getClusterContext(clusterId);

            } catch (RemoteException e) {
                log.error("Error occurred in retrieving Cluster Context for Service LB ", e);
                throw new ADCException(e);
            }

            if (clusterContext != null) {
                cluster.setHostName(clusterContext.getHostName());
                if (log.isDebugEnabled()) {
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.