Package org.apache.ambari.server

Examples of org.apache.ambari.server.AmbariException


      throws AmbariException {

    if (userDAO.findLdapUserByName(user.getUserName()) != null) {
      LOG.warn("Trying to add a role to the LDAP user"
          + ", user=" + user.getUserName());
      throw new AmbariException("Roles are not editable for LDAP users");
    }

    UserEntity userEntity = userDAO.findByPK(user.getUserId());
    if (userEntity == null) {
      throw new AmbariException("User " + user + " doesn't exist");
    }

    RoleEntity roleEntity = roleDAO.findByName(role);
    if (roleEntity == null) {
      throw new AmbariException("Role " + role + " doesn't exist");
    }

    if (userEntity.getRoleEntities().contains(roleEntity)) {
      userEntity.getRoleEntities().remove(roleEntity);
      roleEntity.getUserEntities().remove(userEntity);
      userDAO.merge(userEntity);
      roleDAO.merge(roleEntity);
    } else {
      throw new AmbariException("User " + user + " doesn't own role " + role);
    }

  }
View Full Code Here


              + ", serviceName=" + serviceName);
        }

        if (serviceName == null
            || serviceName.isEmpty()) {
          throw new AmbariException("Could not find service for component"
              + ", componentName=" + request.getComponentName()
              + ", clusterName=" + cluster.getClusterName()
              + ", stackInfo=" + stackId.getStackId());
        }
        request.setServiceName(serviceName);
View Full Code Here

      configs = new HashMap<String, Config>();
    }

    Config config = configs.get(request.getVersionTag());
    if (configs.containsKey(request.getVersionTag())) {
      throw new AmbariException("Configuration with that tag exists for '"
          + request.getType() + "'");
    }

    config = configFactory.createNew (cluster, request.getType(),
        request.getProperties());
