use of org.guvnor.ala.openshift.model.OpenShiftRuntimeState 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.openshift.model.OpenShiftRuntimeState in project kie-wb-common by kiegroup.
the class OpenShiftRuntimeManager method refresh.
@Override
public void refresh(RuntimeId runtimeId) throws RuntimeOperationException {
OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
if (runtime != null) {
try {
// LOG.info( "Refreshing runtime: " + runtimeId.getId() );
OpenShiftRuntimeState runtimeState = openshift.getOpenShiftClient(runtime.getProviderId()).getRuntimeState(runtime.getId());
OpenShiftRuntime newRuntime = new OpenShiftRuntime(runtime.getId(), runtime.getName(), runtime.getConfig(), runtime.getProviderId(), runtime.getEndpoint(), runtime.getInfo(), runtimeState);
runtimeRegistry.registerRuntime(newRuntime);
} catch (OpenShiftClientException ex) {
LOG.error("Error Refreshing runtime: " + runtimeId.getId(), ex);
throw new RuntimeOperationException("Error Refreshing runtime: " + runtimeId.getId(), ex);
}
}
}
use of org.guvnor.ala.openshift.model.OpenShiftRuntimeState in project kie-wb-common by kiegroup.
the class OpenShiftClient method getRuntimeState.
private OpenShiftRuntimeState getRuntimeState(OpenShiftRuntimeId runtimeId) {
String prjName = runtimeId.project();
String svcName = runtimeId.service();
String state;
String startedAt;
Service service = delegate.services().inNamespace(prjName).withName(svcName).get();
if (service != null) {
Integer replicas = getReplicas(service);
if (replicas != null && replicas.intValue() > 0) {
state = OpenShiftRuntimeState.RUNNING;
} else {
state = OpenShiftRuntimeState.READY;
}
startedAt = service.getMetadata().getCreationTimestamp();
} else {
state = OpenShiftRuntimeState.UNKNOWN;
startedAt = new Date().toString();
}
return new OpenShiftRuntimeState(state, startedAt);
}
use of org.guvnor.ala.openshift.model.OpenShiftRuntimeState in project kie-wb-common by kiegroup.
the class OpenShiftClient method create.
// Support for OpenShiftRuntimeExecExecutor ------------------------------
public OpenShiftRuntimeState create(OpenShiftRuntimeConfig runtimeConfig) throws OpenShiftClientException {
try {
String prjName = runtimeConfig.getProjectName();
String svcName = runtimeConfig.getServiceName();
String appName = runtimeConfig.getApplicationName();
OpenShiftRuntimeId runtimeId = new OpenShiftRuntimeId(prjName, svcName, appName);
OpenShiftRuntimeState runtimeState = getRuntimeState(runtimeId);
if (OpenShiftRuntimeState.UNKNOWN.equals(runtimeState.getState())) {
createProject(prjName);
createFromUri(prjName, runtimeConfig.getResourceSecretsUri());
createFromUri(prjName, runtimeConfig.getResourceStreamsUri());
createFromTemplate(runtimeConfig);
runtimeState = getRuntimeState(runtimeId);
}
if (postCreateListener != null) {
postCreateListener.trigger(this, runtimeConfig);
}
return runtimeState;
} catch (Throwable t) {
if (t instanceof OpenShiftClientException) {
throw (OpenShiftClientException) t;
} else {
throw new OpenShiftClientException(t.getMessage(), t);
}
}
}
use of org.guvnor.ala.openshift.model.OpenShiftRuntimeState in project kie-wb-common by kiegroup.
the class OpenShiftRuntimeMarshallerTest method getValue.
@Override
public OpenShiftRuntime getValue() {
OpenShiftProvider providerId = createOpenShiftProvider();
OpenShiftRuntimeConfig runtimeConfig = new ContextAwareOpenShiftRuntimeExecConfig(RUNTIME_NAME, providerId, APPLICATION_NAME, KIE_SERVER_CONTAINER_DEPLOYMENT, PROJECT_NAME, RESOURCE_SECRETS_URI, RESOURCE_STREAMS_URI, RESOURCE_TEMPLATE_NAME, RESOURCE_TEMPLATE_PARAM_DELIMITER, RESOURCE_TEMPLATE_PARAM_ASSIGNER, RESOURCE_TEMPLATE_PARAM_VALUES, RESOURCE_TEMPLATE_URI, SERVICE_NAME);
return new OpenShiftRuntime(RUNTIME_ID, RUNTIME_NAME, runtimeConfig, providerId, new OpenShiftRuntimeEndpoint(PROTOCOL, HOST, PORT, CONTEXT), new OpenShiftRuntimeInfo(runtimeConfig), new OpenShiftRuntimeState(STATE, STARTED_AT));
}
Aggregations