Search in sources :

Example 1 with RefUsage

use of com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage in project intellij-tekton by redhat-developer.

the class TknCli method findTaskUsages.

@Override
public List<RefUsage> findTaskUsages(String kind, String resource) throws IOException {
    String jsonPathExpr = "jsonpath=\\\"{range .items[*]}{@.metadata.name}|{range .spec.tasks[*]}{.taskRef.kind},{.taskRef.name}|{end}{end}\\\"";
    String result = ExecHelper.execute(command, envVars, "pipeline", "ls", "-n", getNamespace(), "-o", jsonPathExpr);
    String[] resultSplitted = result.replace("\"", "").split("\\|");
    List<RefUsage> usages = new ArrayList<>();
    String pipeline = "";
    for (String item : resultSplitted) {
        if (!item.contains(",")) {
            pipeline = item;
            continue;
        }
        String[] kindName = item.split(",");
        if (kindName.length == 2 && kindName[0].equalsIgnoreCase(kind) && kindName[1].equalsIgnoreCase(resource) && !pipeline.isEmpty()) {
            String finalPipeline = pipeline;
            Optional<RefUsage> refUsage = usages.stream().filter(ref -> ref.getKind().equals(KIND_PIPELINE) && ref.getName().equals(finalPipeline)).findFirst();
            if (refUsage.isPresent()) {
                refUsage.get().incremetOccurrence();
            } else {
                usages.add(new RefUsage(getNamespace(), pipeline, KIND_PIPELINE));
            }
        }
    }
    return usages;
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) Arrays(java.util.Arrays) Watcher(io.fabric8.kubernetes.client.Watcher) KIND_PIPELINERUN(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINERUN) FLAG_OUTPUTRESOURCE(com.redhat.devtools.intellij.tektoncd.Constants.FLAG_OUTPUTRESOURCE) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) Constants(com.redhat.devtools.intellij.tektoncd.Constants) ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Level(org.apache.log4j.Level) Map(java.util.Map) TektonClient(io.fabric8.tekton.client.TektonClient) KUBERNETES_VERSION(com.redhat.devtools.intellij.tektoncd.telemetry.TelemetryService.KUBERNETES_VERSION) FLAG_WORKSPACE(com.redhat.devtools.intellij.tektoncd.Constants.FLAG_WORKSPACE) TaskRunList(io.fabric8.tekton.pipeline.v1beta1.TaskRunList) ExecWatch(io.fabric8.kubernetes.client.dsl.ExecWatch) TaskRun(io.fabric8.tekton.pipeline.v1beta1.TaskRun) PollingHelper(com.redhat.devtools.intellij.tektoncd.utils.PollingHelper) StandardCharsets(java.nio.charset.StandardCharsets) ClusterTask(io.fabric8.tekton.pipeline.v1beta1.ClusterTask) Config(io.fabric8.kubernetes.client.Config) TRIGGER_BETA1_API_VERSION(com.redhat.devtools.intellij.tektoncd.Constants.TRIGGER_BETA1_API_VERSION) FLAG_PARAMETER(com.redhat.devtools.intellij.tektoncd.Constants.FLAG_PARAMETER) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) TaskList(io.fabric8.tekton.pipeline.v1beta1.TaskList) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) EventListener(io.fabric8.tekton.triggers.v1alpha1.EventListener) Watch(io.fabric8.kubernetes.client.Watch) NetworkUtils(com.redhat.devtools.intellij.common.utils.NetworkUtils) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) WatcherException(io.fabric8.kubernetes.client.WatcherException) TelemetryService(com.redhat.devtools.intellij.tektoncd.telemetry.TelemetryService) JavaType(com.fasterxml.jackson.databind.JavaType) IS_OPENSHIFT(com.redhat.devtools.intellij.tektoncd.telemetry.TelemetryService.IS_OPENSHIFT) Pod(io.fabric8.kubernetes.api.model.Pod) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) FLAG_TASKSERVICEACCOUNT(com.redhat.devtools.intellij.tektoncd.Constants.FLAG_TASKSERVICEACCOUNT) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) WatchHandler(com.redhat.devtools.intellij.tektoncd.utils.WatchHandler) File(java.io.File) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) JsonFactory(com.fasterxml.jackson.core.JsonFactory) CustomPodOperationsImpl(com.redhat.devtools.intellij.tektoncd.ui.toolwindow.debug.CustomPodOperationsImpl) PodList(io.fabric8.kubernetes.api.model.PodList) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) KIND_TASKRUN(com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASKRUN) PersistentVolumeClaimSpec(io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec) FLAG_SERVICEACCOUNT(com.redhat.devtools.intellij.tektoncd.Constants.FLAG_SERVICEACCOUNT) RefUsage(com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage) PipelineResource(io.fabric8.tekton.resource.v1alpha1.PipelineResource) URL(java.net.URL) VirtualFileHelper(com.redhat.devtools.intellij.tektoncd.utils.VirtualFileHelper) URISyntaxException(java.net.URISyntaxException) Platform(com.twelvemonkeys.lang.Platform) LoggerFactory(org.slf4j.LoggerFactory) TriggerTemplate(io.fabric8.tekton.triggers.v1alpha1.TriggerTemplate) ClusterInfo(com.redhat.devtools.intellij.common.kubernetes.ClusterInfo) TRIGGER_ALPHA1_API_VERSION(com.redhat.devtools.intellij.tektoncd.Constants.TRIGGER_ALPHA1_API_VERSION) CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HttpClientUtils(io.fabric8.kubernetes.client.utils.HttpClientUtils) NAME_PREFIX_DIAG(com.redhat.devtools.intellij.tektoncd.telemetry.TelemetryService.NAME_PREFIX_DIAG) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) FLAG_PREFIXNAME(com.redhat.devtools.intellij.tektoncd.Constants.FLAG_PREFIXNAME) TriggerBinding(io.fabric8.tekton.triggers.v1alpha1.TriggerBinding) StatefulSetCondition(io.fabric8.kubernetes.api.model.apps.StatefulSetCondition) ExecWebSocketListener(io.fabric8.kubernetes.client.dsl.internal.ExecWebSocketListener) FLAG_INPUTRESOURCETASK(com.redhat.devtools.intellij.tektoncd.Constants.FLAG_INPUTRESOURCETASK) FLAG_SKIP_OPTIONAL_WORKSPACES(com.redhat.devtools.intellij.tektoncd.Constants.FLAG_SKIP_OPTIONAL_WORKSPACES) PipelineRunList(io.fabric8.tekton.pipeline.v1beta1.PipelineRunList) ClusterTriggerBinding(io.fabric8.tekton.triggers.v1alpha1.ClusterTriggerBinding) Collectors(java.util.stream.Collectors) OPENSHIFT_VERSION(com.redhat.devtools.intellij.tektoncd.telemetry.TelemetryService.OPENSHIFT_VERSION) List(java.util.List) GenericKubernetesResourceList(io.fabric8.kubernetes.api.model.GenericKubernetesResourceList) Condition(io.fabric8.tekton.pipeline.v1alpha1.Condition) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Optional(java.util.Optional) KIND_CONFIGMAP(com.redhat.devtools.intellij.tektoncd.Constants.KIND_CONFIGMAP) KIND_PIPELINE(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINE) PipelineRun(io.fabric8.tekton.pipeline.v1beta1.PipelineRun) HashMap(java.util.HashMap) ClusterHelper(com.redhat.devtools.intellij.common.kubernetes.ClusterHelper) DebugTabPanelFactory(com.redhat.devtools.intellij.tektoncd.ui.toolwindow.debug.DebugTabPanelFactory) Serialization(io.fabric8.kubernetes.client.utils.Serialization) StatefulSetList(io.fabric8.kubernetes.api.model.apps.StatefulSetList) Project(com.intellij.openapi.project.Project) PROP_RESOURCE_KIND(com.redhat.devtools.intellij.tektoncd.telemetry.TelemetryService.PROP_RESOURCE_KIND) PodCondition(io.fabric8.kubernetes.api.model.PodCondition) PodStatus(io.fabric8.kubernetes.api.model.PodStatus) Pipeline(io.fabric8.tekton.pipeline.v1beta1.Pipeline) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Workspace(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace) ClusterTaskList(io.fabric8.tekton.pipeline.v1beta1.ClusterTaskList) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Consumer(java.util.function.Consumer) FLAG_INPUTRESOURCEPIPELINE(com.redhat.devtools.intellij.tektoncd.Constants.FLAG_INPUTRESOURCEPIPELINE) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) PipelineList(io.fabric8.tekton.pipeline.v1beta1.PipelineList) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) LogManager(org.apache.log4j.LogManager) TelemetryMessageBuilder(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder) Collections(java.util.Collections) Task(io.fabric8.tekton.pipeline.v1beta1.Task) ArrayList(java.util.ArrayList) RefUsage(com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage)

