use of io.fabric8.api.ContainerProvider in project fabric8 by jboss-fuse.
the class FabricServiceImpl method stopContainer.
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;
}
}
}
use of io.fabric8.api.ContainerProvider in project fabric8 by jboss-fuse.
the class FabricServiceImpl method createContainerAutoScaler.
@Override
public ContainerAutoScaler createContainerAutoScaler(FabricRequirements requirements, ProfileRequirements profileRequirements) {
Collection<ContainerProvider> providerCollection = getProviders().values();
for (ContainerProvider containerProvider : providerCollection) {
// lets pick the highest weighted autoscaler (e.g. to prefer openshift to docker to child
SortedMap<Integer, ContainerAutoScaler> sortedAutoScalers = new TreeMap<Integer, ContainerAutoScaler>();
if (containerProvider instanceof ContainerAutoScalerFactory) {
ContainerAutoScalerFactory provider = (ContainerAutoScalerFactory) containerProvider;
ContainerAutoScaler autoScaler = provider.createAutoScaler(requirements, profileRequirements);
if (autoScaler != null) {
int weight = autoScaler.getWeight();
sortedAutoScalers.put(weight, autoScaler);
}
}
if (!sortedAutoScalers.isEmpty()) {
Integer key = sortedAutoScalers.lastKey();
if (key != null) {
return sortedAutoScalers.get(key);
}
}
}
return null;
}
use of io.fabric8.api.ContainerProvider in project fabric8 by jboss-fuse.
the class FabricServiceImpl method getProvider.
private ContainerProvider getProvider(Container container, boolean returnNull) {
CreateContainerMetadata metadata = container.getMetadata();
String type = metadata != null ? metadata.getCreateOptions().getProviderType() : null;
if (type == null) {
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");
}
return provider;
}
use of io.fabric8.api.ContainerProvider in project fabric8 by jboss-fuse.
the class FabricServiceImpl method getValidProviders.
@Override
public Map<String, ContainerProvider> getValidProviders() {
assertValid();
Map<String, ContainerProvider> validProviders = new HashMap<String, ContainerProvider>();
for (ContainerProvider cp : getProviders().values()) {
if (cp.isValidProvider()) {
validProviders.put(cp.getScheme(), cp);
}
}
return Collections.unmodifiableMap(validProviders);
}
use of io.fabric8.api.ContainerProvider in project fabric8 by jboss-fuse.
the class FabricManager method createContainers.
@Override
public Map<String, String> createContainers(Map<String, Object> options) {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating containers from JSON data: " + options);
}
String providerType = (String) options.get("providerType");
if (providerType == null) {
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);
}
if (builder == null) {
throw new RuntimeException("Unknown provider type : " + providerType);
}
ObjectMapper mapper = getObjectMapper();
builder = mapper.convertValue(options, builder.getClass());
builder.zookeeperPassword(fabricService.getZookeeperPassword());
builder.zookeeperUrl(fabricService.getZookeeperUrl());
Object profileObject = options.get("profiles");
if (profileObject != null) {
List profiles = mapper.convertValue(profileObject, List.class);
builder.profiles(profiles);
}
if (builder.getProxyUri() == null) {
builder.proxyUri(fabricService.getMavenRepoURI());
}
CreateContainerOptions build = builder.build();
if (LOG.isDebugEnabled()) {
LOG.debug("Created container options: " + build + " with profiles " + build.getProfiles());
}
CreateContainerMetadata<?>[] metadatas = fabricService.createContainers(build);
Map<String, String> rc = new LinkedHashMap<String, String>();
for (CreateContainerMetadata<?> metadata : metadatas) {
if (!metadata.isSuccess()) {
LOG.error("Failed to create container {}: ", metadata.getContainerName(), metadata.getFailure());
rc.put(metadata.getContainerName(), metadata.getFailure().getMessage());
}
}
return rc;
}
Aggregations