Search in sources :

Example 11 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_NOT_set_result_if_error_exists.

@Test
public void send_should_NOT_set_result_if_error_exists() throws InterruptedException {
    // given
    ActionMessage message = builder.action("jolly jumper");
    message.error("lost luky luke");
    // when
    TelemetryEvent event = message.send();
    // then
    assertThat(event.getProperties().get(PROP_RESULT)).isNull();
}
Also used : ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) Test(org.junit.jupiter.api.Test)

Example 12 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 finished_should_set_duration.

@Test
public void finished_should_set_duration() throws InterruptedException {
    // given
    ActionMessage message = builder.action("inspector gadget");
    final long delay = 1 * 1000;
    Thread.sleep(delay);
    // when
    message.finished();
    // then
    assertThat(TimeUtils.toDuration(message.getDuration())).isGreaterThanOrEqualTo(Duration.ofMillis(delay));
}
Also used : ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) Test(org.junit.jupiter.api.Test)

Example 13 with ActionMessage

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

the class AddTriggerAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "add trigger");
    ParentableNode element = getElement(selected);
    String namespace = element.getNamespace();
    ExecHelper.submit(() -> {
        try {
            String triggerVersion = tkncli.getTektonTriggersApiVersion();
            Map<String, String> triggerBindingTemplates = SnippetHelper.getTriggerBindingTemplates(triggerVersion);
            AddTriggerModel model = createModel(element, namespace, tkncli);
            if (!model.isValid()) {
                UIHelper.executeInUI(() -> Messages.showErrorDialog(model.getErrorMessage(), "Error"));
                return;
            }
            String kind = (element instanceof PipelineNode) ? "Pipeline " : "Task ";
            telemetry.property(PROP_RESOURCE_KIND, kind);
            AddTriggerWizard addTriggerWizard = openTriggerBindingWizard(anActionEvent, element, triggerBindingTemplates, model, kind);
            if (!addTriggerWizard.isOK()) {
                telemetry.result(VALUE_ABORTED).send();
                return;
            }
            createNewVolumes(model.getWorkspaces(), tkncli);
            // take/create all triggerBindings
            Map<String, String> triggerBindingsSelected = model.getBindingsSelectedByUser();
            saveTriggerBindings(triggerBindingsSelected, namespace, tkncli);
            // get all params from bindings
            Set<String> paramsFromBindings = model.extractVariablesFromSelectedBindings();
            // interpolate the variables correctly $variable to $(tt.params.variable)
            normalizeVariablesInterpolation(model, paramsFromBindings);
            // create the triggerTemplate
            String randomString = Utils.getRandomString(6);
            String triggerTemplateName = element.getName() + "-template-" + randomString;
            ObjectNode run = createNode(element, model);
            String triggerApiVersion = tkncli.getTektonTriggersApiVersion();
            ObjectNode triggerTemplate = YAMLBuilder.createTriggerTemplate(triggerTemplateName, triggerApiVersion, new ArrayList<>(paramsFromBindings), Arrays.asList(run));
            saveResource(YAMLHelper.JSONToYAML(triggerTemplate), namespace, KIND_TRIGGERTEMPLATES, tkncli);
            notifySuccessOperation("TriggerTemplate " + triggerTemplateName);
            // create the eventListener
            String eventListenerName = element.getName() + "-listener-" + randomString;
            // TODO we are using the default pipeline serviceAccount but we should allow users to select the one they prefer
            ObjectNode eventListener = YAMLBuilder.createEventListener(eventListenerName, triggerApiVersion, "pipeline", triggerBindingsSelected.keySet().stream().map(binding -> binding.replace(" NEW", "")).collect(Collectors.toList()), triggerTemplateName);
            saveResource(YAMLHelper.JSONToYAML(eventListener), namespace, KIND_EVENTLISTENERS, tkncli);
            telemetry.result("bindings and resources created").send();
            notifySuccessOperation("EventListener " + eventListenerName);
            TreeHelper.refresh(getEventProject(anActionEvent), (ParentableNode) ((ParentableNode) element.getParent()).getParent());
        } catch (IOException e) {
            String errorMessage = "Failed to add a trigger to " + element.getName() + " in namespace " + namespace + "\n" + e.getLocalizedMessage();
            telemetry.error(anonymizeResource(element.getName(), namespace, errorMessage)).send();
            Notification notification = new Notification(NOTIFICATION_ID, "Error", errorMessage, NotificationType.ERROR);
            Notifications.Bus.notify(notification);
            logger.warn(errorMessage, e);
        }
    });
}
Also used : AddTriggerWizard(com.redhat.devtools.intellij.tektoncd.ui.wizard.addtrigger.AddTriggerWizard) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) IOException(java.io.IOException) PipelineNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineNode) Notification(com.intellij.notification.Notification)

