Search in sources :

Example 1 with IOpenShiftConnection

use of org.jboss.tools.openshift.core.connection.IOpenShiftConnection in project jbosstools-openshift by jbosstools.

the class ConnectionWrapper method startLoadJob.

void startLoadJob(ProjectWrapper projectWrapper, IExceptionHandler handler) {
    new Job(NLS.bind("Loading OpenShift project {0}...", projectWrapper.getWrapped().getName())) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                IProject project = projectWrapper.getWrapped();
                IOpenShiftConnection connection = projectWrapper.getParent().getWrapped();
                WatchManager.getInstance().startWatch(project, connection);
                Collection<IResource> resources = new HashSet<>();
                for (String kind : RESOURCE_KINDS) {
                    resources.addAll(getWrapped().getResources(kind, project.getNamespaceName()));
                }
                resources.forEach(r -> resourceCache.add(r));
                projectWrapper.initWithResources(resources);
                projectWrapper.fireChanged();
            } catch (OperationCanceledException e) {
                projectWrapper.setLoadingState(LoadingState.LOAD_STOPPED);
            } catch (Throwable e) {
                projectWrapper.setLoadingState(LoadingState.LOAD_STOPPED);
                handler.handleException(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
}
Also used : IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) Job(org.eclipse.core.runtime.jobs.Job) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) ConnectionProperties(org.jboss.tools.openshift.core.connection.ConnectionProperties) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) Status(org.eclipse.core.runtime.Status) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) HashSet(java.util.HashSet) List(java.util.List) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) WatchManager(org.jboss.tools.openshift.internal.core.WatchManager) Map(java.util.Map) Collections(java.util.Collections) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Collection(java.util.Collection) Job(org.eclipse.core.runtime.jobs.Job) IProject(com.openshift.restclient.model.IProject)

Example 2 with IOpenShiftConnection

use of org.jboss.tools.openshift.core.connection.IOpenShiftConnection in project jbosstools-openshift by jbosstools.

the class OpenshiftUIModel method refresh.

@Override
public void refresh() {
    Map<IOpenShiftConnection, ConnectionWrapper> updated = new HashMap<>();
    boolean changed = false;
    synchronized (connections) {
        HashMap<IOpenShiftConnection, ConnectionWrapper> oldWrappers = new HashMap<>(connections);
        connections.clear();
        for (IOpenShiftConnection connection : ConnectionsRegistrySingleton.getInstance().getAll(IOpenShiftConnection.class)) {
            ConnectionWrapper existingWrapper = oldWrappers.remove(connection);
            if (existingWrapper == null) {
                ConnectionWrapper newWrapper = new ConnectionWrapper(this, connection);
                connections.put(connection, newWrapper);
                changed = true;
            } else {
                connections.put(connection, existingWrapper);
                updated.put(connection, existingWrapper);
            }
        }
        if (!oldWrappers.isEmpty()) {
            changed = true;
        }
    }
    if (changed) {
        fireChanged(this);
    }
    updated.keySet().forEach(r -> {
        ConnectionWrapper wrapper = updated.get(r);
        wrapper.updateWith(r);
    });
    for (ConnectionWrapper connection : getConnections()) {
        connection.refresh();
    }
}
Also used : IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) HashMap(java.util.HashMap)

Example 3 with IOpenShiftConnection

use of org.jboss.tools.openshift.core.connection.IOpenShiftConnection in project jbosstools-openshift by jbosstools.

the class ConnectionWrapperTest method prepareData.

@Before
public void prepareData() throws Exception {
    this.project = mock(IProject.class);
    when(project.getName()).thenReturn(NAMESPACE);
    when(project.getNamespaceName()).thenReturn(NAMESPACE);
    IOpenShiftConnection connection = mock(IOpenShiftConnection.class);
    when(connection.isDefaultHost()).thenReturn(true);
    when(connection.getUsername()).thenReturn("bdshadow");
    when(connection.getResources(eq(ResourceKind.PROJECT))).thenReturn(Arrays.asList(new IResource[] { project }));
    // by doing this we call a protected OpenshiftUIModel constructor, which adds listener to the
    OpenshiftUIModel.getInstance();
    // ConnectionsRegistrySingleton
    ConnectionsRegistrySingleton.getInstance().add(connection);
    ConnectionWrapper connectionWrapper = OpenshiftUIModel.getInstance().getConnectionWrapperForConnection(connection);
    connectionWrapper.refresh();
    this.projectWrapper = (ProjectWrapper) connectionWrapper.getResources().iterator().next();
    this.resource = mock(IBuildConfig.class);
    when(this.resource.getKind()).thenReturn(ResourceKind.BUILD_CONFIG);
    when(this.resource.getNamespaceName()).thenReturn(NAMESPACE);
    when(this.resource.getProject()).thenReturn(project);
    this.watchListener = new WatchListenerTestable(WatchManager.getInstance(), project, connection, ResourceKind.BUILD_CONFIG, 0, 0);
    watchListener.setState("CONNECTED");
}
Also used : IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) IBuildConfig(com.openshift.restclient.model.IBuildConfig) ConnectionWrapper(org.jboss.tools.openshift.internal.ui.models.ConnectionWrapper) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource) Before(org.junit.Before)

Example 4 with IOpenShiftConnection

use of org.jboss.tools.openshift.core.connection.IOpenShiftConnection in project jbosstools-openshift by jbosstools.

the class OpenShiftProjectCacheTest method testGetProjectForOnlyMakesInitialCallToServer.

@Test
public void testGetProjectForOnlyMakesInitialCallToServer() throws InterruptedException, TimeoutException {
    IOpenShiftConnection connection = connectionWrapper.getWrapped();
    connectionWrapper.load(IExceptionHandler.NULL_HANDLER);
    connectionWrapper.load(IExceptionHandler.NULL_HANDLER);
    UITestUtils.waitForState(connectionWrapper, LoadingState.LOADED);
    verify(connection, times(1)).getResources(ResourceKind.PROJECT);
}
Also used : IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) Test(org.junit.Test)

Example 5 with IOpenShiftConnection

use of org.jboss.tools.openshift.core.connection.IOpenShiftConnection in project jbosstools-openshift by jbosstools.

the class ConnectionPropertySource method getPropertyValue.

@Override
public Object getPropertyValue(Object id) {
    if (id == null) {
        return null;
    }
    if (HOST.equals(id)) {
        return this.connection.toString();
    }
    if (USERNAME.equals(id)) {
        return this.connection.getUsername();
    }
    if (connection instanceof IOpenShiftConnection) {
        IOpenShiftConnection openshiftConnection = (IOpenShiftConnection) this.connection;
        if (OPENSHIFT_MASTER_VERSION.equals(id)) {
            return openshiftConnection.getOpenShiftMasterVersion();
        }
        if (KUBERNETES_MASTER_VERSION.equals(id)) {
            return openshiftConnection.getKubernetesMasterVersion();
        }
        Object result = openshiftConnection.getExtendedProperties().get(id);
        return result == null ? "" : result.toString();
    }
    return null;
}
Also used : IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection)

Aggregations

IOpenShiftConnection (org.jboss.tools.openshift.core.connection.IOpenShiftConnection)7 IProject (com.openshift.restclient.model.IProject)3 IResource (com.openshift.restclient.model.IResource)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 ResourceKind (com.openshift.restclient.ResourceKind)1 IBuildConfig (com.openshift.restclient.model.IBuildConfig)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 NLS (org.eclipse.osgi.util.NLS)1