Search in sources :

Example 1 with ResourceApi

use of com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi in project intellij-tekton by redhat-developer.

the class HubModel method retrieveAllResources.

private List<ResourceData> retrieveAllResources() {
    try {
        ResourceApi resApi = new ResourceApi();
        Resources resources = resApi.resourceList(500);
        return resources.getData();
    } catch (ApiException e) {
        logger.warn(e.getLocalizedMessage(), e);
    }
    return Collections.emptyList();
}
Also used : ResourceApi(com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi) Resources(com.redhat.devtools.intellij.tektoncd.hub.model.Resources) ApiException(com.redhat.devtools.intellij.tektoncd.hub.invoker.ApiException)

Example 2 with ResourceApi

use of com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi in project intellij-tekton by redhat-developer.

the class HubModel method getVersionsById.

public List<ResourceVersionData> getVersionsById(int id) {
    List<ResourceVersionData> versions = new ArrayList<>();
    Optional<HubItem> itemSelected = getAllHubItems().stream().filter(item -> item.getResource().getId() == id).findFirst();
    if (itemSelected.isPresent()) {
        versions = itemSelected.get().getResource().getVersions();
    }
    if (versions.isEmpty()) {
        ResourceApi res = new ResourceApi();
        try {
            versions = res.resourceVersionsByID(id).getData().getVersions();
            if (itemSelected.isPresent()) {
                itemSelected.get().getResource().setVersions(versions);
            }
        } catch (ApiException e) {
            logger.warn(e.getLocalizedMessage());
        }
    }
    return versions;
}
Also used : ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData) HUB_CATALOG_TAG(com.redhat.devtools.intellij.tektoncd.Constants.HUB_CATALOG_TAG) URL(java.net.URL) RecognizerFactory(com.redhat.devtools.alizer.api.RecognizerFactory) LoggerFactory(org.slf4j.LoggerFactory) Watcher(io.fabric8.kubernetes.client.Watcher) APP_K8S_IO_VERSION(com.redhat.devtools.intellij.tektoncd.Constants.APP_K8S_IO_VERSION) ConfigWatcher(com.redhat.devtools.intellij.common.utils.ConfigWatcher) YAMLBuilder(com.redhat.devtools.intellij.tektoncd.utils.YAMLBuilder) Language(com.redhat.devtools.alizer.api.Language) Constants(com.redhat.devtools.intellij.tektoncd.Constants) KIND_TASKS(com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASKS) ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Map(java.util.Map) ApiCallback(com.redhat.devtools.intellij.tektoncd.hub.invoker.ApiCallback) Config(io.fabric8.kubernetes.api.model.Config) DeployHelper(com.redhat.devtools.intellij.tektoncd.utils.DeployHelper) KIND_CLUSTERTASK(com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASK) Predicate(java.util.function.Predicate) Resources(com.redhat.devtools.intellij.tektoncd.hub.model.Resources) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) ClusterTask(io.fabric8.tekton.pipeline.v1beta1.ClusterTask) List(java.util.List) ClusterTasksNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode) Optional(java.util.Optional) ApiException(com.redhat.devtools.intellij.tektoncd.hub.invoker.ApiException) KIND_PIPELINE(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINE) YAMLHelper(com.redhat.devtools.intellij.common.utils.YAMLHelper) KIND_TASK(com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASK) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) KIND_PIPELINES(com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINES) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) TknCliFactory(com.redhat.devtools.intellij.tektoncd.tkn.TknCliFactory) WatcherException(io.fabric8.kubernetes.client.WatcherException) Project(com.intellij.openapi.project.Project) ResourceData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData) ConfigHelper(com.redhat.devtools.intellij.common.utils.ConfigHelper) Pipeline(io.fabric8.tekton.pipeline.v1beta1.Pipeline) Logger(org.slf4j.Logger) PipelinesNode(com.redhat.devtools.intellij.tektoncd.tree.PipelinesNode) IOException(java.io.IOException) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) InputStreamReader(java.io.InputStreamReader) ResourceApi(com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi) KIND_CLUSTERTASKS(com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASKS) Paths(java.nio.file.Paths) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) Task(io.fabric8.tekton.pipeline.v1beta1.Task) ResourceApi(com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi) ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData) ArrayList(java.util.ArrayList) ApiException(com.redhat.devtools.intellij.tektoncd.hub.invoker.ApiException)

Example 3 with ResourceApi

use of com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi in project intellij-tekton by redhat-developer.