Example 14 with ActionMessage

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

the class DeleteAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath[] path, Object[] selected, Tkn tkncli) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "delete resource");
    ParentableNode[] elements = Arrays.stream(selected).map(item -> getElement(item)).toArray(ParentableNode[]::new);
    ExecHelper.submit(() -> {
        String deleteText = getDeleteText(tkncli, elements);
        int resultDialog = UIHelper.executeInUI(() -> {
            DeleteDialog delDialog = new DeleteDialog(null, getTitle(elements), deleteText, getDeleteChkText(elements));
            delDialog.show();
            if (delDialog.isOK()) {
                return delDialog.hasToDeleteRelatedResources() ? OK_DELETE_RESOURCES_CODE : OK_DELETE_CODE;
            }
            return CANCEL_CODE;
        });
        if (resultDialog != CANCEL_CODE) {
            String namespace = elements[0].getNamespace();
            boolean deleteRelatedResources = resultDialog == OK_DELETE_RESOURCES_CODE;
            Map<Class, List<ParentableNode>> resourcesByClass = TreeHelper.getResourcesByClass(elements);
            for (Class type : resourcesByClass.keySet()) {
                try {
                    deleteResources(type, resourcesByClass, namespace, deleteRelatedResources, tkncli);
                    ((TektonTreeStructure) getTree(anActionEvent).getClientProperty(Constants.STRUCTURE_PROPERTY)).fireModified(resourcesByClass.get(type).get(0).getParent());
                    telemetry.property(TelemetryService.PROP_RESOURCE_KIND, type.getSimpleName()).property(TelemetryService.PROP_RESOURCE_RELATED, String.valueOf(deleteRelatedResources)).success().send();
                } catch (IOException e) {
                    telemetry.error(anonymizeResource(null, namespace, e.getMessage())).send();
                    UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Error"));
                }
            }
        }
    });
}
Also used : ClusterTaskNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTaskNode) Arrays(java.util.Arrays) RefUsage(com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage) TreeHelper(com.redhat.devtools.intellij.tektoncd.utils.TreeHelper) KIND_TASK(com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASK) ConditionNode(com.redhat.devtools.intellij.tektoncd.tree.ConditionNode) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) PipelineRunNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode) TaskNode(com.redhat.devtools.intellij.tektoncd.tree.TaskNode) Constants(com.redhat.devtools.intellij.tektoncd.Constants) TriggerTemplateNode(com.redhat.devtools.intellij.tektoncd.tree.TriggerTemplateNode) ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Map(java.util.Map) TelemetryService(com.redhat.devtools.intellij.tektoncd.telemetry.TelemetryService) Messages(com.intellij.openapi.ui.Messages) UIHelper(com.redhat.devtools.intellij.common.utils.UIHelper) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) TaskRunNode(com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode) AnonymizeUtils.anonymizeResource(com.redhat.devtools.intellij.telemetry.core.util.AnonymizeUtils.anonymizeResource) KIND_CLUSTERTASK(com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASK) TreePath(javax.swing.tree.TreePath) IOException(java.io.IOException) NAME_PREFIX_CRUD(com.redhat.devtools.intellij.tektoncd.telemetry.TelemetryService.NAME_PREFIX_CRUD) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) DeleteDialog(com.redhat.devtools.intellij.tektoncd.ui.DeleteDialog) Collectors(java.util.stream.Collectors) TektonTreeStructure(com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure) PipelineNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineNode) List(java.util.List) ClusterTriggerBindingNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingNode) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) EventListenerNode(com.redhat.devtools.intellij.tektoncd.tree.EventListenerNode) ResourceNode(com.redhat.devtools.intellij.tektoncd.tree.ResourceNode) TriggerBindingNode(com.redhat.devtools.intellij.tektoncd.tree.TriggerBindingNode) TektonTreeStructure(com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure) IOException(java.io.IOException) DeleteDialog(com.redhat.devtools.intellij.tektoncd.ui.DeleteDialog) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) List(java.util.List)

Example 15 with ActionMessage

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

the class RefreshAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_MISC + "refresh");
    selected = StructureTreeAction.getElement(selected);
    TektonTreeStructure structure = (TektonTreeStructure) getTree(anActionEvent).getClientProperty(Constants.STRUCTURE_PROPERTY);
    structure.fireModified(selected);
    telemetry.property(PROP_RESOURCE_KIND, selected.getClass().getSimpleName()).send();
}
Also used : TektonTreeStructure(com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage)

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