Example 2 with RefUsage

use of com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage in project intellij-tekton by redhat-developer.

the class FindTaskRefAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    TelemetryMessageBuilder.ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_MISC + "find task references").property(PROP_RESOURCE_KIND, KIND_TASK);
    ParentableNode element = getElement(selected);
    ExecHelper.submit(() -> {
        try {
            List<RefUsage> usages = tkncli.findTaskUsages(KIND_TASK, element.getName());
            UIHelper.executeInUI(() -> FindTaskRefPanelBuilder.instance().build(anActionEvent.getProject(), KIND_TASK, element.getName(), usages));
            telemetry.send();
        } catch (IOException e) {
            telemetry.error(anonymizeResource(null, element.getNamespace(), e.getMessage())).send();
            logger.warn(e.getLocalizedMessage(), e);
        }
    });
}
Also used : ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) RefUsage(com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage) TelemetryMessageBuilder(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder) IOException(java.io.IOException)

Example 3 with RefUsage

use of com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage in project intellij-tekton by redhat-developer.

the class FindClusterTaskRefAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected, Tkn tkncli) {
    ParentableNode element = getElement(selected);
    ExecHelper.submit(() -> {
        try {
            List<RefUsage> usages = tkncli.findTaskUsages(KIND_CLUSTERTASK, element.getName());
            UIHelper.executeInUI(() -> FindTaskRefPanelBuilder.instance().build(anActionEvent.getProject(), KIND_CLUSTERTASK, element.getName(), usages));
        } catch (IOException e) {
            logger.warn(e.getLocalizedMessage(), e);
        }
    });
}
Also used : ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) RefUsage(com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage) IOException(java.io.IOException)

