Package org.apache.ambari.server.state

Examples of org.apache.ambari.server.state.ServiceComponentHost


    Cluster cluster = clusters.getCluster(clusterName);
    Service s = cluster.getService(serviceName);
    ServiceComponent sc1 = s.getServiceComponent(componentName1);
    ServiceComponent sc2 = s.getServiceComponent(componentName2);
    ServiceComponentHost sch1 = sc1.getServiceComponentHost(host1);

    Set<ServiceComponentHostRequest> schReqs =
            new HashSet<ServiceComponentHostRequest>();
    Set<ServiceComponentRequest> scReqs =
            new HashSet<ServiceComponentRequest>();
    Set<ServiceRequest> sReqs = new HashSet<ServiceRequest>();
    Map<String, String> configVersions = new HashMap<String, String>();

    // update configs at SCH and SC level
    configVersions.clear();
    configVersions.put("typeA", "v1");
    configVersions.put("typeB", "v1");
    configVersions.put("typeC", "v1");
    schReqs.clear();
    schReqs.add(new ServiceComponentHostRequest(clusterName, serviceName,
            componentName1, host1, configVersions, null));
    Assert.assertNull(controller.updateHostComponents(schReqs, Collections.<String, String>emptyMap(), true));

    Assert.assertEquals(0, s.getDesiredConfigs().size());
    Assert.assertEquals(0, sc1.getDesiredConfigs().size());
    Assert.assertEquals(3, sch1.getDesiredConfigs().size());

    configVersions.clear();
    configVersions.put("typeC", "v1");
    configVersions.put("typeD", "v1");
    scReqs.clear();
    scReqs.add(new ServiceComponentRequest(clusterName, serviceName,
            componentName2, configVersions, null));
    Assert.assertNull(controller.updateComponents(scReqs, Collections.<String, String>emptyMap(), true));

    Assert.assertEquals(0, s.getDesiredConfigs().size());
    Assert.assertEquals(0, sc1.getDesiredConfigs().size());
    Assert.assertEquals(2, sc2.getDesiredConfigs().size());
    Assert.assertEquals(3, sch1.getDesiredConfigs().size());

    // update configs at service level
    configVersions.clear();
    configVersions.put("typeA", "v2");
    configVersions.put("typeC", "v2");
    configVersions.put("typeE", "v1");
    sReqs.clear();
    sReqs.add(new ServiceRequest(clusterName, serviceName, configVersions,
            null));
    Assert.assertNull(controller.updateServices(sReqs, mapRequestProps, true, false));

    Assert.assertEquals(3, s.getDesiredConfigs().size());
    Assert.assertEquals(3, sc1.getDesiredConfigs().size());
    Assert.assertEquals(4, sc2.getDesiredConfigs().size());
    Assert.assertEquals(4, sch1.getDesiredConfigs().size());

    Assert.assertEquals("v2",
            s.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
            s.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
            s.getDesiredConfigs().get("typeE").getVersionTag());

    Assert.assertEquals("v2",
            sc1.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
            sc1.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
            sc1.getDesiredConfigs().get("typeE").getVersionTag());

    Assert.assertEquals("v2",
            sc2.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
            sc2.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
            sc2.getDesiredConfigs().get("typeE").getVersionTag());
    Assert.assertEquals("v1",
            sc2.getDesiredConfigs().get("typeD").getVersionTag());

    Assert.assertEquals("v2",
            sch1.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
            sch1.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
            sch1.getDesiredConfigs().get("typeE").getVersionTag());
    Assert.assertEquals("v1",
            sch1.getDesiredConfigs().get("typeB").getVersionTag());

    // update configs at SCH level
    configVersions.clear();
    configVersions.put("typeA", "v1");
    configVersions.put("typeB", "v1");
    configVersions.put("typeC", "v1");
    schReqs.clear();
    schReqs.add(new ServiceComponentHostRequest(clusterName, serviceName,
            componentName1, host1, configVersions, null));
    Assert.assertNull(controller.updateHostComponents(schReqs, Collections.<String, String>emptyMap(), true));

    Assert.assertEquals(3, s.getDesiredConfigs().size());
    Assert.assertEquals(3, sc1.getDesiredConfigs().size());
    Assert.assertEquals(4, sc2.getDesiredConfigs().size());
    Assert.assertEquals(4, sch1.getDesiredConfigs().size());

    Assert.assertEquals("v1",
            sch1.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v1",
            sch1.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
            sch1.getDesiredConfigs().get("typeE").getVersionTag());
    Assert.assertEquals("v1",
            sch1.getDesiredConfigs().get("typeB").getVersionTag());

    // update configs at SC level
    configVersions.clear();
    configVersions.put("typeC", "v2");
    configVersions.put("typeD", "v1");
    scReqs.clear();
    scReqs.add(new ServiceComponentRequest(clusterName, serviceName,
            componentName1, configVersions, null));
    Assert.assertNull(controller.updateComponents(scReqs, Collections.<String, String>emptyMap(), true));

    Assert.assertEquals(3, s.getDesiredConfigs().size());
    Assert.assertEquals(4, sc1.getDesiredConfigs().size());
    Assert.assertEquals(4, sc2.getDesiredConfigs().size());
    Assert.assertEquals(5, sch1.getDesiredConfigs().size());

    Assert.assertEquals("v2",
            sc1.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
            sc1.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
            sc2.getDesiredConfigs().get("typeD").getVersionTag());
    Assert.assertEquals("v1",
            sc1.getDesiredConfigs().get("typeE").getVersionTag());

    Assert.assertEquals("v1",
            sch1.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
            sch1.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
            sch1.getDesiredConfigs().get("typeD").getVersionTag());
    Assert.assertEquals("v1",
            sch1.getDesiredConfigs().get("typeE").getVersionTag());
    Assert.assertEquals("v1",
            sch1.getDesiredConfigs().get("typeB").getVersionTag());
  }
