use of com.redhat.devtools.intellij.common.model.GenericResource in project intellij-common by redhat-developer.
the class GenericResourceDeserializerTest method Convert_ResourceIsValid_GenericResource.
@Test
public void Convert_ResourceIsValid_GenericResource() throws IOException {
GenericResource genericResource = mapper.readValue(load("resource.yaml"), GenericResource.class);
assertEquals(genericResource.getApiVersion(), "tekton.dev/v1beta1");
assertEquals(genericResource.getKind(), "Pipeline");
assertEquals(genericResource.getName(), "foo");
assertTrue(genericResource.getMetadata() != null);
assertTrue(genericResource.getSpec() != null);
}
use of com.redhat.devtools.intellij.common.model.GenericResource in project intellij-tekton by redhat-developer.
the class DeployHelper method saveResource.
public static String saveResource(String resourceAsYAML, String namespace, Tkn tkncli) throws IOException {
try {
GenericResource resource = getResource(resourceAsYAML);
Pair<String, Boolean> saveResult = doSave(namespace, resourceAsYAML, false, resource, tkncli);
return saveResult.getFirst();
} catch (KubernetesClientException e) {
throw new IOException(e);
}
}
use of com.redhat.devtools.intellij.common.model.GenericResource in project intellij-tekton by redhat-developer.
the class DeployHelper method saveOnCluster.
public static boolean saveOnCluster(Project project, String namespace, String yaml, String confirmationMessage, boolean updateLabels, boolean skipConfirmatioDialog) throws IOException {
ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "save to cluster");
GenericResource resource = getResource(yaml, telemetry);
Tkn tknCli = TreeHelper.getTkn(project);
if (tknCli == null) {
telemetry.error("tkn not found").send();
return false;
}
if (namespace.isEmpty()) {
namespace = tknCli.getNamespace();
}
if (confirmationMessage.isEmpty()) {
confirmationMessage = getDefaultConfirmationMessage(resource.getName(), resource.getKind());
}
if (!skipConfirmatioDialog && !isSaveConfirmed(confirmationMessage)) {
telemetry.result(VALUE_ABORTED).send();
return false;
}
try {
String resourceNamespace = CRDHelper.isClusterScopedResource(resource.getKind()) ? "" : namespace;
Pair<String, Boolean> saveResult = doSave(resourceNamespace, yaml, updateLabels, resource, tknCli);
telemetry.property(PROP_RESOURCE_CRUD, (saveResult.getSecond() ? VALUE_RESOURCE_CRUD_CREATE : VALUE_RESOURCE_CRUD_UPDATE)).send();
} catch (KubernetesClientException e) {
String errorMsg = createErrorMessage(resource, e);
telemetry.error(anonymizeResource(resource.getName(), namespace, errorMsg)).send();
logger.warn(errorMsg, e);
// give a visual notification to user if an error occurs during saving
throw new IOException(errorMsg, e);
}
return true;
}
Aggregations