Package io.fabric8.api

Examples of io.fabric8.api.ContainerProvider


        }
        ContainersNode containersNode = fabric.getContainersNode();
        if (containersNode != null) {
          List<Container> selectedContainers = getSelectedContainers();
          if (!selectedContainers.isEmpty()) {
            Container container = selectedContainers.get(0);
            ContainerNode containerNode = containersNode
                .getContainerNode(container.getId());
            if (containerNode != null) {
              Selections.setSingleSelection(
                  fabric.getRefreshableUI(), containerNode);
            }
          }
View Full Code Here


    IStructuredSelection selection = getSelection();
    if (selection != null) {
      boolean changed = false;
      Iterator iterator = selection.iterator();
      while (iterator.hasNext()) {
        Container container = ContainerNode
            .toContainer(iterator.next());
        if (container != null) {
          containers.add(container);
        }
      }
View Full Code Here

          public boolean apply(Container container) {
            return container != null && container.isRoot();
          }
        }));
    if (rootContainers.size() == 1 && fabric != null) {
      Container rootContainer = rootContainers.get(0);
      ContainersNode containersNode = fabric.getContainersNode();
      if (containersNode != null) {
        return containersNode.getContainerNode(rootContainer.getId());
      }
    }
    return null;
  }
View Full Code Here

    }
    return null;
  }

  public boolean matches(ProfileNode profile) {
    Container ag = getContainer();
    Profile[] profiles = ag.getProfiles();
    for (Profile prof : profiles) {
      if (Objects.equal(prof.getId(), profile.getId())) {
        if (Objects.equal(ag.getVersionId(), profile.getVersion())) {
          return true;
        }
      }
    }
    return false;
View Full Code Here

    }

    public void startContainer(Container container, boolean force) {
        assertValid();
        LOGGER.info("Starting container {}", container.getId());
        ContainerProvider provider = getProvider(container);
        provider.start(container);
    }
