use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ResourceUtilsTest method shouldReturnDeploymentConfigForServiceByNameGivenServiceHasDCNameSelector.
@Test
public void shouldReturnDeploymentConfigForServiceByNameGivenServiceHasDCNameSelector() throws CoreException {
// given
Connection connection = ResourceMocks.create3ProjectsConnection();
IService service = ResourceMocks.PROJECT2_SERVICES[1];
// when
IDeploymentConfig dc = ResourceUtils.getDeploymentConfigFor(service, connection);
// then
assertThat(dc).isEqualTo(ResourceMocks.PROJECT2_DEPLOYMENTCONFIGS[2]);
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ConnectionPropertySourceTest method setup.
@Before
public void setup() throws Exception {
connection = new Connection("http://localhost:8080", null, null);
connection.setUsername("foo");
source = new ConnectionPropertySource(connection);
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenShiftServerUtils method getConnection.
/**
* Returns the connection for the given server. Returns {@code null} if none was
* found.
*
* @param server
* @return
*/
public static Connection getConnection(IServerAttributes server) {
if (server == null) {
return null;
}
Connection connection = null;
try {
String url = getConnectionURL(server);
if (StringUtils.isEmpty(url)) {
return null;
}
ConnectionURL connectionUrl = ConnectionURL.forURL(url);
if (connectionUrl != null) {
connection = ConnectionsRegistrySingleton.getInstance().getByUrl(connectionUrl, Connection.class);
}
if (connection == null) {
OpenShiftCoreActivator.pluginLog().logError(NLS.bind("Could not find an existing OpenShift connection to host {0} with user {1} for server {2}", new String[] { connectionUrl.getHost(), connectionUrl.getUsername(), server.getName() }));
}
} catch (UnsupportedEncodingException | MalformedURLException e) {
OpenShiftCoreActivator.pluginLog().logError(NLS.bind("Connection url stored in server {0} is malformed.", server.getName()), e);
}
return connection;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenShiftPropertySourceAdapterFactory method getAdapter.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType == IPropertySource.class) {
Connection connection = Adapters.adapt(adaptableObject, Connection.class);
if (connection != null) {
if (currentConnectionPropertySource != null) {
currentConnectionPropertySource.dispose();
}
return currentConnectionPropertySource = new ConnectionPropertySource(connection);
}
IResource resource = Adapters.adapt(adaptableObject, IResource.class);
if (resource != null) {
switch(resource.getKind()) {
case ResourceKind.BUILD:
return new BuildPropertySource((IBuild) resource);
case ResourceKind.BUILD_CONFIG:
return new BuildConfigPropertySource((IBuildConfig) resource);
case ResourceKind.EVENT:
return new EventPropertySource((IEvent) resource);
case ResourceKind.IMAGE_STREAM:
return new ImageStreamPropertySource((IImageStream) resource);
case ResourceKind.POD:
return new PodPropertySource((IPod) resource);
case ResourceKind.REPLICATION_CONTROLLER:
return new ReplicationControllerPropertySource((IReplicationController) resource);
case ResourceKind.ROUTE:
return new RoutePropertySource((IRoute) resource);
case ResourceKind.SERVICE:
return new ServicePropertySource((IService) resource);
case ResourceKind.PVC:
return new StoragePropertySource((IPersistentVolumeClaim) resource);
default:
return new ResourcePropertySource<>(resource);
}
}
}
return null;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ImportApplicationWizard method init.
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
if (model.getConnection() != null && model.getSelectedItem() != null) {
return;
}
Connection connection = UIUtils.getFirstElement(selection, Connection.class);
if (connection != null) {
model.setConnection(connection);
} else {
IResource resource = UIUtils.getFirstElement(selection, IResource.class);
if (resource != null) {
setModelConnection(ConnectionsRegistryUtil.safeGetConnectionFor(resource));
model.setSelectedItem(resource);
} else {
IProject project = UIUtils.getFirstElement(selection, IProject.class);
if (project != null) {
setModelConnection(ConnectionsRegistryUtil.safeGetConnectionFor(project));
model.setSelectedItem(project);
}
}
}
}
Aggregations