use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class DockerImageLabels method getInstance.
/**
* Returns an instance for a given server behaviour and resource. The server
* behaviour shared data is looked up for a matching instance. If it doesn't
* exists a new one is created. The docker image metadata is lazyly loaded when
* data is requested via {@link #getPodPath()}, {@link #getDevmodePortKey()}
* etc.
*
* @param resource
* @param behaviour
* @return
*
* @see IControllableServerBehavior
* @see IResource
*/
public static DockerImageLabels getInstance(IResource resource, IControllableServerBehavior behaviour) {
DockerImageLabels metadata = (DockerImageLabels) behaviour.getSharedData(SHARED_DATA_KEY);
if (metadata == null || !Objects.equals(resource, metadata.resource)) {
Connection connection = OpenShiftServerUtils.getConnection(behaviour.getServer());
metadata = new DockerImageLabels(resource, connection);
behaviour.putSharedData(SHARED_DATA_KEY, metadata);
}
return metadata;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenShiftServerUtils method getAllPods.
/**
* Returns all pods for the given server. Returns an empty list otherwise.
*
* @param server
* @return
*/
public static Collection<IPod> getAllPods(IServer server, IProgressMonitor monitor) {
Connection connection = getConnection(server);
if (connection == null) {
return Collections.emptyList();
}
IResource resource = getResource(server, connection, monitor);
if (resource == null) {
return Collections.emptyList();
}
List<IPod> collection = new ArrayList<>();
List<IPod> pods = connection.getResources(ResourceKind.POD, resource.getNamespaceName());
List<IPod> servicePods = ResourceUtils.getPodsFor(resource, pods);
collection.addAll(pods);
collection.addAll(servicePods);
return collection;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ImportApplicationHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
ISelection currentSelection = UIUtils.getCurrentSelection(event);
IBuildConfig buildConfig = UIUtils.getFirstElement(currentSelection, IBuildConfig.class);
Map<IProject, Collection<IBuildConfig>> projectsAndBuildConfigs = null;
IProject project = null;
Collection<IBuildConfig> buildConfigs = null;
if (buildConfig == null) {
IResource resource = UIUtils.getFirstElement(currentSelection, IResource.class);
if (resource != null) {
project = resource.getProject();
}
if (project != null) {
buildConfigs = project.getResources(ResourceKind.BUILD_CONFIG);
}
} else {
project = buildConfig.getProject();
buildConfigs = Collections.singleton(buildConfig);
}
if (project != null) {
if (buildConfigs == null || buildConfigs.isEmpty()) {
MessageDialog.openWarning(HandlerUtil.getActiveShell(event), NO_BUILD_CONFIG_MSG, NO_BUILD_CONFIG_MSG);
return OpenShiftUIActivator.statusFactory().cancelStatus(NO_BUILD_CONFIG_MSG);
}
projectsAndBuildConfigs = Collections.singletonMap(project, buildConfigs);
}
if (projectsAndBuildConfigs == null) {
ImportApplicationWizard wizard = new ImportApplicationWizard();
Connection connection = UIUtils.getFirstElement(currentSelection, Connection.class);
wizard.setConnection(connection);
WizardUtils.openWizardDialog(wizard, HandlerUtil.getActiveShell(event));
} else {
WizardUtils.openWizardDialog(new ImportApplicationWizard(projectsAndBuildConfigs), HandlerUtil.getActiveShell(event));
}
return Status.OK_STATUS;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ManageEnvironmentVariablesWizard method performFinish.
@Override
public boolean performFinish() {
new Job("Updating environment variables for deployment config " + dc.getName()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
List<EnvironmentVariable> vars = model.getEnvironmentVariables();
boolean modified = false;
for (EnvironmentVariable var : vars) {
if (model.isEnvironmentVariableModified(var)) {
modified = true;
String value = var.getValue();
if (IEnvironmentVariablesPageModel.DELETED.equals(value)) {
dc.removeEnvironmentVariable(var.getKey());
} else {
dc.setEnvironmentVariable(var.getKey(), var.getValue());
}
}
}
if (modified) {
Connection conn = ConnectionsRegistryUtil.getConnectionFor(dc);
conn.updateResource(dc);
}
} catch (Exception e) {
String message = "Unable to update environment variables for deployment config " + dc.getName();
OpenShiftUIActivator.getDefault().getLogger().logError(message, e);
return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, e);
}
return Status.OK_STATUS;
}
}.schedule();
return true;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenInWebConsoleHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
ISelection currentSelection = UIUtils.getCurrentSelection(event);
IResource resource = UIUtils.getFirstElement(currentSelection, IResource.class);
Connection connection = null;
if (resource == null) {
connection = UIUtils.getFirstElement(currentSelection, Connection.class);
} else {
connection = ConnectionsRegistryUtil.safeGetConnectionFor(resource);
}
String msg;
if (connection == null) {
msg = "Could not find an OpenShift connection to open a console for";
} else {
String url = getWebConsoleUrl(connection, resource);
if (!StringUtils.isEmpty(url)) {
new BrowserUtility().checkedCreateExternalBrowser(url, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
return Status.OK_STATUS;
}
msg = NLS.bind("Could not determine the url for the web console on {0}", connection.getHost());
}
MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "No Web Console Url", msg);
return new Status(IStatus.WARNING, OpenShiftUIActivator.PLUGIN_ID, msg);
}
Aggregations