View Full Code Here

    for (UserRequest request : requests) {

      if (null == request.getUsername() || request.getUsername().isEmpty() ||
          null == request.getPassword() || request.getPassword().isEmpty()) {
        throw new AmbariException("Username and password must be supplied.");
      }

      User user = users.getAnyUser(request.getUsername());
      if (null != user)
        throw new AmbariException("User already exists.");

      users.createUser(request.getUsername(), request.getPassword());

      if (0 != request.getRoles().size()) {
        user = users.getAnyUser(request.getUsername());
View Full Code Here

  private synchronized Set<ServiceResponse> getServices(ServiceRequest request)
      throws AmbariException {
    if (request.getClusterName() == null
        || request.getClusterName().isEmpty()) {
      throw new AmbariException("Invalid arguments, cluster name"
          + " cannot be null");
    }
    String clusterName = request.getClusterName();
    final Cluster cluster;
    try {
View Full Code Here

              + ", componentName=" + request.getComponentName()
              + ", serviceName=" + serviceName);
        }
        if (serviceName == null
            || serviceName.isEmpty()) {
          throw new AmbariException("Could not find service for component"
              + ", componentName=" + request.getComponentName()
              + ", clusterName=" + cluster.getClusterName()
              + ", stackInfo=" + stackId.getStackId());
        }
        request.setServiceName(serviceName);
View Full Code Here

      LOG.info("Received a cluster update request"
          + ", clusterName=" + request.getClusterName()
          + ", request=" + request);
      requestedVersion = new StackId(requestedVersionString);
      if (!requestedVersion.getStackName().equals(currentVersion.getStackName())) {
        throw new AmbariException("Upgrade not possible between different stacks.");
      }
      requiresVersionUpdate = !currentVersion.equals(requestedVersion);
      if(!requiresVersionUpdate) {
        LOG.info("The cluster is already at " + currentVersion);
      }
    }

    if (requiresVersionUpdate && requiresHostListUpdate) {
      throw new IllegalArgumentException("Invalid arguments, "
          + "cluster version cannot be upgraded"
          + " along with host list modifications");
    }

    if (requiresHostListUpdate) {
      clusters.mapHostsToCluster(
          request.getHostNames(), request.getClusterName());
    }

    if (requiresVersionUpdate) {
      LOG.info("Upgrade cluster request received for stack " + requestedVersion);
      boolean retry = false;
      if (0 == currentVersion.compareTo(desiredVersion)) {
        if (1 != requestedVersion.compareTo(currentVersion)) {
          throw new AmbariException("Target version : " + requestedVersion
              + " must be greater than current version : " + currentVersion);
        } else {
          StackInfo stackInfo =
              ambariMetaInfo.getStackInfo(requestedVersion.getStackName(), requestedVersion.getStackVersion());
          if (stackInfo == null) {
            throw new AmbariException("Target version : " + requestedVersion
                + " is not a recognized version");
          }
          if(!isUpgradeAllowed(stackInfo, currentVersion))
          {
            throw new AmbariException("Upgrade is not allowed from " + currentVersion
                + " to the target version " + requestedVersion);
          }
        }
      } else {
        retry = true;
        LOG.info("Received upgrade request is a retry.");
        if (0 != requestedVersion.compareTo(desiredVersion)) {
          throw new AmbariException("Upgrade in progress to target version : "
              + desiredVersion
              + ". Illegal request to upgrade to : " + requestedVersion);
        }
      }
View Full Code Here

          for (HostRoleCommand command : commands) {
            if (command.getRoleCommand() == RoleCommand.UPGRADE
                && (command.getStatus() == HostRoleStatus.QUEUED
                || command.getStatus() == HostRoleStatus.PENDING
                || command.getStatus() == HostRoleStatus.IN_PROGRESS)) {
              throw new AmbariException("A prior upgrade request with id " + requestId
                  + " is in progress. Upgrade can "
                  + "only be retried after the prior command has completed.");
            }
          }
        }
View Full Code Here

    for (Service service : cluster.getServices().values()) {
      State oldState = service.getDesiredState();
      State newState = State.INSTALLED;

      if (!isValidDesiredStateTransition(oldState, newState)) {
        throw new AmbariException("Invalid transition for"
            + " service"
            + ", clusterName=" + cluster.getClusterName()
            + ", clusterId=" + cluster.getClusterId()
            + ", serviceName=" + service.getName()
            + ", currentDesiredState=" + oldState
            + ", newDesiredState=" + newState);
      }
      changedServices.put(newState, new ArrayList<Service>());
      changedServices.get(newState).add(service);

      for (ServiceComponent sc : service.getServiceComponents().values()) {
        State oldScState = sc.getDesiredState();
        if (newState != oldScState) {
          if (!isValidDesiredStateTransition(oldScState, newState)) {
            throw new AmbariException("Invalid transition for"
                + " servicecomponent"
                + ", clusterName=" + cluster.getClusterName()
                + ", clusterId=" + cluster.getClusterId()
                + ", serviceName=" + sc.getServiceName()
                + ", componentName=" + sc.getName()
View Full Code Here

    String stackVersion = currentStackId.getStackVersion();
    StringBuilder sb = new StringBuilder("Upgrade needs all services to be stopped. ");
    for (Service service : c.getServices().values()) {
      if (service.getDesiredState() != State.INSTALLED) {
        sb.append("Service " + service.getName() + " is not stopped.");
        throw new AmbariException(sb.toString());
      }
      for (ServiceComponent component : service.getServiceComponents().values()) {
        if (component.getDesiredState() != State.INSTALLED) {
          sb.append("Component " + component.getName() + " of service "
              + service.getName() + " is not stopped.");
          throw new AmbariException(sb.toString());
        }
        for (ServiceComponentHost componentHost : component.getServiceComponentHosts().values()) {
          if (componentHost.getDesiredState() != State.INSTALLED) {
            sb.append("Component " + component.getName() + " of service "
                + service.getName() " on host "
                + componentHost.getHostName() + " is not stopped.");
            throw new AmbariException(sb.toString());
          }
          if(componentHost.getState() == State.STARTED) {
            ComponentInfo compInfo = ambariMetaInfo.getComponent(stackName, stackVersion,
                componentHost.getServiceName(), componentHost.getServiceComponentName());
            if(compInfo.isMaster()) {
              sb.append("Component " + component.getName() + " of service "
                  + service.getName() " on host "
                  + componentHost.getHostName() + " is not yet stopped.");
              throw new AmbariException(sb.toString());
            }
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.AmbariException

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.