View Full Code Here


    Cluster cluster = clusters.getCluster(clusterName);
    Service s = cluster.getService(serviceName);
    ServiceComponent sc1 = s.getServiceComponent(componentName1);
    ServiceComponent sc2 = s.getServiceComponent(componentName2);
    ServiceComponentHost sch1 = sc1.getServiceComponentHost(host1);

    Set<ServiceComponentHostRequest> schReqs =
        new HashSet<ServiceComponentHostRequest>();
    Set<ServiceComponentRequest> scReqs =
        new HashSet<ServiceComponentRequest>();
    Set<ServiceRequest> sReqs = new HashSet<ServiceRequest>();
    Map<String, String> configVersions = new HashMap<String, String>();

    // update configs at SCH and SC level
    configVersions.clear();
    configVersions.put("typeA", "v1");
    configVersions.put("typeB", "v1");
    configVersions.put("typeC", "v1");
    schReqs.clear();
    schReqs.add(new ServiceComponentHostRequest(clusterName, serviceName,
        componentName1, host1, configVersions, null));
    Assert.assertNull(controller.updateHostComponents(schReqs, Collections.<String, String>emptyMap(), true));

    Assert.assertEquals(0, s.getDesiredConfigs().size());
    Assert.assertEquals(0, sc1.getDesiredConfigs().size());
    Assert.assertEquals(3, sch1.getDesiredConfigs().size());

    configVersions.clear();
    configVersions.put("typeC", "v1");
    configVersions.put("typeD", "v1");
    scReqs.clear();
    scReqs.add(new ServiceComponentRequest(clusterName, serviceName,
        componentName2, configVersions, null));
    Assert.assertNull(controller.updateComponents(scReqs, Collections.<String, String>emptyMap(), true));

    Assert.assertEquals(0, s.getDesiredConfigs().size());
    Assert.assertEquals(0, sc1.getDesiredConfigs().size());
    Assert.assertEquals(2, sc2.getDesiredConfigs().size());
    Assert.assertEquals(3, sch1.getDesiredConfigs().size());

    // update configs at service level
    configVersions.clear();
    configVersions.put("typeA", "v2");
    configVersions.put("typeC", "v2");
    configVersions.put("typeE", "v1");
    sReqs.clear();
    sReqs.add(new ServiceRequest(clusterName, serviceName, configVersions,
        null));
    Assert.assertNull(controller.updateServices(sReqs, mapRequestProps, true, false));

    Assert.assertEquals(3, s.getDesiredConfigs().size());
    Assert.assertEquals(3, sc1.getDesiredConfigs().size());
    Assert.assertEquals(4, sc2.getDesiredConfigs().size());
    Assert.assertEquals(4, sch1.getDesiredConfigs().size());

    Assert.assertEquals("v2",
        s.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
        s.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
        s.getDesiredConfigs().get("typeE").getVersionTag());

    Assert.assertEquals("v2",
        sc1.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
        sc1.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
        sc1.getDesiredConfigs().get("typeE").getVersionTag());

    Assert.assertEquals("v2",
        sc2.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
        sc2.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
        sc2.getDesiredConfigs().get("typeE").getVersionTag());
    Assert.assertEquals("v1",
        sc2.getDesiredConfigs().get("typeD").getVersionTag());

    Assert.assertEquals("v2",
        sch1.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
        sch1.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
        sch1.getDesiredConfigs().get("typeE").getVersionTag());
    Assert.assertEquals("v1",
        sch1.getDesiredConfigs().get("typeB").getVersionTag());

    // update configs at SCH level
    configVersions.clear();
    configVersions.put("typeA", "v1");
    configVersions.put("typeB", "v1");
    configVersions.put("typeC", "v1");
    schReqs.clear();
    schReqs.add(new ServiceComponentHostRequest(clusterName, serviceName,
        componentName1, host1, configVersions, null));
    Assert.assertNull(controller.updateHostComponents(schReqs, Collections.<String, String>emptyMap(), true));

    Assert.assertEquals(3, s.getDesiredConfigs().size());
    Assert.assertEquals(3, sc1.getDesiredConfigs().size());
    Assert.assertEquals(4, sc2.getDesiredConfigs().size());
    Assert.assertEquals(4, sch1.getDesiredConfigs().size());

    Assert.assertEquals("v1",
        sch1.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v1",
        sch1.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
        sch1.getDesiredConfigs().get("typeE").getVersionTag());
    Assert.assertEquals("v1",
        sch1.getDesiredConfigs().get("typeB").getVersionTag());

    // update configs at SC level
    configVersions.clear();
    configVersions.put("typeC", "v2");
    configVersions.put("typeD", "v1");
    scReqs.clear();
    scReqs.add(new ServiceComponentRequest(clusterName, serviceName,
        componentName1, configVersions, null));
    Assert.assertNull(controller.updateComponents(scReqs, Collections.<String, String>emptyMap(), true));

    Assert.assertEquals(3, s.getDesiredConfigs().size());
    Assert.assertEquals(4, sc1.getDesiredConfigs().size());
    Assert.assertEquals(4, sc2.getDesiredConfigs().size());
    Assert.assertEquals(5, sch1.getDesiredConfigs().size());

    Assert.assertEquals("v2",
        sc1.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
        sc1.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
        sc2.getDesiredConfigs().get("typeD").getVersionTag());
    Assert.assertEquals("v1",
        sc1.getDesiredConfigs().get("typeE").getVersionTag());

    Assert.assertEquals("v1",
        sch1.getDesiredConfigs().get("typeA").getVersionTag());
    Assert.assertEquals("v2",
        sch1.getDesiredConfigs().get("typeC").getVersionTag());
    Assert.assertEquals("v1",
        sch1.getDesiredConfigs().get("typeD").getVersionTag());
    Assert.assertEquals("v1",
        sch1.getDesiredConfigs().get("typeE").getVersionTag());
    Assert.assertEquals("v1",
        sch1.getDesiredConfigs().get("typeB").getVersionTag());

  }
