Search in sources :

Example 31 with ActionMessage

use of com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage in project intellij-redhat-telemetry by redhat-developer.

the class TelemetryMessageBuilderTest method error_should_set_error_property.

@Test
public void error_should_set_error_property() {
    // given
    ActionMessage message = builder.action("the simpsons");
    String error = "nuclear plant emergency";
    // when
    message.error(error);
    // then
    assertThat(message.getError()).isEqualTo(error);
}
Also used : ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) Test(org.junit.jupiter.api.Test)

Example 32 with ActionMessage

use of com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage in project intellij-redhat-telemetry by redhat-developer.

the class TelemetryMessageBuilderTest method send_should_send_message_via_service_facade.

@Test
public void send_should_send_message_via_service_facade() {
    // given
    ActionMessage message = builder.action("gargamel");
    // when
    message.send();
    // then
    verify(serviceFacadeMock).send(any(TelemetryEvent.class));
}
Also used : ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) Test(org.junit.jupiter.api.Test)

Example 33 with ActionMessage

use of com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage in project intellij-redhat-telemetry by redhat-developer.

the class TelemetryMessageBuilderTest method send_should_send_event_with_given_type_name_and_properties.

@Test
public void send_should_send_event_with_given_type_name_and_properties() {
    // given
    String name = "gargamel";
    String key1 = "the lovliest";
    String value1 = "smurfette";
    String key2 = "the smallest";
    String value2 = "baby smurf";
    ActionMessage message = builder.action(name).property(key1, value1).property(key2, value2);
    ArgumentCaptor<TelemetryEvent> eventArgument = ArgumentCaptor.forClass(TelemetryEvent.class);
    // when
    message.send();
    // then
    verify(serviceFacadeMock).send(eventArgument.capture());
    TelemetryEvent event = eventArgument.getValue();
    assertThat(event.getType()).isEqualTo(ACTION);
    assertThat(event.getName()).isEqualTo(name);
    assertThat(event.getProperties()).containsEntry(key1, value1);
    assertThat(event.getProperties()).containsEntry(key2, value2);
}
Also used : ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) Test(org.junit.jupiter.api.Test)

Example 34 with ActionMessage

use of com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage 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)

Example 35 with ActionMessage

use of com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage in project intellij-tekton by redhat-developer.

the class CancelAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_START_STOP + "cancel");
    ExecHelper.submit(() -> {
        ParentableNode element = getElement(selected);
        String namespace = element.getNamespace();
        try {
            if (element instanceof PipelineRunNode) {
                tkncli.cancelPipelineRun(namespace, element.getName());
                telemetry.property(TelemetryService.PROP_RESOURCE_KIND, Constants.KIND_PIPELINERUN).send();
            } else if (element instanceof TaskRunNode) {
                tkncli.cancelTaskRun(namespace, element.getName());
                telemetry.property(TelemetryService.PROP_RESOURCE_KIND, Constants.KIND_TASKRUN).send();
            }
        } catch (IOException e) {
            telemetry.error(anonymizeResource(element.getName(), namespace, e.getMessage())).send();
            Notification notification = new Notification(NOTIFICATION_ID, "Error", element.getName() + " in namespace " + namespace + " failed to cancel\n" + e.getLocalizedMessage(), NotificationType.ERROR);
            Notifications.Bus.notify(notification);
            logger.warn("Error: " + e.getLocalizedMessage(), e);
        }
    });
}
Also used : ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) TaskRunNode(com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode) IOException(java.io.IOException) Notification(com.intellij.notification.Notification) PipelineRunNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)

Aggregations

ActionMessage (com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage)39 Test (org.junit.jupiter.api.Test)26 IOException (java.io.IOException)11 ParentableNode (com.redhat.devtools.intellij.tektoncd.tree.ParentableNode)6 Notification (com.intellij.notification.Notification)3 PipelineRunNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)3 TaskRunNode (com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode)3 Tkn (com.redhat.devtools.intellij.tektoncd.tkn.Tkn)2 PipelineNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineNode)2 TektonTreeStructure (com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure)2 Duration (java.time.Duration)2 LocalDateTime (java.time.LocalDateTime)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Project (com.intellij.openapi.project.Project)1 Messages (com.intellij.openapi.ui.Messages)1 GenericResource (com.redhat.devtools.intellij.common.model.GenericResource)1 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)1 UIHelper (com.redhat.devtools.intellij.common.utils.UIHelper)1