Search in sources :

Example 1 with URLFileContentProvider

use of org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider in project devspaces-images by redhat-developer.

the class DefaultFactoryParameterResolver method createFactory.

/**
 * Creates factory based on provided parameters. Presumes url parameter as direct URL to a devfile
 * content.
 *
 * @param factoryParameters map containing factory data parameters provided through URL
 */
@Override
public FactoryMetaDto createFactory(@NotNull final Map<String, String> factoryParameters) throws ApiException {
    // This should never be null, because our contract in #accept prohibits that
    String devfileLocation = factoryParameters.get(URL_PARAMETER_NAME);
    URI devfileURI;
    try {
        devfileURI = new URL(devfileLocation).toURI();
    } catch (MalformedURLException | URISyntaxException e) {
        throw new BadRequestException(format("Unable to process provided factory URL. Please check its validity and try again. Parser message: %s", e.getMessage()));
    }
    return urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(devfileLocation), new URLFileContentProvider(devfileURI, urlFetcher), extractOverrideParams(factoryParameters)).orElse(null);
}
Also used : MalformedURLException(java.net.MalformedURLException) BadRequestException(org.eclipse.che.api.core.BadRequestException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) DefaultFactoryUrl(org.eclipse.che.api.factory.server.urlfactory.DefaultFactoryUrl) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider)

Example 2 with URLFileContentProvider

use of org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider in project devspaces-images by redhat-developer.

the class KubernetesComponentToWorkspaceApplierTest method shouldUseReferenceContentAsRecipeIfPresent.

@Test
public void shouldUseReferenceContentAsRecipeIfPresent() throws Exception {
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setReferenceContent(yamlRecipeContent);
    component.setAlias(COMPONENT_NAME);
    applier.apply(workspaceConfig, component, new URLFileContentProvider(null, null));
    KubernetesList list = toK8SList(yamlRecipeContent);
    replaceImagePullPolicy(list, "Always");
    verify(k8sEnvProvisioner).provision(eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), eq(list.getItems()), anyMap());
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider) Test(org.testng.annotations.Test)

Example 3 with URLFileContentProvider

use of org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider in project che-server by eclipse-che.

the class DefaultFactoryParameterResolver method createFactory.

/**
 * Creates factory based on provided parameters. Presumes url parameter as direct URL to a devfile
 * content.
 *
 * @param factoryParameters map containing factory data parameters provided through URL
 */
@Override
public FactoryMetaDto createFactory(@NotNull final Map<String, String> factoryParameters) throws ApiException {
    // This should never be null, because our contract in #accept prohibits that
    String devfileLocation = factoryParameters.get(URL_PARAMETER_NAME);
    URI devfileURI;
    try {
        devfileURI = new URL(devfileLocation).toURI();
    } catch (MalformedURLException | URISyntaxException e) {
        throw new BadRequestException(format("Unable to process provided factory URL. Please check its validity and try again. Parser message: %s", e.getMessage()));
    }
    return urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(devfileLocation), new URLFileContentProvider(devfileURI, urlFetcher), extractOverrideParams(factoryParameters)).orElse(null);
}
Also used : MalformedURLException(java.net.MalformedURLException) BadRequestException(org.eclipse.che.api.core.BadRequestException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) DefaultFactoryUrl(org.eclipse.che.api.factory.server.urlfactory.DefaultFactoryUrl) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider)

Example 4 with URLFileContentProvider

use of org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider in project che-server by eclipse-che.

the class KubernetesComponentToWorkspaceApplierTest method shouldUseReferenceContentAsRecipeIfPresent.

@Test
public void shouldUseReferenceContentAsRecipeIfPresent() throws Exception {
    String yamlRecipeContent = getResource("devfile/petclinic.yaml");
    doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
    ComponentImpl component = new ComponentImpl();
    component.setType(KUBERNETES_COMPONENT_TYPE);
    component.setReference(REFERENCE_FILENAME);
    component.setReferenceContent(yamlRecipeContent);
    component.setAlias(COMPONENT_NAME);
    applier.apply(workspaceConfig, component, new URLFileContentProvider(null, null));
    KubernetesList list = toK8SList(yamlRecipeContent);
    replaceImagePullPolicy(list, "Always");
    verify(k8sEnvProvisioner).provision(eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), eq(list.getItems()), anyMap());
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) URLFileContentProvider(org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider) Test(org.testng.annotations.Test)

Aggregations

URLFileContentProvider (org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider)4 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)2 MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2 DefaultFactoryUrl (org.eclipse.che.api.factory.server.urlfactory.DefaultFactoryUrl)2 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Test (org.testng.annotations.Test)2