Package org.apache.ambari.server.actionmanager

Examples of org.apache.ambari.server.actionmanager.ActionDefinition


      throws AmbariException {
    if (actionRequest.getActionName() == null || actionRequest.getActionName().isEmpty()) {
      throw new AmbariException("Action name must be specified");
    }

    ActionDefinition actionDef = actionManager.getActionDefinition(actionRequest.getActionName());
    if (actionDef == null) {
      throw new AmbariException("Action " + actionRequest.getActionName() + " does not exist");
    }

    StackId stackId = cluster.getCurrentStackVersion();
    String expectedService = actionDef.getTargetService() == null ? "" : actionDef.getTargetService();
    String actualService = actionRequest.getServiceName() == null ? "" : actionRequest.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);
    }

    String 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 = actionRequest.getComponentName() == null ? "" : actionRequest.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);
    }

    String 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 (actionDef.getInputs() != null) {
      String[] inputs = actionDef.getInputs().split(",");
      for (String input : inputs) {
        if (!input.trim().isEmpty() && !actionRequest.getParameters().containsKey(input.trim())) {
          throw new AmbariException("Action " + actionRequest.getActionName() + " requires input '" +
              input.trim() + "' that is not provided.");
        }
      }
    }

    if (actionDef.getTargetType() == TargetHostType.SPECIFIC
        || (targetService.isEmpty() && targetService.isEmpty())) {
      if (actionRequest.getHosts().size() == 0) {
        throw new AmbariException("Action " + actionRequest.getActionName() + " requires explicit target host(s)" +
            " that is not provided.");
      }
    }

    LOG.info("Received action execution request"
        + ", clusterName=" + actionRequest.getClusterName()
        + ", request=" + actionRequest.toString());

    ActionExecutionContext actionExecutionContext = new ActionExecutionContext(
        actionRequest.getClusterName(), actionRequest.getActionName(), targetService, targetComponent,
        actionRequest.getHosts(), actionRequest.getParameters(), actionDef.getTargetType(),
        actionDef.getDefaultTimeout());

    return actionExecutionContext;
  }
View Full Code Here


        List<ActionDefinition> ads = getActionManager().getAllActionDefinition();
        for (ActionDefinition ad : ads) {
          responses.add(new ActionResponse(ad));
        }
      } else {
        ActionDefinition ad = getActionManager().getActionDefinition(request.getActionName());
        if (ad != null) {
          responses.add(new ActionResponse(ad));
        }
      }
    }
View Full Code Here

      throws AmbariException {
    if (actionRequest.getActionName() == null || actionRequest.getActionName().isEmpty()) {
      throw new AmbariException("Action name must be specified");
    }

    ActionDefinition actionDef = actionManager.getActionDefinition(actionRequest.getActionName());
    if (actionDef == null) {
      throw new AmbariException("Action " + actionRequest.getActionName() + " does not exist");
    }

    StackId stackId = cluster.getCurrentStackVersion();
    String expectedService = actionDef.getTargetService() == null ? "" : actionDef.getTargetService();
    String actualService = actionRequest.getServiceName() == null ? "" : actionRequest.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);
    }

    String 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 = actionRequest.getComponentName() == null ? "" : actionRequest.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);
    }

    String 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 (actionDef.getInputs() != null) {
      String[] inputs = actionDef.getInputs().split(",");
      for (String input : inputs) {
        if (!input.trim().isEmpty() && !actionRequest.getParameters().containsKey(input.trim())) {
          throw new AmbariException("Action " + actionRequest.getActionName() + " requires input '" +
              input.trim() + "' that is not provided.");
        }
      }
    }

    if (actionDef.getTargetType() == TargetHostType.SPECIFIC
        || (targetService.isEmpty() && targetService.isEmpty())) {
      if (actionRequest.getHosts().size() == 0) {
        throw new AmbariException("Action " + actionRequest.getActionName() + " requires explicit target host(s)" +
            " that is not provided.");
      }
    }

    LOG.info("Received action execution request"
        + ", clusterName=" + actionRequest.getClusterName()
        + ", request=" + actionRequest.toString());

    ActionExecutionContext actionExecutionContext = new ActionExecutionContext(
        actionRequest.getClusterName(), actionRequest.getActionName(), targetService, targetComponent,
        actionRequest.getHosts(), actionRequest.getParameters(), actionDef.getTargetType(),
        actionDef.getDefaultTimeout());

    return actionExecutionContext;
  }
View Full Code Here

    ActionManager am = createNiceMock(ActionManager.class);
    AmbariManagementController managementController = createNiceMock(AmbariManagementController.class);
    expect(managementController.getActionManager()).andReturn(am).anyTimes();

    List<ActionDefinition> allDefinition = new ArrayList<ActionDefinition>();
    allDefinition.add(new ActionDefinition(
        "a1", ActionType.SYSTEM, "fileName", "HDFS", "DATANODE", "Does file exist", TargetHostType.ANY,
        Short.valueOf("100")));
    allDefinition.add(new ActionDefinition(
        "a2", ActionType.SYSTEM, "fileName", "HDFS", "DATANODE", "Does file exist", TargetHostType.ANY,
        Short.valueOf("100")));
    allDefinition.add(new ActionDefinition(
        "a3", ActionType.SYSTEM, "fileName", "HDFS", "DATANODE", "Does file exist", TargetHostType.ANY,
        Short.valueOf("100")));

    Set<ActionResponse> allResponse = new HashSet<ActionResponse>();
    for (ActionDefinition definition : allDefinition) {
      allResponse.add(new ActionResponse(definition));
    }

    ActionDefinition namedDefinition = new ActionDefinition(
        "a1", ActionType.SYSTEM, "fileName", "HDFS", "DATANODE", "Does file exist", TargetHostType.ANY,
        Short.valueOf("100"));

    Set<ActionResponse> nameResponse = new HashSet<ActionResponse>();
    nameResponse.add(new ActionResponse(namedDefinition));
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.actionmanager.ActionDefinition

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.