Search in sources :

Example 91 with IResource

use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.

the class ResourceDetailsLabelProvider method getStyledText.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public StyledString getStyledText(Object element) {
    if (element instanceof IResource) {
        IResource resource = (IResource) element;
        StyledString text = new StyledString(StringUtils.capitalize(resource.getKind()));
        text.append(" ").append(replaceParameters(resource.getName()), StyledString.QUALIFIER_STYLER);
        return text;
    }
    if (element instanceof ResourceProperty) {
        ResourceProperty property = (ResourceProperty) element;
        StyledString text = new StyledString(StringUtils.capitalize(property.getProperty()));
        text.append(": ");
        String value = null;
        if (property.getValue() instanceof Map) {
            value = org.jboss.tools.openshift.common.core.utils.StringUtils.serialize((Map) property.getValue());
        } else if (property.getValue() instanceof Collection) {
            value = StringUtils.join((Collection) property.getValue(), ", ");
        } else {
            value = property.getValue() != null ? property.getValue().toString() : "";
        }
        if (StringUtils.isBlank(value)) {
            if (property.isUnknownValue()) {
                value = LABEL_UNKNOWN;
            } else {
                value = LABEL_NOT_PROVIDED;
            }
        }
        text.append(replaceParameters(value), StyledString.QUALIFIER_STYLER);
        return text;
    }
    return null;
}
Also used : ResourceProperty(org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsContentProvider.ResourceProperty) Collection(java.util.Collection) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Map(java.util.Map) IResource(com.openshift.restclient.model.IResource)

Example 92 with IResource

use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.

the class NewApplicationWizardModel method getLocalAppSource.

private IApplicationSource getLocalAppSource(IProgressMonitor monitor, String filename) {
    if (StringUtils.isBlank(filename)) {
        return null;
    }
    IResource resource = null;
    filename = VariablesHelper.replaceVariables(filename);
    try {
        if (!OpenshiftUIConstants.URL_VALIDATOR.isValid(filename) && !Files.isRegularFile(Paths.get(filename))) {
            return null;
        }
        try (InputStream input = createInputStream(filename, monitor)) {
            resource = resourceFactory.create(input);
            if (resource != null && !(resource instanceof ITemplate)) {
                throw new NotATemplateException(resource.getKind());
            }
        }
    } catch (FileNotFoundException e) {
        throw new OpenShiftException(e, NLS.bind("Could not find the file \"{0}\" to upload", filename));
    } catch (IOException e) {
        throw new OpenShiftException(e, NLS.bind("Error reading the file or URL \"{0}\" to upload", filename));
    } catch (ResourceFactoryException | ClassCastException e) {
        throw e;
    }
    switch(resource.getKind()) {
        case ResourceKind.TEMPLATE:
            return new TemplateApplicationSource((ITemplate) resource);
    }
    throw new OpenShiftException("Creating applications from local files is only allowed using a template");
}
Also used : OpenShiftException(com.openshift.restclient.OpenShiftException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) TemplateApplicationSource(org.jboss.tools.openshift.internal.ui.wizard.newapp.fromtemplate.TemplateApplicationSource) ITemplate(com.openshift.restclient.model.template.ITemplate) IOException(java.io.IOException) IResource(com.openshift.restclient.model.IResource) ResourceFactoryException(com.openshift.restclient.ResourceFactoryException)

Example 93 with IResource

use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.

the class ResourceDetailsContentProvider method getChildren.

@Override
public Object[] getChildren(Object node) {
    if (node instanceof IResource) {
        IResource resource = (IResource) node;
        Collection<ResourceProperty> properties = new ArrayList<>();
        properties.add(new ResourceProperty("labels", resource.getLabels()));
        switch(resource.getKind()) {
            case ResourceKind.BUILD_CONFIG:
                addBuildConfigProperties(properties, (IBuildConfig) resource);
                break;
            case ResourceKind.DEPLOYMENT_CONFIG:
                addDeploymentConfigProperties(properties, (IDeploymentConfig) resource);
                break;
            case ResourceKind.SERVICE:
                addServiceProperties(properties, (IService) resource);
                break;
            case ResourceKind.ROUTE:
                addRouteProperties(properties, (IRoute) resource);
                break;
            case ResourceKind.IMAGE_STREAM:
                addImageStreamProperties(properties, (IImageStream) resource);
                break;
            default:
        }
        return properties.toArray();
    }
    return new Object[] {};
}
Also used : ArrayList(java.util.ArrayList) IResource(com.openshift.restclient.model.IResource)

Example 94 with IResource

use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.

the class ApplicationSourceFromImageModel method lookupImageMetadata.

@Override
protected IDockerImageMetadata lookupImageMetadata() {
    if (source == null) {
        return null;
    }
    try {
        Connection conn = ConnectionsRegistryUtil.getConnectionFor(getProject());
        IResource istag = conn.getResource(ResourceKind.IMAGE_STREAM_TAG, source.getNamespace(), source.getName());
        return new ImageStreamTagMetaData(istag.toJson(true));
    } catch (Exception e) {
        OpenShiftUIActivator.getDefault().getLogger().logError(NLS.bind("Unable to retrieve imagestream tag for {0}", getImageName()), e);
    }
    return null;
}
Also used : ImageStreamTagMetaData(org.jboss.tools.openshift.internal.core.docker.ImageStreamTagMetaData) Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 95 with IResource

use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.

the class OpenShiftServerUtilsTest method should_return_service_from_server.

@Test
public void should_return_service_from_server() {
    // given
    // when
    IResource resource = OpenShiftServerUtils.getResource(server, connection, new NullProgressMonitor());
    // then
    assertThat(resource).isEqualTo(ResourceMocks.PROJECT2_SERVICES[1]);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Aggregations

IResource (com.openshift.restclient.model.IResource)101 Test (org.junit.Test)32 Connection (org.jboss.tools.openshift.core.connection.Connection)27 IProject (com.openshift.restclient.model.IProject)14 IStatus (org.eclipse.core.runtime.IStatus)12 Collection (java.util.Collection)10 ServerResourceViewModel (org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel)9 IReplicationController (com.openshift.restclient.model.IReplicationController)8 IService (com.openshift.restclient.model.IService)8 ArrayList (java.util.ArrayList)8 CoreException (org.eclipse.core.runtime.CoreException)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)7 Status (org.eclipse.core.runtime.Status)7 ISelection (org.eclipse.jface.viewers.ISelection)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IPod (com.openshift.restclient.model.IPod)6 List (java.util.List)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IBuildConfig (com.openshift.restclient.model.IBuildConfig)5