Example #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);
 }
Example #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");
    }
  }
Example #3
0
 @Override
 public String profileWebAppURL(String webAppId, String profileId, String versionId) {
   if (versionId == null || versionId.length() == 0) {
     Version version = getDefaultVersion();
     if (version != null) {
       versionId = version.getId();
     }
   }
   List<Container> containers =
       Containers.containersForProfile(getContainers(), profileId, versionId);
   for (Container container : containers) {
     String url = containerWebAppURL(webAppId, container.getId());
     if (url != null && url.length() > 0) {
       return url;
     }
   }
   return null;
 }
    protected void recompile() {
        LOG.debug("Looking for XSDs to recompile");

        Set<String> urls = new TreeSet<String>();
        FabricService fabric = getFabricService();
        Container container = fabric.getCurrentContainer();
        String version = container.getVersion().getId();
        List<Profile> profiles = Containers.overlayProfiles(container);
        List<String> profileIds = Profiles.profileIds(profiles);
        Collection<String> names = fabric.getDataStore().listFiles(version, profileIds, schemaPath);
        for (String name : names) {
            if (name.endsWith(".xsd")) {
                String prefix = schemaPath;
                if (Strings.isNotBlank(prefix)) {
                    prefix += "/";
                }
                urls.add("profile:" + prefix + name);
            }
        }

        LOG.info("Recompiling XSDs at URLs: " + urls);
        startedFlag.set(false);

        ClassLoader classLoader = AriesFrameworkUtil.getClassLoader(bundleContext.getBundle());
        if (classLoader == null) {
            classLoader = getClass().getClassLoader();
        }
        DynamicXJC xjc = new DynamicXJC(classLoader);
        xjc.setSchemaUrls(new ArrayList<String>(urls));
        compileResults = xjc.compileSchemas();
        if (handler != null) {
            handler.onCompileResults(compileResults);
        }
        if (introspector != null) {
            introspector.setClassLoaderProvider("dynamic.jaxb", new ClassLoaderProvider() {
                @Override
                public ClassLoader getClassLoader() {
                    return compileResults.getClassLoader();
                }
            });
        }
    }
Example #5
0
 @Override
 public boolean scaleProfile(String profile, int numberOfInstances) throws IOException {
   if (numberOfInstances == 0) {
     throw new IllegalArgumentException("numberOfInstances should be greater or less than zero");
   }
   FabricRequirements requirements = getRequirements();
   ProfileRequirements profileRequirements = requirements.getOrCreateProfileRequirement(profile);
   Integer minimumInstances = profileRequirements.getMinimumInstances();
   List<Container> containers = Containers.containersForProfile(getContainers(), profile);
   int containerCount = containers.size();
   int newCount = containerCount + numberOfInstances;
   if (newCount < 0) {
     newCount = 0;
   }
   boolean update = minimumInstances == null || newCount != minimumInstances;
   if (update) {
     profileRequirements.setMinimumInstances(newCount);
     setRequirements(requirements);
   }
   return update;
 }