View Full Code Here

    Cluster cluster = clusters.getCluster(clusterName);
    Service s = cluster.getService(serviceName);
    ServiceComponent sc1 = s.getServiceComponent(componentName1);
    ServiceComponent sc2 = s.getServiceComponent(componentName2);
    ServiceComponentHost sch1 = sc1.getServiceComponentHost(host1);

    Set<ServiceComponentHostRequest> schReqs =
      new HashSet<ServiceComponentHostRequest>();
    Set<ServiceComponentRequest> scReqs =
      new HashSet<ServiceComponentRequest>();
    Set<ServiceRequest> sReqs = new HashSet<ServiceRequest>();
    Map<String, String> configVersions = new HashMap<String, String>();

    // SCH level
    configVersions.clear();
    configVersions.put("core-site", "version1");
    configVersions.put("hdfs-site", "version1");
    schReqs.clear();
    schReqs.add(new ServiceComponentHostRequest(clusterName, serviceName,
      componentName1, host1, configVersions, null));
    Assert.assertNull(controller.updateHostComponents(schReqs, Collections.<String, String>emptyMap(), true));
    Assert.assertEquals(2, sch1.getDesiredConfigs().size());

    // Reconfigure SCH level
    configVersions.clear();
    configVersions.put("core-site", "version122");
    schReqs.clear();
    schReqs.add(new ServiceComponentHostRequest(clusterName, serviceName,
      componentName1, host1, configVersions, null));
    Assert.assertNull(controller.updateHostComponents(schReqs, Collections.<String, String>emptyMap(), true));

    // Clear Entity Manager
    entityManager.clear();

    Assert.assertEquals(2, sch1.getDesiredConfigs().size());
    Assert.assertEquals("version122", sch1.getDesiredConfigs().get
      ("core-site").getVersionTag());

    //SC Level
    configVersions.clear();
    configVersions.put("core-site", "version1");
