Search in sources :

Example 1 with GenericResource

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);
}
Also used : GenericResource(com.redhat.devtools.intellij.common.model.GenericResource) Test(org.junit.Test)

Example 2 with GenericResource

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);
    }
}
Also used : GenericResource(com.redhat.devtools.intellij.common.model.GenericResource) IOException(java.io.IOException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 3 with GenericResource

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;
}
Also used : Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) GenericResource(com.redhat.devtools.intellij.common.model.GenericResource) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) IOException(java.io.IOException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

GenericResource (com.redhat.devtools.intellij.common.model.GenericResource)3 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 IOException (java.io.IOException)2 Tkn (com.redhat.devtools.intellij.tektoncd.tkn.Tkn)1 ActionMessage (com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage)1 Test (org.junit.Test)1