use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ServerAdapterHandler method getOpenShiftServer.
/**
* Finds the OpenShift server corresponding to the selection or prompts the
* user to create one.
*
* @param resource
* the selected OpenShift {@link IResource}
*
* @return the matching OpenShift {@link IServer} or <code>null</code> if
* none was found or user cancelled the creation operation.
*/
private IServer getOpenShiftServer(final IResource resource) {
if (resource == null) {
return null;
}
IResource source = null;
IRoute route = null;
if (resource instanceof IService) {
source = (IService) resource;
} else if (resource instanceof IRoute) {
route = (IRoute) resource;
final IRoute localRoute = route;
source = (IService) route.getProject().getResources(ResourceKind.SERVICE).stream().filter(s -> ResourceUtils.areRelated(localRoute, (IService) s)).findFirst().orElseGet(() -> null);
} else if (resource instanceof IReplicationController) {
source = resource;
} else if (resource instanceof IPod) {
final Collection<IService> services = ResourceUtils.getServicesFor((IPod) resource, resource.getProject().getResources(ResourceKind.SERVICE));
if (!services.isEmpty()) {
source = services.iterator().next();
} else {
source = ResourceUtils.getDeploymentConfigOrReplicationControllerFor((IPod) resource);
}
}
if (source != null) {
final Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(source);
return openOrCreateServerAdapter(source, route, connection);
}
return null;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class DeployImageJob method doRun.
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
final Connection connection = parameters.getConnection();
final String name = parameters.getResourceName();
if (updateTriggerIfUpdate(connection, parameters.getProject().getName(), name)) {
return Status.OK_STATUS;
}
Map<String, IResource> resources = generateResources(connection, name);
// validate
Collection<IResource> existing = findExistingResources(connection, resources.values());
// TODO may need to disregard if only error is the imagestream - TBD
if (!existing.isEmpty()) {
return createErrorStatusForExistingResources(existing);
}
// create
created = createResources(connection, resources.values());
} catch (Exception e) {
String message = NLS.bind("Unable to create resources to deploy image {0}", parameters.getImageName());
OpenShiftUIActivator.getDefault().getLogger().logError(message, e);
return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, e);
}
return Status.OK_STATUS;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class RefreshResourcesJob method doRun.
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
monitor.beginTask("Refreshing OpenShift resources...", IProgressMonitor.UNKNOWN);
refreshedResources.clear();
Collection<IResource> resources = model.getResources();
if (resources == null || resources.isEmpty())
return Status.OK_STATUS;
for (IResource resource : resources) {
if (ResourceKind.STATUS.equals(resource.getKind())) {
continue;
}
Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(resource);
if (connection != null) {
IResource newValue = ((Connection) connection).refresh(resource);
IResource oldValue = resourcesAdded ? null : resource;
refreshedResources.add(newValue);
ConnectionsRegistrySingleton.getInstance().fireConnectionChanged(connection, ConnectionProperties.PROPERTY_RESOURCE, oldValue, newValue);
}
}
} catch (Exception e) {
return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Exception refreshing resources", e);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class AbstractProjectPage method getLoadResourcesJobBuilder.
/**
* Create and configure the list of jobs that need to be performed during
* resource loading. The base behavior is to load the projects and force project
* creation if no project exists.
*
* @param closeAfter
* return parameter if wizard needs to be closed (may be updated)
* @param closeOnCancel
* true if the wizard need to be closed
* @return the job builder
*/
protected JobChainBuilder getLoadResourcesJobBuilder(final boolean[] closeAfter, final boolean closeOnCancel) {
JobChainBuilder builder = new JobChainBuilder(new AbstractDelegatingMonitorJob("Loading projects...") {
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
model.loadResources();
} catch (OpenShiftException e) {
closeAfter[0] = closeOnCancel;
String problem = e.getStatus() == null ? e.getMessage() : e.getStatus().getMessage();
return OpenShiftUIActivator.statusFactory().errorStatus(problem, e);
}
return Status.OK_STATUS;
}
});
builder.runWhenSuccessfullyDone(new UIJob("Verifying required project...") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (!model.hasProjects()) {
List<IProject> projects = new ObservableTreeItem2ModelConverter().convert(model.getProjectItems());
Connection connection = model.getConnection();
NewProjectWizard newProjectWizard = new NewProjectWizard(connection, projects);
if (Dialog.CANCEL == WizardUtils.openWizardDialog(newProjectWizard, getShell())) {
closeAfter[0] = closeOnCancel;
return Status.CANCEL_STATUS;
} else {
model.loadResources();
model.setProject(newProjectWizard.getProject());
}
}
return Status.OK_STATUS;
}
});
return builder;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class NewApplicationWizard method init.
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
fromImageModel.setContainer(getContainer());
if (selection == null || selection.isEmpty()) {
return;
}
org.eclipse.core.resources.IProject selectedProject = UIUtils.getFirstElement(selection, org.eclipse.core.resources.IProject.class);
model.setEclipseProject(selectedProject);
Connection connection = UIUtils.getFirstElement(selection, Connection.class);
if (connection != null) {
setConnection(connection);
} else {
IResource resource = UIUtils.getFirstElement(selection, IResource.class);
if (resource != null) {
connection = ConnectionsRegistryUtil.safeGetConnectionFor(resource);
setConnection(connection);
model.setProject(resource.getProject());
}
}
if (connection != null) {
ConnectionsRegistrySingleton.getInstance().setRecent(connection);
}
}
Aggregations