Search in sources :

Example 21 with Connection

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;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection)

Example 22 with 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;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection)

Example 23 with 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);
    }
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) IBuildConfig(com.openshift.restclient.model.IBuildConfig) KeyValueFilterFactory(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IProject(com.openshift.restclient.model.IProject) HashSet(java.util.HashSet) IPod(com.openshift.restclient.model.IPod) IClientCapability(com.openshift.restclient.capability.resources.IClientCapability) CollectionUtils(org.apache.commons.collections.CollectionUtils) EGitUtils(org.jboss.tools.openshift.egit.core.EGitUtils) Map(java.util.Map) KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) URIish(org.eclipse.jgit.transport.URIish) OpenShiftResourceSelectors(org.jboss.tools.openshift.core.OpenShiftResourceSelectors) ITags(com.openshift.restclient.capability.resources.ITags) IImageStreamImport(com.openshift.restclient.model.image.IImageStreamImport) StatusFactory(org.jboss.tools.foundation.core.plugin.log.StatusFactory) IService(com.openshift.restclient.model.IService) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) MapUtils(org.apache.commons.collections.MapUtils) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) IBuild(com.openshift.restclient.model.IBuild) Set(java.util.Set) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) Collectors(java.util.stream.Collectors) IObjectReference(com.openshift.restclient.model.IObjectReference) Connection(org.jboss.tools.openshift.core.connection.Connection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IClient(com.openshift.restclient.IClient) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) IRoute(com.openshift.restclient.model.route.IRoute) Optional(java.util.Optional) ModelNode(org.jboss.dmr.ModelNode) Comparator(java.util.Comparator) Collections(java.util.Collections) IReplicationController(com.openshift.restclient.model.IReplicationController) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IReplicationController(com.openshift.restclient.model.IReplicationController) IPod(com.openshift.restclient.model.IPod) IService(com.openshift.restclient.model.IService)

Example 24 with Connection

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;
    }
}
Also used : ResourceCreationJobUtils.findExistingResources(org.jboss.tools.openshift.internal.ui.job.ResourceCreationJobUtils.findExistingResources) StringUtils(org.apache.commons.lang.StringUtils) IImageStream(com.openshift.restclient.model.IImageStream) HashMap(java.util.HashMap) AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) DockerImageUtils(org.jboss.tools.openshift.internal.core.docker.DockerImageUtils) OpenShiftException(com.openshift.restclient.OpenShiftException) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ITargetPort(com.openshift.restclient.model.route.ITargetPort) IStatus(org.eclipse.core.runtime.IStatus) Map(java.util.Map) NotFoundException(com.openshift.restclient.NotFoundException) IResourceFactory(com.openshift.restclient.IResourceFactory) Trace(org.jboss.tools.openshift.internal.core.Trace) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) IService(com.openshift.restclient.model.IService) ResourceCreationJobUtils.createErrorStatusForExistingResources(org.jboss.tools.openshift.internal.ui.job.ResourceCreationJobUtils.createErrorStatusForExistingResources) IHttpConstants(com.openshift.restclient.http.IHttpConstants) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) Connection(org.jboss.tools.openshift.core.connection.Connection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeployImageParameters(org.jboss.tools.openshift.internal.ui.wizard.deployimage.IDeployImageParameters) List(java.util.List) ICommonAttributes(org.jboss.tools.openshift.core.ICommonAttributes) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IServicePort(com.openshift.restclient.model.IServicePort) IRoute(com.openshift.restclient.model.route.IRoute) DeploymentTriggerType(com.openshift.restclient.model.deploy.DeploymentTriggerType) Collections(java.util.Collections) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) DockerImageURI(com.openshift.restclient.images.DockerImageURI) OpenShiftException(com.openshift.restclient.OpenShiftException) NotFoundException(com.openshift.restclient.NotFoundException) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)

Example 25 with Connection

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);
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) Test(org.junit.Test)

Aggregations

Connection (org.jboss.tools.openshift.core.connection.Connection)110 Test (org.junit.Test)48 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)30 IResource (com.openshift.restclient.model.IResource)27 IProject (com.openshift.restclient.model.IProject)18 IService (com.openshift.restclient.model.IService)11 IStatus (org.eclipse.core.runtime.IStatus)11 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)9 Collection (java.util.Collection)8 List (java.util.List)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IPod (com.openshift.restclient.model.IPod)7 ArrayList (java.util.ArrayList)7 CoreException (org.eclipse.core.runtime.CoreException)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IRoute (com.openshift.restclient.model.route.IRoute)6 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Status (org.eclipse.core.runtime.Status)6