Package org.apache.ambari.server.controller.internal

Examples of org.apache.ambari.server.controller.internal.RequestResourceFilter


      componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "NODEMANAGER", HOST1, null));
      componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "HDFS_CLIENT", HOST1, null));

      amc.createHostComponents(componentHostRequests);

      RequestResourceFilter resourceFilter = new RequestResourceFilter("HDFS", null, null);
      ExecuteActionRequest ar = new ExecuteActionRequest(CLUSTER_NAME, Role.HDFS_SERVICE_CHECK.name(), null);
      ar.getResourceFilters().add(resourceFilter);
      amc.createAction(ar, null);

      // change mind, delete the cluster
View Full Code Here


    map = rpCapture.getValue();
   
    Assert.assertEquals("nagios_update_ignore", ear.getActionName());
    Assert.assertEquals(null, ear.getCommandName());
    Assert.assertEquals(1, ear.getResourceFilters().size());
    RequestResourceFilter resourceFilter = ear.getResourceFilters().get(0);

    Assert.assertEquals("NAGIOS", resourceFilter.getServiceName());
    Assert.assertEquals("NAGIOS_SERVER", resourceFilter.getComponentName());
    Assert.assertEquals("c1", ear.getClusterName());
    Assert.assertTrue(map.containsKey("context"))
  }
View Full Code Here

    rpCapture.getValue();
   
    Assert.assertEquals("nagios_update_ignore", ear.getActionName());
    Assert.assertEquals(null, ear.getCommandName());
    Assert.assertEquals(1, ear.getResourceFilters().size());
    RequestResourceFilter resourceFilter = ear.getResourceFilters().get(0);
    Assert.assertEquals("NAGIOS", resourceFilter.getServiceName());
    Assert.assertEquals("NAGIOS_SERVER", resourceFilter.getComponentName());
    Assert.assertEquals("c1", ear.getClusterName());
    Assert.assertTrue(map.containsKey("context"));   
  }
View Full Code Here

    map = rpCapture.getValue();
   
    Assert.assertEquals("nagios_update_ignore", ear.getActionName());
    Assert.assertEquals(null, ear.getCommandName());
    Assert.assertEquals(1, ear.getResourceFilters().size());
    RequestResourceFilter resourceFilter = ear.getResourceFilters().get(0);
    Assert.assertEquals("NAGIOS", resourceFilter.getServiceName());
    Assert.assertEquals("NAGIOS_SERVER", resourceFilter.getComponentName());
    Assert.assertEquals("c1", ear.getClusterName());
    Assert.assertTrue(map.containsKey("context"));
  }
View Full Code Here

    String expectedService = actionDef.getTargetService() == null ? "" : actionDef.getTargetService();

    List<RequestResourceFilter> resourceFilters = actionRequest.getResourceFilters();
    String targetService = "";
    String targetComponent = "";
    RequestResourceFilter resourceFilter = null;

    if (resourceFilters != null && !resourceFilters.isEmpty()) {
      if (resourceFilters.size() > 1) {
        throw new AmbariException("Custom action definition only allows one " +
          "resource filter to be specified.");
      }

      resourceFilter = resourceFilters.get(0);
      String actualService = resourceFilter.getServiceName() == null ? "" : resourceFilter.getServiceName();
      if (!expectedService.isEmpty() && !actualService.isEmpty() && !expectedService.equals(actualService)) {
        throw new AmbariException("Action " + actionRequest.getActionName() + " targets service " + actualService +
          " that does not match with expected " + expectedService);
      }

      targetService = expectedService;
      if (targetService == null || targetService.isEmpty()) {
        targetService = actualService;
      }

      if (targetService != null && !targetService.isEmpty()) {
        ServiceInfo serviceInfo;
        try {
          serviceInfo = ambariMetaInfo.getService(stackId.getStackName(), stackId.getStackVersion(),
            targetService);
        } catch (StackAccessException se) {
          serviceInfo = null;
        }

        if (serviceInfo == null) {
          throw new AmbariException("Action " + actionRequest.getActionName() +
            " targets service " + targetService + " that does not exist.");
        }
      }

      String expectedComponent = actionDef.getTargetComponent() == null ? "" : actionDef.getTargetComponent();
      String actualComponent = resourceFilter.getComponentName() == null ? "" : resourceFilter.getComponentName();
      if (!expectedComponent.isEmpty() && !actualComponent.isEmpty() && !expectedComponent.equals(actualComponent)) {
        throw new AmbariException("Action " + actionRequest.getActionName() + " targets component " + actualComponent +
          " that does not match with expected " + expectedComponent);
      }

      targetComponent = expectedComponent;
      if (targetComponent == null || targetComponent.isEmpty()) {
        targetComponent = actualComponent;
      }

      if (!targetComponent.isEmpty() && targetService.isEmpty()) {
        throw new AmbariException("Action " + actionRequest.getActionName() + " targets component " + targetComponent +
          " without specifying the target service.");
      }

      if (targetComponent != null && !targetComponent.isEmpty()) {
        ComponentInfo compInfo;
        try {
          compInfo = ambariMetaInfo.getComponent(stackId.getStackName(), stackId.getStackVersion(),
            targetService, targetComponent);
        } catch (StackAccessException se) {
          compInfo = null;
        }

        if (compInfo == null) {
          throw new AmbariException("Action " + actionRequest.getActionName() + " targets component " + targetComponent +
            " that does not exist.");
        }
      }
    }

    if (TargetHostType.SPECIFIC.equals(actionDef.getTargetType())
      || (targetService.isEmpty() && targetComponent.isEmpty())) {
      if (resourceFilter == null || resourceFilter.getHostNames().size() == 0) {
        throw new AmbariException("Action " + actionRequest.getActionName() + " requires explicit target host(s)" +
          " that is not provided.");
      }
    }
  }