Aggregations

RefUsage (com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage)3 IOException (java.io.IOException)3 ParentableNode (com.redhat.devtools.intellij.tektoncd.tree.ParentableNode)2 TelemetryMessageBuilder (com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings (com.google.common.base.Strings)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Project (com.intellij.openapi.project.Project)1 ClusterHelper (com.redhat.devtools.intellij.common.kubernetes.ClusterHelper)1 ClusterInfo (com.redhat.devtools.intellij.common.kubernetes.ClusterInfo)1 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)1 NetworkUtils (com.redhat.devtools.intellij.common.utils.NetworkUtils)1 Constants (com.redhat.devtools.intellij.tektoncd.Constants)1 FLAG_INPUTRESOURCEPIPELINE (com.redhat.devtools.intellij.tektoncd.Constants.FLAG_INPUTRESOURCEPIPELINE)1 FLAG_INPUTRESOURCETASK (com.redhat.devtools.intellij.tektoncd.Constants.FLAG_INPUTRESOURCETASK)1 FLAG_OUTPUTRESOURCE (com.redhat.devtools.intellij.tektoncd.Constants.FLAG_OUTPUTRESOURCE)1 FLAG_PARAMETER (com.redhat.devtools.intellij.tektoncd.Constants.FLAG_PARAMETER)1 FLAG_PREFIXNAME (com.redhat.devtools.intellij.tektoncd.Constants.FLAG_PREFIXNAME)1