use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ResourceMocks method create3ProjectsConnection.
public static Connection create3ProjectsConnection() {
Connection connection = createConnection("http://localhost:8443", "dev@openshift.com");
doReturn(Arrays.asList(PROJECTS)).when(connection).getResources(ResourceKind.PROJECT);
// project 2
mockGetResources(PROJECT2_SERVICES, ResourceKind.SERVICE, PROJECT2, connection);
mockGetResources(PROJECT2_ROUTES, ResourceKind.ROUTE, PROJECT2, connection);
mockGetResources(PROJECT2_BUILDCONFIGS, ResourceKind.BUILD_CONFIG, PROJECT2, connection);
mockGetResources(PROJECT2_PODS, ResourceKind.POD, PROJECT2, connection);
mockGetResources(PROJECT2_REPLICATION_CONTROLLERS, ResourceKind.REPLICATION_CONTROLLER, PROJECT2, connection);
mockGetResources(PROJECT2_DEPLOYMENTCONFIGS, ResourceKind.DEPLOYMENT_CONFIG, PROJECT2, connection);
mockConnectionGetResource(PROJECT2_DEPLOYMENTCONFIGS, ResourceKind.DEPLOYMENT_CONFIG, connection);
// project 3
mockGetResources(PROJECT3_SERVICES, ResourceKind.SERVICE, PROJECT3, connection);
mockGetResources(PROJECT3_ROUTES, ResourceKind.ROUTE, PROJECT3, connection);
// project 4
mockGetResources(PROJECT4_BUILDCONFIGS, ResourceKind.BUILD_CONFIG, PROJECT4, connection);
mockGetResources(PROJECT4_PODS, ResourceKind.POD, PROJECT4, connection);
mockGetResources(PROJECT4_DEPLOYMENTCONFIGS, ResourceKind.DEPLOYMENT_CONFIG, PROJECT4, connection);
mockConnectionGetResource(PROJECT4_DEPLOYMENTCONFIGS, ResourceKind.DEPLOYMENT_CONFIG, connection);
// project 5
mockGetResources(PROJECT5_PODS, ResourceKind.POD, PROJECT5, connection);
mockGetResources(PROJECT5_REPLICATINCONTROLLERS, ResourceKind.REPLICATION_CONTROLLER, PROJECT5, connection);
mockConnectionGetResource(PROJECT5_REPLICATINCONTROLLERS, ResourceKind.REPLICATION_CONTROLLER, connection);
return connection;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ResourceMocks method createConnection.
public static Connection createConnection(String host, String username) {
Connection connection = mock(Connection.class);
when(connection.getHost()).thenReturn(host);
when(connection.getUsername()).thenReturn(username);
when(connection.isDefaultHost()).thenReturn(false);
return connection;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ResourceUtils method getDeploymentConfigFor.
private static IDeploymentConfig getDeploymentConfigFor(IService service, Connection connection) {
if (service == null) {
return null;
}
String dcName = getDeploymentConfigNameFor(service);
if (dcName != null) {
return getDeploymentConfigByName(dcName, service, connection);
} else {
String namespace = service.getNamespaceName();
IReplicationController rc = getReplicationControllerFor(service, connection.getResources(ResourceKind.REPLICATION_CONTROLLER, namespace));
if (rc == null) {
return null;
}
List<IPod> allPods = connection.getResources(ResourceKind.POD, namespace);
List<IPod> pods = allPods.stream().filter(pod -> areRelated((IPod) pod, rc)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(pods)) {
return null;
}
List<IDeploymentConfig> dcs = connection.getResources(ResourceKind.DEPLOYMENT_CONFIG, namespace);
return dcs.stream().filter(dc -> areRelated((IService) service, (IDeploymentConfig) dc, pods)).findFirst().orElse(null);
}
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class DeployImageJob method updateTriggerIfUpdate.
protected boolean updateTriggerIfUpdate(Connection connection, String project, String name) {
try {
IDeploymentConfig dc = connection.getResource(ResourceKind.DEPLOYMENT_CONFIG, project, name);
IDeploymentImageChangeTrigger trigger = (IDeploymentImageChangeTrigger) dc.getTriggers().stream().filter(t -> DeploymentTriggerType.IMAGE_CHANGE.equals(t.getType())).findFirst().orElse(null);
if (trigger == null || !ResourceKind.IMAGE_STREAM_TAG.equals(trigger.getKind()) || StringUtils.isBlank(trigger.getNamespace()) || connection.getResource(ResourceKind.IMAGE_STREAM, trigger.getNamespace(), trigger.getFrom().getName()) == null) {
return false;
}
DockerImageURI sourceImage = getSourceImage();
if (sourceImage.getName().equals(trigger.getFrom().getName()) && !sourceImage.getTag().equals(trigger.getFrom().getTag())) {
trigger.setFrom(new DockerImageURI(null, null, sourceImage.getName(), sourceImage.getTag()));
connection.updateResource(dc);
}
return true;
} catch (NotFoundException e) {
return false;
} catch (OpenShiftException e) {
if (e.getStatus() != null && e.getStatus().getCode() == IHttpConstants.STATUS_NOT_FOUND) {
return false;
}
throw e;
}
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenShiftServerUtilsTest method should_return_connection_from_server.
@Test
public void should_return_connection_from_server() {
// given
// when
Connection connection = OpenShiftServerUtils.getConnection(server);
// then
assertThat(connection).isEqualTo(this.connection);
}
Aggregations