View Full Code Here

    String clusterName = actionContext.getClusterName();
    Cluster cluster = clusters.getCluster(clusterName);

    List<RequestResourceFilter> resourceFilters = actionContext.getResourceFilters();

    RequestResourceFilter resourceFilter = new RequestResourceFilter();
    if (resourceFilters != null && !resourceFilters.isEmpty()) {
      resourceFilter = resourceFilters.get(0);
    }

    // List of host to select from
    Set<String> candidateHosts = new HashSet<String>();

    String serviceName = actionContext.getExpectedServiceName();
    String componentName = actionContext.getExpectedComponentName();
    StackId stackId = cluster.getCurrentStackVersion();
    ComponentInfo componentInfo = null;

    if (serviceName != null && !serviceName.isEmpty()) {
      if (componentName != null && !componentName.isEmpty()) {
        Map<String, ServiceComponentHost> componentHosts =
          cluster.getService(serviceName)
            .getServiceComponent(componentName).getServiceComponentHosts();
        candidateHosts.addAll(componentHosts.keySet());
        componentInfo = ambariMetaInfo.getComponentCategory(stackId.getStackName(),
          stackId.getStackVersion(), serviceName, componentName);
      } else {
        for (String component : cluster.getService(serviceName).getServiceComponents().keySet()) {
          Map<String, ServiceComponentHost> componentHosts =
            cluster.getService(serviceName)
              .getServiceComponent(component).getServiceComponentHosts();
          candidateHosts.addAll(componentHosts.keySet());
        }
      }
    } else {
      // All hosts are valid target host
      candidateHosts.addAll(clusters.getHostsForCluster(cluster.getClusterName()).keySet());
    }

    // If request did not specify hosts and there exists no host
    if (resourceFilter.getHostNames().isEmpty() && candidateHosts.isEmpty()) {
      throw new AmbariException("Suitable hosts not found, component="
        + componentName + ", service=" + serviceName
        + ", cluster=" + cluster.getClusterName() + ", " +
        "actionName=" + actionContext.getActionName());
    }

    // Compare specified hosts to available hosts
    if (!resourceFilter.getHostNames().isEmpty() && !candidateHosts.isEmpty()) {
      for (String hostname : resourceFilter.getHostNames()) {
        if (!candidateHosts.contains(hostname)) {
          throw new AmbariException("Request specifies host " + hostname +
            " but its not a valid host based on the " +
            "target service=" + serviceName + " and component=" + componentName);
        }
      }
    }

    List<String> targetHosts = resourceFilter.getHostNames();

    //Find target hosts to execute
    if (targetHosts.isEmpty()) {
      TargetHostType hostType = actionContext.getTargetType();
      switch (hostType) {
        case ALL:
          targetHosts.addAll(candidateHosts);
          break;
        case ANY:
          targetHosts.add(managementController.getHealthyHost(candidateHosts));
          break;
        case MAJORITY:
          for (int i = 0; i < (candidateHosts.size() / 2) + 1; i++) {
            String hostname = managementController.getHealthyHost(candidateHosts);
            targetHosts.add(hostname);
            candidateHosts.remove(hostname);
          }
          break;
        default:
          throw new AmbariException("Unsupported target type = " + hostType);
      }
    }

    Set<Map<String, String>> maintenanceSCHs =
      maintenanceStateHelper.getMaintenanceHostComponents(clusters, cluster);

    //create tasks for each host
    for (String hostName : targetHosts) {
      stage.addHostRoleExecutionCommand(hostName,
        Role.valueOf(actionContext.getActionName()), RoleCommand.ACTIONEXECUTE,
          new ServiceComponentHostOpInProgressEvent(actionContext.getActionName(),
            hostName, System.currentTimeMillis()), clusterName,
              serviceName);

      Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String, String>>();
      Map<String, Map<String, String>> configTags = null;
      if (!serviceName.isEmpty()) {
        configTags = managementController.findConfigurationTagsWithOverrides(cluster, hostName);
      }

      Map<String, String> commandParams = actionContext.getParameters();
      commandParams.put(COMMAND_TIMEOUT, actionContext.getTimeout().toString());
      commandParams.put(SCRIPT, actionName + ".py");
      commandParams.put(SCRIPT_TYPE, TYPE_PYTHON);
      commandParams.put(SCHEMA_VERSION, AmbariMetaInfo.SCHEMA_VERSION_2);

      ExecutionCommand execCmd = stage.getExecutionCommandWrapper(hostName,
        actionContext.getActionName()).getExecutionCommand();

      /*
       * TODO Execution command field population should be (partially?)
        * combined with the same code at createHostAction()
        */
      execCmd.setConfigurations(configurations);
      execCmd.setConfigurationTags(configTags);
      execCmd.setHostLevelParams(hostLevelParams);
      execCmd.setCommandParams(commandParams);
      execCmd.setServiceName(serviceName == null || serviceName.isEmpty() ?
        resourceFilter.getServiceName() : serviceName);
      execCmd.setComponentName(componentName == null || componentName.isEmpty() ?
        resourceFilter.getComponentName() : componentName);

      Map<String, String> roleParams = execCmd.getRoleParams();
      if (roleParams == null) {
        roleParams = new TreeMap<String, String>();
      }
View Full Code Here

    }
    Collection<RequestResourceFilterEntity> resourceFilterEntities = entity.getResourceFilterEntities();
    if (resourceFilterEntities != null) {
      this.resourceFilters = new ArrayList<RequestResourceFilter>();
      for (RequestResourceFilterEntity resourceFilterEntity : resourceFilterEntities) {
        RequestResourceFilter resourceFilter =
          new RequestResourceFilter(
            resourceFilterEntity.getServiceName(),
            resourceFilterEntity.getComponentName(),
            getHostsList(resourceFilterEntity.getHosts()));
        this.resourceFilters.add(resourceFilter);
      }
View Full Code Here

    map = rpCapture.getValue();
   
    Assert.assertEquals("nagios_update_ignore", ear.getActionName());
    Assert.assertEquals(null, ear.getCommandName());
    Assert.assertEquals(1, ear.getResourceFilters().size());
    RequestResourceFilter resourceFilter = ear.getResourceFilters().get(0);

    Assert.assertEquals("NAGIOS", resourceFilter.getServiceName());
    Assert.assertEquals("NAGIOS_SERVER", resourceFilter.getComponentName());
    Assert.assertEquals("c1", ear.getClusterName());
    Assert.assertTrue(map.containsKey("context"))
  }
