use of org.guvnor.ala.exceptions.ProvisioningException in project kie-wb-common by kiegroup.
the class DockerRuntimeExecExecutor method create.
private Optional<DockerRuntime> create(final DockerRuntimeConfig runtimeConfig) throws ProvisioningException {
if (runtimeConfig.isPull()) {
try {
LOG.info("Pulling Docker Image: " + runtimeConfig.getImage());
docker.getDockerClient(runtimeConfig.getProviderId()).pull(runtimeConfig.getImage());
} catch (DockerException | InterruptedException ex) {
LOG.error(ex.getMessage(), ex);
throw new ProvisioningException("Error Pulling Docker Image: " + runtimeConfig.getImage() + "with error: " + ex.getMessage());
}
}
final String[] ports = { runtimeConfig.getPort() };
final Map<String, List<PortBinding>> portBindings = new HashMap<>();
final Optional<DockerProvider> _dockerProvider = runtimeRegistry.getProvider(runtimeConfig.getProviderId(), DockerProvider.class);
if (!_dockerProvider.isPresent()) {
return Optional.empty();
}
final DockerProvider dockerProvider = _dockerProvider.get();
final List<PortBinding> randomPort = new ArrayList<>();
final PortBinding randomPortBinding = PortBinding.randomPort(dockerProvider.getConfig().getHostIp());
randomPort.add(randomPortBinding);
portBindings.put(runtimeConfig.getPort(), randomPort);
final HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build();
final ContainerConfig containerConfig = ContainerConfig.builder().hostConfig(hostConfig).image(runtimeConfig.getImage()).exposedPorts(ports).build();
final ContainerCreation creation;
try {
creation = docker.getDockerClient(runtimeConfig.getProviderId()).createContainer(containerConfig);
docker.getDockerClient(runtimeConfig.getProviderId()).startContainer(creation.id());
} catch (DockerException | InterruptedException ex) {
LOG.error(ex.getMessage(), ex);
throw new ProvisioningException("Error Creating Docker Container with image: " + runtimeConfig.getImage() + "with error: " + ex.getMessage(), ex);
}
final String id = creation.id();
String shortId = id.substring(0, 12);
String host = "";
try {
docker.getDockerClient(runtimeConfig.getProviderId()).inspectContainer(id);
host = docker.getDockerClient(runtimeConfig.getProviderId()).getHost();
} catch (DockerException | InterruptedException ex) {
throw new ProvisioningException("Error Getting Docker Container info: " + id + "with error: " + ex.getMessage(), ex);
}
DockerRuntimeEndpoint dockerRuntimeEndpoint = new DockerRuntimeEndpoint();
dockerRuntimeEndpoint.setHost(host);
dockerRuntimeEndpoint.setPort(Integer.valueOf(runtimeConfig.getPort()));
dockerRuntimeEndpoint.setContext("");
return Optional.of(new DockerRuntime(shortId, buildRuntimeName(runtimeConfig, shortId), runtimeConfig, dockerProvider, dockerRuntimeEndpoint, new DockerRuntimeInfo(), new DockerRuntimeState(RUNNING, new Date().toString())));
}
use of org.guvnor.ala.exceptions.ProvisioningException in project kie-wb-common by kiegroup.
the class OpenShiftRuntimeExecExecutor method create.
private Optional<OpenShiftRuntime> create(final OpenShiftRuntimeConfig runtimeConfig) throws ProvisioningException {
final Optional<OpenShiftProvider> _openshiftProvider = runtimeRegistry.getProvider(runtimeConfig.getProviderId(), OpenShiftProvider.class);
if (!_openshiftProvider.isPresent()) {
return Optional.empty();
}
OpenShiftProvider openshiftProvider = _openshiftProvider.get();
OpenShiftClient openshiftClient = openshift.getOpenShiftClient(openshiftProvider);
LOG.info("Creating runtime...");
OpenShiftRuntimeState runtimeState;
try {
runtimeState = openshiftClient.create(runtimeConfig);
} catch (OpenShiftClientException ex) {
throw new ProvisioningException(ex.getMessage(), ex);
}
final String id = runtimeConfig.getRuntimeId().toString();
LOG.info("Created runtime: " + id);
OpenShiftRuntimeEndpoint endpoint = openshiftClient.getRuntimeEndpoint(id);
return Optional.of(new OpenShiftRuntime(id, buildRuntimeName(runtimeConfig, id), runtimeConfig, openshiftProvider, endpoint, new OpenShiftRuntimeInfo(runtimeConfig), runtimeState));
}
use of org.guvnor.ala.exceptions.ProvisioningException in project kie-wb-common by kiegroup.
the class WildflyProviderConfigExecutor method apply.
@Override
public Optional<WildflyProvider> apply(final WildflyProviderConfig wildflyProviderConfig) {
if (wildflyProviderConfig.getName() == null || wildflyProviderConfig.getName().isEmpty()) {
throw new ProvisioningException("No name was provided for the WildflyProviderConfig.getName() " + "configuration parameter. You might probably have to properly set " + "the pipeline input parameter: " + ProviderConfig.PROVIDER_NAME);
}
Provider provider = runtimeRegistry.getProvider(wildflyProviderConfig.getName());
WildflyProvider wildflyProvider;
if (provider != null) {
if (!(provider instanceof WildflyProvider)) {
throw new ProvisioningException("The provider: " + wildflyProviderConfig.getName() + " must be an instance of " + WildflyProviderConfig.class + " but is: " + provider.getClass());
} else {
wildflyProvider = (WildflyProvider) provider;
}
} else {
wildflyProvider = new WildflyProviderImpl(new WildflyProviderConfigImpl(wildflyProviderConfig.getName(), wildflyProviderConfig.getHost(), wildflyProviderConfig.getPort(), wildflyProviderConfig.getManagementPort(), wildflyProviderConfig.getUser(), wildflyProviderConfig.getPassword()));
runtimeRegistry.registerProvider(wildflyProvider);
}
return Optional.of(wildflyProvider);
}
use of org.guvnor.ala.exceptions.ProvisioningException in project kie-wb-common by kiegroup.
the class WildflyRuntimeExecExecutor method destroy.
@Override
public void destroy(final RuntimeId runtimeId) {
final Optional<WildflyProvider> _wildflyProvider = runtimeRegistry.getProvider(runtimeId.getProviderId(), WildflyProvider.class);
WildflyProvider wildflyProvider = _wildflyProvider.get();
int result = wildfly.getWildflyClient(wildflyProvider).undeploy(runtimeId.getId());
if (result != 200) {
throw new ProvisioningException("UnDeployment to Wildfly Failed with error code: " + result);
}
runtimeRegistry.deregisterRuntime(runtimeId);
}
use of org.guvnor.ala.exceptions.ProvisioningException in project kie-wb-common by kiegroup.
the class WildflyRuntimeExecExecutor method create.
private Optional<WildflyRuntime> create(final WildflyRuntimeConfiguration runtimeConfig) throws ProvisioningException {
String warPath = runtimeConfig.getWarPath();
final Optional<WildflyProvider> _wildflyProvider = runtimeRegistry.getProvider(runtimeConfig.getProviderId(), WildflyProvider.class);
if (!_wildflyProvider.isPresent()) {
throw new ProvisioningException("No Wildfly provider was found for providerId: " + runtimeConfig.getProviderId());
}
WildflyProvider wildflyProvider = _wildflyProvider.get();
File file = new File(warPath);
final String id = file.getName();
WildflyAppState appState = wildfly.getWildflyClient(wildflyProvider).getAppState(id);
if (UNKNOWN.equals(appState.getState())) {
int result = wildfly.getWildflyClient(wildflyProvider).deploy(file);
if (result != 200) {
throw new ProvisioningException("Deployment to Wildfly Failed with error code: " + result);
}
} else if ((RUNNING.equals(appState.getState()) || STOPPED.equals(appState.getState())) && (isNullOrEmpty(runtimeConfig.getRedeployStrategy()) || "auto".equals(runtimeConfig.getRedeployStrategy()))) {
wildfly.getWildflyClient(wildflyProvider).undeploy(id);
int result = wildfly.getWildflyClient(wildflyProvider).deploy(file);
if (result != 200) {
throw new ProvisioningException("Deployment to Wildfly Failed with error code: " + result);
}
} else {
throw new ProvisioningException("A runtime with the given identifier: " + id + " is already deployed");
}
String appContext = id.substring(0, id.lastIndexOf(".war"));
WildflyRuntimeEndpoint endpoint = new WildflyRuntimeEndpoint();
endpoint.setHost(wildfly.getWildflyClient(wildflyProvider).getHost());
endpoint.setPort(wildfly.getWildflyClient(wildflyProvider).getPort());
endpoint.setContext(appContext);
return Optional.of(new WildflyRuntime(id, buildRuntimeName(runtimeConfig, id), runtimeConfig, wildflyProvider, endpoint, new WildflyRuntimeInfo(), new WildflyRuntimeState(RUNNING, new Date().toString())));
}
Aggregations