예제 #1
0
 protected CreateChildContainerOptions.Builder createAutoScaleOptions(
     AutoScaleRequest request, FabricService fabricService) {
   CreateChildContainerOptions.Builder builder = CreateChildContainerOptions.builder();
   Container[] containers = fabricService.getContainers();
   if (containers != null) {
     List<String> containerIds = Containers.rootContainerIds(containers);
     // allow the requirements to customise which root to use...
     if (containerIds.isEmpty()) {
       throw new IllegalStateException("No root containers are available!");
     }
     String rootContainer = null;
     if (containerIds.size() == 1) {
       rootContainer = containerIds.get(0);
     } else {
       rootContainer = chooseRootContainer(request, containerIds);
     }
     if (Strings.isNullOrBlank(rootContainer)) {
       throw new IllegalStateException(
           "Could not choose a root container from the possible IDs: "
               + containerIds
               + " with requirements: "
               + getChildScalingRequirements(request));
     } else {
       builder = builder.parent(rootContainer);
     }
   }
   String zookeeperUrl = fabricService.getZookeeperUrl();
   String zookeeperPassword = fabricService.getZookeeperPassword();
   return builder
       .jmxUser("admin")
       .jmxPassword(zookeeperPassword)
       .zookeeperUrl(zookeeperUrl)
       .zookeeperPassword(zookeeperPassword);
 }
예제 #2
0
  @Override
  public void createContainers(AutoScaleRequest request) throws Exception {
    int count = request.getDelta();
    String profile = request.getProfile();
    String version = request.getVersion();
    FabricService fabricService = request.getFabricService();
    CreateChildContainerOptions.Builder builder = null;
    if (fabricService != null) {
      builder = createAutoScaleOptions(request, fabricService);
    }
    if (builder != null) {
      Set<String> ignoreContainerNames = new HashSet<>();
      for (int i = 0; i < count; i++) {
        final CreateChildContainerOptions.Builder configuredBuilder =
            builder.number(1).version(version).profiles(profile);

        Container[] containers = fabricService.getContainers();
        NameValidator nameValidator = Containers.createNameValidator(containers);
        String name =
            Containers.createContainerName(
                containers, profile, containerProvider.getScheme(), nameValidator);
        ignoreContainerNames.add(name);

        CreateChildContainerOptions options = configuredBuilder.name(name).build();
        LOG.info(
            "Creating container name "
                + name
                + " version "
                + version
                + " profile "
                + profile
                + " "
                + count
                + " container(s)");
        fabricService.createContainers(options);
      }
    } else {
      LOG.warn(
          "Could not create version "
              + version
              + " profile "
              + profile
              + " due to missing autoscale configuration");
    }
  }
예제 #3
0
  @Test
  public void testLocalFabricCluster() throws Exception {
    fabricService = getFabricService();
    // Test autostartup.
    assertNotNull(fabricService);
    CuratorFramework curator = getCurator();
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    Provision.containerAlive(
        Arrays.<Container>asList(new ContainerImpl(null, "root", fabricService)),
        PROVISION_TIMEOUT);
    Container[] containers = fabricService.getContainers();
    assertNotNull(containers);
    assertEquals("Expected to find 1 container", 1, containers.length);
    assertEquals("Expected to find the root container", "root", containers[0].getId());

    // Test that a generated password exists
    // We don't inject the configuration admin as it causes issues when the tracker gets closed.
    ConfigurationAdmin configurationAdmin = getOsgiService(ConfigurationAdmin.class);
    org.osgi.service.cm.Configuration configuration =
        configurationAdmin.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID);
    Dictionary<String, Object> dictionary = configuration.getProperties();
    assertNotNull("Expected a generated zookeeper password", dictionary.get("zookeeper.password"));
    assertTrue(String.valueOf(dictionary.get("zookeeper.url")).endsWith("2182"));
  }