View Full Code Here

    }

    public void stopContainer(Container container, boolean force) {
        assertValid();
        LOGGER.info("Stopping container {}", container.getId());
        ContainerProvider provider = getProvider(container);
        try {
            provider.stop(container);
        } catch (RuntimeException ex) {
            // if its already stopped then ignore the exception
            boolean stopped = "Instance already stopped".equals(ex.getMessage());
            if (!stopped) {
                throw ex;
View Full Code Here

        Exception providerException = null;
        LOGGER.info("Destroying container {}", containerId);
        boolean destroyed = false;
        boolean invalidContainer = false;
        try {
            ContainerProvider provider = getProvider(container, true);
            if (provider != null) {
                try {
                    provider.stop(container);
                } catch (Exception ex) {
                    // Ignore error while stopping and try to destroy.
                    // and if its already stopped then ignore the exception and do not rethrow later
                    boolean stopped = "Instance already stopped".equals(ex.getMessage());
                    if (!stopped) {
                        providerException = ex;
                    }
                }
                provider.destroy(container);
                destroyed = true;
            } else {
                invalidContainer = true;
                throw new FabricException("Container's lifecycle not managed by Fabric8 (the container was not created by Fabric8).");
            }
View Full Code Here

            if (returnNull) {
                return null;
            }
            throw new UnsupportedOperationException("Container " + container.getId() + " has not been created using Fabric");
        }
        ContainerProvider provider = getProvider(type);
        if (provider == null) {
            if (returnNull) {
                return null;
            }
            throw new UnsupportedOperationException("Container provider " + type + " not supported");
View Full Code Here

    @Override
    public CreateContainerMetadata[] createContainers(CreateContainerOptions options, CreationStateListener listener) {
        assertValid();
        try {
            final ContainerProvider provider = getProvider(options.getProviderType());
            if (provider == null) {
                throw new FabricException("Unable to find a container provider supporting '" + options.getProviderType() + "'");
            }
            if (!provider.isValidProvider()) {
                throw new FabricException("The provider '" + options.getProviderType() + "' is not valid in current environment");
            }

            String originalName = options.getName();
            if (originalName == null || originalName.length() == 0) {
                throw new FabricException("A name must be specified when creating containers");
            }

            if (listener == null) {
                listener = new NullCreationStateListener();
            }

            validateProfileDependencies(options);
            ObjectMapper mapper = new ObjectMapper();
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            Map optionsMap = mapper.readValue(mapper.writeValueAsString(options), Map.class);
            String versionId = options.getVersion() != null ? options.getVersion() : dataStore.get().getDefaultVersion();
            Set<String> profileIds = options.getProfiles();
            if (profileIds == null || profileIds.isEmpty()) {
                profileIds = new LinkedHashSet<String>();
                profileIds.add("default");
            }
            optionsMap.put("version", versionId);
            optionsMap.put("profiles", profileIds);
            optionsMap.put("number", 0);

            final List<CreateContainerMetadata> metadatas = new CopyOnWriteArrayList<CreateContainerMetadata>();
            int orgNumber = options.getNumber();
            int number = Math.max(orgNumber, 1);
            final CountDownLatch latch = new CountDownLatch(number);
            Set<String> ignoreContainerNames = new HashSet<>();
            Container[] containers = getContainers();

            // check that there is no container with the given name
            for (Container container : containers) {
                if (container.getId().equals(options.getName())) {
                    throw new IllegalArgumentException("A container with name " + options.getName() + " already exists.");
                }
            }

            for (int i = 1; i <= number; i++) {
                NameValidator validator = Containers.createNameValidator(containers, ignoreContainerNames);
                final String containerName = Containers.createUniqueContainerName(containers, originalName, validator);
                ignoreContainerNames.add(containerName);

                optionsMap.put("name", containerName);

                //Check if datastore configuration has been specified and fallback to current container settings.
                if (!hasValidDataStoreProperties(optionsMap)) {
                    optionsMap.put("dataStoreProperties", profileRegistry.get().getDataStoreProperties());
                }
                Class cl = options.getClass().getClassLoader().loadClass(options.getClass().getName() + "$Builder");
                CreateContainerBasicOptions.Builder builder = (CreateContainerBasicOptions.Builder) mapper.readValue(mapper.writeValueAsString(optionsMap), cl);
                //We always want to pass the obfuscated version of the password to the container provider.
                builder = (CreateContainerBasicOptions.Builder) builder.zookeeperPassword(PasswordEncoder.encode(getZookeeperPassword()));
                final CreateContainerOptions containerOptions = builder.build();
                final CreationStateListener containerListener = listener;
                final FabricService fabricService = this;
                new Thread("Creating container " + containerName) {
                    public void run() {
                        try {
                            if (dataStore.get().hasContainer(containerName)) {
                                CreateContainerBasicMetadata metadata = new CreateContainerBasicMetadata();
                                metadata.setContainerName(containerName);
                                metadata.setCreateOptions(containerOptions);
                                metadata.setFailure(new IllegalArgumentException("A container with name " + containerName + " already exists."));
                                metadatas.add(metadata);
                                return;
                            }
                            dataStore.get().createContainerConfig(containerOptions);
                            CreateContainerMetadata metadata = provider.create(containerOptions, containerListener);
                            if (metadata.isSuccess()) {
                                Container parent = containerOptions.getParent() != null ? getContainer(containerOptions.getParent()) : null;
                                //An ensemble server can be created without an existing ensemble.
                                //In this case container config will be created by the newly created container.
                                //TODO: We need to make sure that this entries are somehow added even to ensemble servers.
View Full Code Here

            throw new RuntimeException("No providerType provided");
        }

        CreateContainerBasicOptions.Builder builder = null;

        ContainerProvider provider = fabricService.getValidProviders().get(providerType);
        if (provider == null) {
            throw new RuntimeException("Can't find valid provider of type: " + providerType);
        }

        Class clazz = provider.getOptionsType();
        try {
            builder = (CreateContainerBasicOptions.Builder) clazz.getMethod("builder").invoke(null);
        } catch (Exception e) {
            LOG.warn("Failed to find builder type", e);
        }
View Full Code Here

TOP

Related Classes of io.fabric8.api.ContainerProvider

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.