View Full Code Here

    rpCapture.getValue();
   
    Assert.assertEquals("nagios_update_ignore", ear.getActionName());
    Assert.assertEquals(null, ear.getCommandName());
    Assert.assertEquals(1, ear.getResourceFilters().size());
    RequestResourceFilter resourceFilter = ear.getResourceFilters().get(0);
    Assert.assertEquals("NAGIOS", resourceFilter.getServiceName());
    Assert.assertEquals("NAGIOS_SERVER", resourceFilter.getComponentName());
    Assert.assertEquals("c1", ear.getClusterName());
    Assert.assertTrue(map.containsKey("context"));   
  }
View Full Code Here

    map = rpCapture.getValue();
   
    Assert.assertEquals("nagios_update_ignore", ear.getActionName());
    Assert.assertEquals(null, ear.getCommandName());
    Assert.assertEquals(1, ear.getResourceFilters().size());
    RequestResourceFilter resourceFilter = ear.getResourceFilters().get(0);
    Assert.assertEquals("NAGIOS", resourceFilter.getServiceName());
    Assert.assertEquals("NAGIOS_SERVER", resourceFilter.getComponentName());
    Assert.assertEquals("c1", ear.getClusterName());
    Assert.assertTrue(map.containsKey("context"));
  }
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.controller.internal.RequestResourceFilter

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.