use of io.fabric8.api.Container in project fabric8 by jboss-fuse.
the class CloudFirewallEdit method doExecute.
@Override
protected Object doExecute() throws Exception {
if (validateArguments()) {
ComputeService computeService = findTargetComputeService();
if (computeService == null) {
return null;
}
Set<String> sourceCidrs = collectCirds();
FirewallManager firewallManager = firewallManagerFactory.getFirewallManager(computeService);
NodeMetadata node = null;
if (!Strings.isNullOrEmpty(targetContainerName) && getCurator().getZookeeperClient().isConnected() && fabricService != null) {
CreateJCloudsContainerMetadata metadata = getContainerCloudMetadata(targetContainerName);
if (metadata != null && !Strings.isNullOrEmpty(metadata.getNodeId())) {
targetNodeId = metadata.getNodeId();
}
}
if (!Strings.isNullOrEmpty(targetNodeId)) {
node = computeService.getNodeMetadata(targetNodeId);
}
if (node == null) {
System.err.println("Could not find target node. Make sure you specified either --target-node-id or --target-container using a valid cloud container.");
return null;
}
if (flush) {
firewallManager.addRule(Rule.create().destination(node).flush());
return null;
}
for (String cidr : sourceCidrs) {
Rule rule = Rule.create().destination(node).source(cidr);
if (port != null && port.length > 0) {
rule = rule.ports(port);
}
if (revoke) {
firewallManager.addRule(rule.revoke());
} else {
firewallManager.addRule(rule);
}
}
}
return null;
}
use of io.fabric8.api.Container in project fabric8 by jboss-fuse.
the class SshContainerCompleter method getProvider.
private ContainerProvider getProvider(Container container) {
CreateContainerMetadata metadata = container.getMetadata();
String type = metadata != null ? metadata.getCreateOptions().getProviderType() : null;
if (type == null) {
return null;
}
ContainerProvider provider = fabricService.getProvider(type);
if (provider == null) {
return null;
}
return provider;
}
use of io.fabric8.api.Container in project fabric8 by jboss-fuse.
the class SshContainerProvider method start.
@Override
public void start(Container container) {
CreateContainerMetadata metadata = container.getMetadata();
if (!(metadata instanceof CreateSshContainerMetadata)) {
throw new IllegalStateException("Container doesn't have valid create container metadata type");
} else {
CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
Session session = null;
try {
String script = buildStartScript(container.getId(), options);
session = createSession(options);
runScriptOnHost(session, script);
} catch (Throwable t) {
LOGGER.error("Failed to start container: " + container.getId(), t);
throw new FabricException(t);
} finally {
if (session != null) {
session.disconnect();
}
}
}
}
use of io.fabric8.api.Container in project fabric8 by jboss-fuse.
the class SshContainerProvider method destroy.
@Override
public void destroy(Container container) {
CreateContainerMetadata metadata = container.getMetadata();
if (!(metadata instanceof CreateSshContainerMetadata)) {
throw new IllegalStateException("Container doesn't have valid create container metadata type");
} else {
CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
Session session = null;
String prevProvisionResult = container.getProvisionResult();
try {
String script = buildUninstallScript(container.getId(), options);
session = createSession(options);
container.setProvisionResult(Container.PROVISION_DELETING);
runScriptOnHost(session, script);
} catch (Throwable t) {
LOGGER.error("Failed to stop container: " + container.getId(), t);
throw new FabricException(t);
} finally {
if (session != null) {
session.disconnect();
}
}
}
}
use of io.fabric8.api.Container in project fabric8 by jboss-fuse.
the class SshContainerProvider method stop.
@Override
public void stop(Container container) {
CreateContainerMetadata metadata = container.getMetadata();
if (!(metadata instanceof CreateSshContainerMetadata)) {
throw new IllegalStateException("Container doesn't have valid create container metadata type");
} else {
CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
Session session = null;
try {
String script = buildStopScript(container.getId(), options);
session = createSession(options);
container.setProvisionResult(Container.PROVISION_STOPPING);
runScriptOnHost(session, script);
container.setProvisionResult(Container.PROVISION_STOPPED);
} catch (Throwable t) {
LOGGER.error("Failed to stop container: " + container.getId(), t);
throw new FabricException(t);
} finally {
if (session != null) {
session.disconnect();
}
}
}
}
Aggregations