View Full Code Here

            try {
              Cluster cluster = fsmObject.getCluster(s.getClusterName());
              Service svc = cluster.getService(c.getServiceName());
              ServiceComponent svcComp = svc.getServiceComponent(
                  roleStr);
              ServiceComponentHost svcCompHost =
                  svcComp.getServiceComponentHost(host);
              svcCompHost.handleEvent(timeoutEvent);
            } catch (ServiceComponentNotFoundException scnex) {
              LOG.info("Not a service component, assuming its an action", scnex);
            } catch (InvalidStateTransitionException e) {
              LOG.info("Transition failed for host: " + host + ", role: "
                  + roleStr, e);
View Full Code Here

    if (s.getStartTime(hostname, roleStr) < 0) {
      try {
        Cluster c = fsmObject.getCluster(s.getClusterName());
        Service svc = c.getService(cmd.getServiceName());
        ServiceComponent svcComp = svc.getServiceComponent(roleStr);
        ServiceComponentHost svcCompHost =
            svcComp.getServiceComponentHost(hostname);
        svcCompHost.handleEvent(s.getFsmEvent(hostname, roleStr).getEvent());
      } catch (ServiceComponentNotFoundException scnex) {
        LOG.info("Not a service component, assuming its an action", scnex);
      } catch (InvalidStateTransitionException e) {
        LOG.info(
            "Transition failed for host: " + hostname + ", role: "
View Full Code Here

          }
          /** Get Service Host Components **/
          for (Map.Entry<String, ServiceComponentHost> svchost:
              comp.getServiceComponentHosts().entrySet()) {
              String hostname = svchost.getKey();
              ServiceComponentHost svcHostComponent = svchost.getValue();
              if (!serviceComponentHostsByHost.containsKey(hostname)) {
                serviceComponentHostsByHost.put(hostname,
                    new ArrayList<ServiceComponentHost>());
              }
              List<ServiceComponentHost> compList =  serviceComponentHostsByHost.get(hostname);
View Full Code Here

      if (!validCluster) {
        throw new ParentObjectNotFoundException("Attempted to add a host_component to a host that doesn't exist: " +
            "clusterName=" + request.getClusterName() + ", hostName=" + request.getHostname());
      }
      try {
        ServiceComponentHost sch = sc.getServiceComponentHost(
            request.getHostname());
        if (sch != null) {
          duplicates.add("[clusterName=" + request.getClusterName() + ", hostName=" + request.getHostname() +
              ", componentName=" +request.getComponentName() +']');
          continue;
        }
      } catch (AmbariException e) {
        // Expected
      }
    }

    // ensure only a single cluster update
    if (hostComponentNames.size() != 1) {
      throw new IllegalArgumentException("Invalid arguments - updates allowed"
          + " on only one cluster at a time");
    }

    if (!duplicates.isEmpty()) {
      StringBuilder names = new StringBuilder();
      boolean first = true;
      for (String hName : duplicates) {
        if (!first) {
          names.append(",");
        }
        first = false;
        names.append(hName);
      }
      String msg;
      if (duplicates.size() == 1) {
        msg = "Attempted to create a host_component which already exists: ";
      } else {
        msg = "Attempted to create host_component's which already exist: ";
      }
      throw new DuplicateResourceException(msg + names.toString());
    }

    // now doing actual work
    for (ServiceComponentHostRequest request : requests) {
      Cluster cluster = clusters.getCluster(request.getClusterName());
      Service s = cluster.getService(request.getServiceName());
      ServiceComponent sc = s.getServiceComponent(
          request.getComponentName());

      StackId stackId = sc.getDesiredStackVersion();
      ComponentInfo compInfo = ambariMetaInfo.getComponentCategory(
          stackId.getStackName(), stackId.getStackVersion(),
          s.getName(), sc.getName());
      boolean isClient = compInfo.isClient();

      ServiceComponentHost sch =
          serviceComponentHostFactory.createNew(sc, request.getHostname(),
              isClient);

      if (request.getDesiredState() != null
          && !request.getDesiredState().isEmpty()) {
        State state = State.valueOf(request.getDesiredState());
        sch.setDesiredState(state);
      }

      sch.setDesiredStackVersion(sc.getDesiredStackVersion());

      // TODO fix config versions to configs conversion
      Map<String, Config> configs = new HashMap<String, Config>();
      if (request.getConfigVersions() != null) {
      }

      sch.updateDesiredConfigs(configs);
      sc.addServiceComponentHost(sch);
      sch.persist();
    }

  }
View Full Code Here

        // filter on hostname if provided
        // filter on desired state if provided

        if (request.getHostname() != null) {
          try {
            ServiceComponentHost sch = sc.getServiceComponentHost(
                request.getHostname());
            if (checkDesiredState
                && (desiredStateToCheck != sch.getDesiredState())) {
              continue;
            }
            ServiceComponentHostResponse r = sch.convertToResponse();
            response.add(r);
          } catch (ServiceComponentHostNotFoundException e) {
            if (request.getServiceName() != null && request.getComponentName() != null) {
              throw new ServiceComponentHostNotFoundException(cluster.getClusterName(),
                  request.getServiceName(), request.getComponentName(),request.getHostname());
            } else {
              // ignore this since host_component was not specified
              // this is an artifact of how we get host_components and can happen
              // in case where we get all host_components for a host
            }

          }
        } else {
          for (ServiceComponentHost sch :
              sc.getServiceComponentHosts().values()) {
            if (checkDesiredState
                && (desiredStateToCheck != sch.getDesiredState())) {
              continue;
            }
            ServiceComponentHostResponse r = sch.convertToResponse();
            response.add(r);
          }
        }
      }
    }
