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;
}
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");
}
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[] {};
}
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;
}
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]);
}
Aggregations