the class HubModelTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    watch = mock(Watch.class);
    when(tkn.getNamespace()).thenReturn("namespace");
    when(tkn.watchPipelines(anyString(), any())).thenReturn(watch);
    when(tkn.watchTasks(anyString(), any())).thenReturn(watch);
    when(tkn.watchClusterTasks(any())).thenReturn(watch);
    pipelinesNode = mock(PipelinesNode.class);
    clusterTasksNode = mock(ClusterTasksNode.class);
    recognizerFactory = mock(RecognizerFactory.class);
    languageRecognizer = mock(LanguageRecognizer.class);
    when(recognizerFactory.createLanguageRecognizer()).thenReturn(languageRecognizer);
    languageJAVA = new Language("java", Collections.emptyList(), 1.0, true);
    languageUnknown = new Language("Unknown", Collections.emptyList(), 1.0, false);
    resourceApi = mock(ResourceApi.class);
    resourceDataJAVA = mock(ResourceData.class);
    resourceVersionDataJAVA = mock(ResourceVersionData.class);
    when(resourceDataJAVA.getName()).thenReturn("java");
    when(resourceDataJAVA.getKind()).thenReturn(KIND_TASK);
    when(resourceDataJAVA.getLatestVersion()).thenReturn(resourceVersionDataJAVA);
    when(resourceVersionDataJAVA.getVersion()).thenReturn("v1");
    resourceDataGO = mock(ResourceData.class);
    resourceVersionDataGO = mock(ResourceVersionData.class);
    when(resourceDataGO.getName()).thenReturn("go");
    when(resourceDataGO.getKind()).thenReturn(KIND_TASK);
    when(resourceDataGO.getLatestVersion()).thenReturn(resourceVersionDataGO);
    when(resourceVersionDataGO.getVersion()).thenReturn("v1");
    resourceDataNET = mock(ResourceData.class);
    resourceVersionDataNET = mock(ResourceVersionData.class);
    when(resourceDataNET.getName()).thenReturn("net");
    when(resourceDataNET.getKind()).thenReturn(KIND_PIPELINE);
    when(resourceDataNET.getLatestVersion()).thenReturn(resourceVersionDataNET);
    when(resourceVersionDataNET.getVersion()).thenReturn("v1");
    when(project.getBasePath()).thenReturn(".");
    resources = new Resources();
    resources.addDataItem(resourceDataJAVA);
    resources.addDataItem(resourceDataGO);
}
Also used : PipelinesNode(com.redhat.devtools.intellij.tektoncd.tree.PipelinesNode) ResourceApi(com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi) ResourceData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData) LanguageRecognizer(com.redhat.devtools.alizer.api.LanguageRecognizer) Language(com.redhat.devtools.alizer.api.Language) ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData) Watch(io.fabric8.kubernetes.client.Watch) RecognizerFactory(com.redhat.devtools.alizer.api.RecognizerFactory) Resources(com.redhat.devtools.intellij.tektoncd.hub.model.Resources) ClusterTasksNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode) Before(org.junit.Before)

Example 4 with ResourceApi

use of com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi in project intellij-tekton by redhat-developer.

the class HubModelTest method GetAllTaskHubItems_RemoteHubHasNoTaskResources_EmptyList.

@Test
public void GetAllTaskHubItems_RemoteHubHasNoTaskResources_EmptyList() throws IOException {
    Resources resources = new Resources();
    resources.addDataItem(resourceDataNET);
    try (MockedConstruction<ResourceApi> resourceApiMockedConstruction = mockConstruction(ResourceApi.class, (mock, context) -> when(mock.resourceList(anyInt())).thenReturn(resources))) {
        try (MockedConstruction<RecognizerFactory> languageRecognizerBuilderMockedConstruction = mockConstruction(RecognizerFactory.class, (mock, context) -> when(mock.createLanguageRecognizer()).thenReturn(languageRecognizer))) {
            List<Language> languages = Arrays.asList(languageJAVA);
            when(languageRecognizer.analyze(anyString())).thenReturn(languages);
            HubModel model = new HubModel(project, tkn, null);
            List<HubItem> taskItems = model.getAllTaskHubItems();
            assertEquals(0, taskItems.size());
        }
    }
}
Also used : ResourceApi(com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi) Language(com.redhat.devtools.alizer.api.Language) Resources(com.redhat.devtools.intellij.tektoncd.hub.model.Resources) RecognizerFactory(com.redhat.devtools.alizer.api.RecognizerFactory) Test(org.junit.Test) BaseTest(com.redhat.devtools.intellij.tektoncd.BaseTest)

Aggregations

ResourceApi (com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi)4 Resources (com.redhat.devtools.intellij.tektoncd.hub.model.Resources)4 Language (com.redhat.devtools.alizer.api.Language)3 RecognizerFactory (com.redhat.devtools.alizer.api.RecognizerFactory)3 ApiException (com.redhat.devtools.intellij.tektoncd.hub.invoker.ApiException)2 ResourceData (com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData)2 ResourceVersionData (com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData)2 ClusterTasksNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode)2 PipelinesNode (com.redhat.devtools.intellij.tektoncd.tree.PipelinesNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Project (com.intellij.openapi.project.Project)1 LanguageRecognizer (com.redhat.devtools.alizer.api.LanguageRecognizer)1 ConfigHelper (com.redhat.devtools.intellij.common.utils.ConfigHelper)1 ConfigWatcher (com.redhat.devtools.intellij.common.utils.ConfigWatcher)1 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)1 YAMLHelper (com.redhat.devtools.intellij.common.utils.YAMLHelper)1 BaseTest (com.redhat.devtools.intellij.tektoncd.BaseTest)1 Constants (com.redhat.devtools.intellij.tektoncd.Constants)1 APP_K8S_IO_VERSION (com.redhat.devtools.intellij.tektoncd.Constants.APP_K8S_IO_VERSION)1 HUB_CATALOG_TAG (com.redhat.devtools.intellij.tektoncd.Constants.HUB_CATALOG_TAG)1