use of org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException 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.access.exceptions.OpenShiftClientException in project kie-wb-common by kiegroup.
the class OpenShiftClient method getRuntimeEndpoint.
public OpenShiftRuntimeEndpoint getRuntimeEndpoint(String id) throws OpenShiftClientException {
try {
OpenShiftRuntimeId runtimeId = OpenShiftRuntimeId.fromString(id);
String prjName = runtimeId.project();
String svcName = runtimeId.service();
OpenShiftRuntimeEndpoint endpoint = new OpenShiftRuntimeEndpoint();
Route route = delegate.routes().inNamespace(prjName).withName(svcName).get();
if (route != null) {
RouteSpec routeSpec = route.getSpec();
endpoint.setProtocol(routeSpec.getTls() != null ? "https" : "http");
endpoint.setHost(routeSpec.getHost());
RoutePort routePort = routeSpec.getPort();
if (routePort != null) {
IntOrString targetPort = routePort.getTargetPort();
if (targetPort != null) {
endpoint.setPort(targetPort.getIntVal());
}
}
}
return endpoint;
} catch (Throwable t) {
throw new OpenShiftClientException(t.getMessage(), t);
}
}
use of org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException 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.access.exceptions.OpenShiftClientException in project kie-wb-common by kiegroup.
the class OpenShiftClient method destroy.
public void destroy(String id) throws OpenShiftClientException {
try {
OpenShiftRuntimeId runtimeId = OpenShiftRuntimeId.fromString(id);
String prjName = runtimeId.project();
String svcName = runtimeId.service();
// TODO: should we always depend on the app label being specified, or gotten from the service?
String appName = runtimeId.application();
if (appName == null || appName.isEmpty()) {
Service service = delegate.services().inNamespace(prjName).withName(svcName).get();
if (service != null) {
appName = service.getMetadata().getLabels().get(APP_LABEL);
}
}
/*
* cascading delete of deploymentConfigs means we don't have to also do the following:
* delegate.deploymentConfigs().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
* delegate.replicationControllers().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
* delegate.pods().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
* , but deleting services and routes are still necessary:
*/
delegate.deploymentConfigs().inNamespace(prjName).withName(svcName).cascading(true).delete();
if (appName != null) {
delegate.services().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
delegate.routes().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
} else {
delegate.services().inNamespace(prjName).delete();
delegate.routes().inNamespace(prjName).delete();
}
// clean up any generated image streams, secrets, and service accounts
for (ImageStream item : delegate.imageStreams().inNamespace(prjName).list().getItems()) {
if (isGuvnorAlaGenerated(item)) {
delegate.imageStreams().inNamespace(prjName).delete(item);
}
}
for (Secret item : delegate.secrets().inNamespace(prjName).list().getItems()) {
if (isGuvnorAlaGenerated(item)) {
delegate.secrets().inNamespace(prjName).delete(item);
}
}
for (ServiceAccount item : delegate.serviceAccounts().inNamespace(prjName).list().getItems()) {
if (isGuvnorAlaGenerated(item)) {
delegate.serviceAccounts().inNamespace(prjName).delete(item);
}
}
// clean up generated project
if (isGuvnorAlaGenerated(delegate.projects().withName(prjName).get())) {
delegate.projects().withName(prjName).delete();
}
} catch (Throwable t) {
throw new OpenShiftClientException(t.getMessage(), t);
}
}
use of org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException in project kie-wb-common by kiegroup.
the class OpenShiftRuntimeManager method restart.
@Override
public void restart(RuntimeId runtimeId) throws RuntimeOperationException {
OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
try {
LOG.info("Restarting runtime: " + runtimeId.getId());
openshift.getOpenShiftClient(runtime.getProviderId()).restart(runtime.getId());
refresh(runtimeId);
LOG.info("Restarted runtime: " + runtimeId.getId());
} catch (OpenShiftClientException ex) {
LOG.error("Error Restarting runtime: " + runtimeId.getId(), ex);
throw new RuntimeOperationException("Error Restarting runtime: " + runtimeId.getId(), ex);
}
}
Aggregations