View Full Code Here


      Service s = cluster.getService(request.getServiceName());
      ServiceComponent sc = s.getServiceComponent(
        request.getComponentName());
      ServiceComponentHost sch = sc.getServiceComponentHost(
        request.getHostname());
      State oldState = sch.getState();
      State newState = null;
      if (request.getDesiredState() != null) {
        newState = State.valueOf(request.getDesiredState());
        if (!newState.isValidDesiredState()) {
          throw new IllegalArgumentException("Invalid arguments, invalid"
              + " desired state, desiredState=" + newState.toString());
        }
      }

      if (request.getConfigVersions() != null) {
        safeToUpdateConfigsForServiceComponentHost(sch, oldState, newState);

        for (Entry<String,String> entry :
            request.getConfigVersions().entrySet()) {
          Config config = cluster.getDesiredConfig(
              entry.getKey(), entry.getValue());
          if (null == config) {
            throw new AmbariException("Trying to update servicecomponenthost"
                + " with invalid configs"
                + ", clusterName=" + cluster.getClusterName()
                + ", clusterId=" + cluster.getClusterId()
                + ", serviceName=" + s.getName()
                + ", componentName=" + sc.getName()
                + ", hostname=" + sch.getHostName()
                + ", invalidConfigType=" + entry.getKey()
                + ", invalidConfigTag=" + entry.getValue());
          }
        }
      }

      if (newState == null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Nothing to do for new updateServiceComponentHost request"
              + ", clusterName=" + request.getClusterName()
              + ", serviceName=" + request.getServiceName()
              + ", componentName=" + request.getComponentName()
              + ", hostname=" + request.getHostname()
              + ", newDesiredState=null");
        }
        continue;
      }

      if (sc.isClientComponent() &&
          !newState.isValidClientComponentState()) {
        throw new IllegalArgumentException("Invalid desired state for a client"
            + " component");
      }

      seenNewStates.add(newState);

      State oldSchState = sch.getState();
      if (newState == oldSchState) {
        sch.setDesiredState(newState);
        if (LOG.isDebugEnabled()) {
          LOG.debug("Ignoring ServiceComponentHost"
              + ", clusterName=" + request.getClusterName()
              + ", serviceName=" + s.getName()
              + ", componentName=" + sc.getName()
              + ", hostname=" + sch.getHostName()
              + ", currentState=" + oldSchState
              + ", newDesiredState=" + newState);
        }
        continue;
      }
     
      if (!isValidStateTransition(oldSchState, newState)) {
        throw new AmbariException("Invalid transition for"
            + " servicecomponenthost"
            + ", clusterName=" + cluster.getClusterName()
            + ", clusterId=" + cluster.getClusterId()
            + ", serviceName=" + sch.getServiceName()
            + ", componentName=" + sch.getServiceComponentName()
            + ", hostname=" + sch.getHostName()
            + ", currentState=" + oldSchState
            + ", newDesiredState=" + newState);
      }
      if (!changedScHosts.containsKey(sc.getName())) {
        changedScHosts.put(sc.getName(),
            new HashMap<State, List<ServiceComponentHost>>());
      }
      if (!changedScHosts.get(sc.getName()).containsKey(newState)) {
        changedScHosts.get(sc.getName()).put(newState,
            new ArrayList<ServiceComponentHost>());
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("Handling update to ServiceComponentHost"
            + ", clusterName=" + request.getClusterName()
            + ", serviceName=" + s.getName()
            + ", componentName=" + sc.getName()
            + ", hostname=" + sch.getHostName()
            + ", currentState=" + oldSchState
            + ", newDesiredState=" + newState);
      }
      changedScHosts.get(sc.getName()).get(newState).add(sch);
    }

    if (seenNewStates.size() > 1) {
      // FIXME should we handle this scenario
      throw new IllegalArgumentException("Cannot handle different desired"
          + " state changes for a set of service components at the same time");
    }


    // TODO additional validation?
    for (ServiceComponentHostRequest request : requests) {
      Cluster cluster = clusters.getCluster(request.getClusterName());
      Service s = cluster.getService(request.getServiceName());
      ServiceComponent sc = s.getServiceComponent(
          request.getComponentName());
      ServiceComponentHost sch = sc.getServiceComponentHost(
          request.getHostname());
      if (request.getConfigVersions() != null) {
        Map<String, Config> updated = new HashMap<String, Config>();

        for (Entry<String,String> entry : request.getConfigVersions().entrySet()) {
          Config config = cluster.getDesiredConfig(
              entry.getKey(), entry.getValue());
          updated.put(config.getType(), config);

          if (!updated.isEmpty()) {
            sch.updateDesiredConfigs(updated);
            sch.persist();
          }
        }
      }
    }
