use of io.fabric8.maven.docker.model.Container 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.maven.docker.model.Container in project fabric8 by jboss-fuse.
the class FabricServiceImpl method setRequirements.
@Override
public void setRequirements(FabricRequirements requirements) throws IOException {
assertValid();
validateRequirements(this, requirements);
Set<String> activeAutoScaledProfiles = new HashSet<>();
for (Container container : getContainers()) {
if (container.getId().startsWith("auto_")) {
activeAutoScaledProfiles.addAll(container.getProfileIds());
}
}
requirements.removeEmptyRequirements(activeAutoScaledProfiles);
dataStore.get().setRequirements(requirements);
}
use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.
the class FabricServiceImpl method getContainers.
@Override
public Container[] getContainers() {
assertValid();
Map<String, Container> containers = new HashMap<String, Container>();
List<String> containerIds = dataStore.get().getContainers();
for (String containerId : containerIds) {
String parentId = dataStore.get().getContainerParent(containerId);
if (parentId.isEmpty()) {
if (!containers.containsKey(containerId)) {
Container container = new ContainerImpl(null, containerId, this);
containers.put(containerId, container);
}
} else {
Container parent = containers.get(parentId);
if (parent == null) {
parent = new ContainerImpl(null, parentId, this);
containers.put(parentId, parent);
}
Container container = new ContainerImpl(parent, containerId, this);
containers.put(containerId, container);
}
}
return containers.values().toArray(new Container[containers.size()]);
}
use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.
the class FabricServiceImpl method scaleProfile.
@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;
}
use of io.fabric8.maven.docker.model.Container 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;
}
Aggregations