View Full Code Here

    sc1.persist();
    sc2.persist();
    sc3.persist();

    ServiceComponentHost sch1 = serviceComponentHostFactory.createNew(sc1, "h1",
        false);
    ServiceComponentHost sch2 = serviceComponentHostFactory.createNew(sc1, "h2",
        false);
    ServiceComponentHost sch3 = serviceComponentHostFactory.createNew(sc1, "h3",
        false);
    ServiceComponentHost sch4 = serviceComponentHostFactory.createNew(sc2, "h1",
        false);
    ServiceComponentHost sch5 = serviceComponentHostFactory.createNew(sc2, "h2",
        false);
    ServiceComponentHost sch6 = serviceComponentHostFactory.createNew(sc3, "h3",
        false);

    sc1.addServiceComponentHost(sch1);
    sc1.addServiceComponentHost(sch2);
    sc1.addServiceComponentHost(sch3);
    sc2.addServiceComponentHost(sch4);
    sc2.addServiceComponentHost(sch5);
    sc3.addServiceComponentHost(sch6);

    sch1.setDesiredState(State.INSTALLED);
    sch2.setDesiredState(State.INIT);
    sch4.setDesiredState(State.INSTALLED);
    sch5.setDesiredState(State.UNINSTALLED);

    sch1.persist();
    sch2.persist();
    sch3.persist();
    sch4.persist();
    sch5.persist();
    sch6.persist();

    ServiceComponentHostRequest r =
        new ServiceComponentHostRequest(null, null, null, null, null, null);

    try {
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.state.ServiceComponentHost

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.