Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to specify reference or registry url for chePlugin/cheEditor type components #13297

Merged
merged 37 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
77e53d7
Add registryUrl into editor/plugin components
mshaposhnik May 3, 2019
d238e59
Put reference into PluginFQN
mshaposhnik May 8, 2019
10b5e1b
Fixes for the components with references
mshaposhnik May 8, 2019
7fb6445
Fix typo
mshaposhnik May 8, 2019
337e76c
Fix in FQN parser
mshaposhnik May 10, 2019
bf2e2b2
FQN paresr fixes
mshaposhnik May 11, 2019
7adb88f
fixup! FQN paresr fixes
mshaposhnik May 13, 2019
9608e3d
Merge branch 'master' into registryUrl
mshaposhnik May 20, 2019
e1b5380
Prefetch plugins with references
mshaposhnik May 23, 2019
5fefb23
Merge with master
mshaposhnik May 24, 2019
b82ef32
More fixups
mshaposhnik May 24, 2019
849787a
Make default plugin resolving respect referenced pluins
mshaposhnik May 24, 2019
16b3780
Merge branch 'master' into registryUrl
mshaposhnik May 28, 2019
a793855
User FileContentProvider
mshaposhnik May 29, 2019
2adeba4
Move some classes to WS api
mshaposhnik May 29, 2019
b6b709d
Merge branch 'master' into registryUrl
mshaposhnik May 30, 2019
c28e5f5
Use FileContentProvider in tests
mshaposhnik May 30, 2019
e36e710
Use FileContentProvider in tests
mshaposhnik May 30, 2019
4a3a2fb
Merge witj latest master
mshaposhnik May 31, 2019
0111a48
Use per-request file content provider
mshaposhnik Jun 3, 2019
04dc344
Fixup test
mshaposhnik Jun 3, 2019
1997b6a
Fixup test
mshaposhnik Jun 3, 2019
a71d436
Code feractoring
mshaposhnik Jun 3, 2019
8d2f3dc
Code feractoring
mshaposhnik Jun 3, 2019
666e328
Code feractoring
mshaposhnik Jun 3, 2019
245428d
Merge branch 'master' into registryUrl
mshaposhnik Jun 5, 2019
d1e011c
Add doc example about references and registry url-s
mshaposhnik Jun 5, 2019
1ba01b5
Merge branch 'master' into registryUrl
mshaposhnik Jun 5, 2019
c232369
Change schema version
mshaposhnik Jun 6, 2019
34cac61
FIx review comments
mshaposhnik Jun 6, 2019
110f77b
Fix typos & comments
mshaposhnik Jun 6, 2019
2c179f9
Review fixes
mshaposhnik Jun 6, 2019
79fbde3
refactor FQN parsing
mshaposhnik Jun 6, 2019
0c13775
Code fix
mshaposhnik Jun 7, 2019
669f3ad
Javadoc fixup
mshaposhnik Jun 10, 2019
d736c7d
Review fixups & broker version
mshaposhnik Jun 10, 2019
7541cb1
Fixup regex
mshaposhnik Jun 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ public interface Component {
String getId();

/**
* Returns absolute or devfile-relative location of Kubernetes list yaml file. It is mandatory and
* applicable only for 'kubernetes' and 'openshift' components types.
* For 'kubernetes' and 'openshift' components types, returns absolute or devfile-relative
* location of Kubernetes list yaml file. It is mandatory for those types.
mshaposhnik marked this conversation as resolved.
Show resolved Hide resolved
*
* <p>For 'cheEditor' and 'chePlugin' components types, returns absolute location of plugin
* descriptor (typically, named meta.yaml). For those types this field is optional.
*/
String getReference();

/**
* Returns address of custom plugin registry. It is optional and applicable only for 'cheEditor'
* and 'chePlugin' components types.
*/
String getRegistryUrl();

/**
* Returns inlined content of a file specified in field 'reference'. It is optional and applicable
* only for 'kubernetes' and 'openshift' components types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
*/
package org.eclipse.che.api.devfile.server.convert;

import static com.google.common.base.Strings.isNullOrEmpty;
import static org.eclipse.che.api.devfile.server.Constants.EDITOR_COMPONENT_TYPE;
import static org.eclipse.che.api.devfile.server.Constants.EDITOR_FREE_DEVFILE_ATTRIBUTE;
import static org.eclipse.che.api.devfile.server.Constants.PLUGIN_COMPONENT_TYPE;

import com.google.common.base.Strings;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -48,7 +48,7 @@ public DefaultEditorProvisioner(
@Named("che.workspace.devfile.default_editor.plugins") String[] defaultPluginsRefs,
PluginFQNParser fqnParser)
throws DevfileException {
this.defaultEditorRef = Strings.isNullOrEmpty(defaultEditorRef) ? null : defaultEditorRef;
this.defaultEditorRef = isNullOrEmpty(defaultEditorRef) ? null : defaultEditorRef;
this.fqnParser = fqnParser;
this.defaultEditor =
this.defaultEditorRef == null ? null : getPluginPublisherAndName(this.defaultEditorRef);
Expand Down Expand Up @@ -86,7 +86,9 @@ public void apply(DevfileImpl devfile) throws DevfileException {
isDefaultEditorUsed = true;
} else {
Component editor = editorOpt.get();
isDefaultEditorUsed = defaultEditor.equals(getPluginPublisherAndName(editor.getId()));
isDefaultEditorUsed =
!isNullOrEmpty(editor.getId())
mshaposhnik marked this conversation as resolved.
Show resolved Hide resolved
&& defaultEditor.equals(getPluginPublisherAndName(editor.getId()));
}

if (isDefaultEditorUsed) {
Expand All @@ -98,7 +100,7 @@ private void provisionDefaultPlugins(List<ComponentImpl> components) throws Devf
Map<String, String> missingPluginsIdToRef = new HashMap<>(defaultPluginsToRefs);

for (ComponentImpl t : components) {
if (PLUGIN_COMPONENT_TYPE.equals(t.getType())) {
if (PLUGIN_COMPONENT_TYPE.equals(t.getType()) && !isNullOrEmpty(t.getId())) {
mshaposhnik marked this conversation as resolved.
Show resolved Hide resolved
missingPluginsIdToRef.remove(getPluginPublisherAndName(t.getId()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.che.api.devfile.server.convert.component.editor;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.lang.String.format;
import static org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE;
import static org.eclipse.che.api.devfile.server.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE;
Expand Down Expand Up @@ -68,35 +69,42 @@ public void apply(

String editorComponentAlias = editorComponent.getAlias();
String editorId = editorComponent.getId();
String registryUrl = editorComponent.getRegistryUrl();
String reference = editorComponent.getReference();
String memoryLimit = editorComponent.getMemoryLimit();

workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, editorId);

if (editorComponentAlias != null) {
workspaceConfig
.getAttributes()
.put(EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE, editorComponentAlias);
}

final ExtendedPluginFQN fqn;
try {
fqn = fqnParser.parsePluginFQN(editorId);
} catch (InfrastructureException e) {
throw new DevfileException(e.getMessage(), e);
}
if (memoryLimit != null) {
if (!isNullOrEmpty(reference)) {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, reference);
} else {
String compositeId = registryUrl != null ? registryUrl + "#" + editorId : editorId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make this a method of the PluginFQNParser or maybe rather PluginFQN? Could be combined with the logic of parsePluginFQN below and result in a simpler flow here.

workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, compositeId);
final ExtendedPluginFQN fqn;
try {
fqn = fqnParser.parsePluginFQN(compositeId);
} catch (InfrastructureException e) {
throw new DevfileException(e.getMessage(), e);
}
if (memoryLimit != null) {
workspaceConfig
.getAttributes()
.put(
format(SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE, fqn.getPublisherAndName()), memoryLimit);
}
workspaceConfig
.getAttributes()
.put(format(SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE, fqn.getPublisherAndName()), memoryLimit);
.getCommands()
.stream()
.filter(
c ->
c.getAttributes()
.get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE)
.equals(editorComponentAlias))
.forEach(c -> c.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId()));
}
workspaceConfig
.getCommands()
.stream()
.filter(
c ->
c.getAttributes()
.get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE)
.equals(editorComponentAlias))
.forEach(c -> c.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,48 +71,59 @@ public void apply(

String workspacePluginsAttribute =
workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE);
workspaceConfig
.getAttributes()
.put(
WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE,
append(workspacePluginsAttribute, pluginComponent.getId()));

String pluginsAliases =
workspaceConfig.getAttributes().get(PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE);
if (pluginComponent.getAlias() != null) {
String reference = pluginComponent.getReference();
String pluginId = pluginComponent.getId();
String registryUrl = pluginComponent.getRegistryUrl();
String compositeId = registryUrl != null ? registryUrl + "#" + pluginId : pluginId;

if (!isNullOrEmpty(reference)) {
workspaceConfig
.getAttributes()
.put(
PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE,
append(pluginsAliases, pluginComponent.getId() + "=" + pluginComponent.getAlias()));
}

ExtendedPluginFQN fqn;
try {
fqn = fqnParser.parsePluginFQN(pluginComponent.getId());
} catch (InfrastructureException e) {
throw new DevfileException(e.getMessage(), e);
}
String memoryLimit = pluginComponent.getMemoryLimit();
if (memoryLimit != null) {
.put(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE, append(workspacePluginsAttribute, reference));
} else {
workspaceConfig
.getAttributes()
.put(format(SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE, fqn.getPublisherAndName()), memoryLimit);
}

for (CommandImpl command : workspaceConfig.getCommands()) {
String commandComponent = command.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE);
.put(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE, append(workspacePluginsAttribute, compositeId));

if (commandComponent == null) {
// command does not have component information
continue;
ExtendedPluginFQN fqn;
try {
fqn = fqnParser.parsePluginFQN(compositeId);
} catch (InfrastructureException e) {
throw new DevfileException(e.getMessage(), e);
}
String memoryLimit = pluginComponent.getMemoryLimit();
if (memoryLimit != null) {
workspaceConfig
.getAttributes()
.put(
format(SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE, fqn.getPublisherAndName()), memoryLimit);
}

for (CommandImpl command : workspaceConfig.getCommands()) {
String commandComponent = command.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE);

if (commandComponent == null) {
// command does not have component information
continue;
}

if (!commandComponent.equals(pluginComponent.getAlias())) {
continue;
if (!commandComponent.equals(pluginComponent.getAlias())) {
continue;
}

command.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId());
}
}

command.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId());
String pluginsAliases =
workspaceConfig.getAttributes().get(PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE);
if (pluginComponent.getAlias() != null) {
workspaceConfig
.getAttributes()
.put(
PLUGINS_COMPONENTS_ALIASES_WORKSPACE_ATTRIBUTE,
append(pluginsAliases, compositeId + "=" + pluginComponent.getAlias()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,19 @@
}
},
"then": {
"required": [
"id"
"oneOf": [
mshaposhnik marked this conversation as resolved.
Show resolved Hide resolved
{
"required": [
"id"
],
"additionalProperties": true
},
{
"required": [
"reference"
],
"additionalProperties": true
}
],
"additionalProperties": false,
"properties": {
Expand All @@ -174,8 +185,21 @@
"description": "Describes the component id. It has the following format: [{REGISTRY_URL}/]{plugin/editor PUBLISHER}/{plugin/editor NAME}/{plugin/editor VERSION}, where {REGISTRY_URL}/ is an optional part.",
"pattern": "^((https?://)[a-zA-Z0-9_\\-./]+/)?[a-z0-9_\\-.]+/[a-z0-9_\\-.]+/[a-z0-9_\\-.]+$",
"examples": [
"eclipse/maven-jdk8/1.0.0",
"https://che-plugin-registry.openshift.io/eclipse/maven-jdk8/1.0.0"
"eclipse/maven-jdk8/1.0.0"
]
},
"reference": {
"description": "Describes raw location of plugin yaml file.",
"type": "string",
"examples": [
"https://pastebin.com/raw/kYprWiNB"
]
},
"registryUrl": {
"description": "Describes URL of custom plugin registry.",
"type": "string",
"examples": [
"https://che-plugin-registry.openshift.io/"
]
},
"memoryLimit": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void shouldProvisionDefaultPluginsIfTheyAreNotSpecifiedAndDefaultEditorIs
ComponentImpl defaultEditorWithDifferentVersion =
new ComponentImpl(
EDITOR_COMPONENT_TYPE,
"https://my-custom-registry/" + EDITOR_PUBLISHER + "/" + EDITOR_NAME + "/latest");
"https://my-custom-registry#" + EDITOR_PUBLISHER + "/" + EDITOR_NAME + "/latest");
devfile.getComponents().add(defaultEditorWithDifferentVersion);

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void shouldNoNothingIfWorkspaceDoesNotHaveEnvironmentsWithKubernetesOpenS
assertEquals(dockerimageComponent.getEndpoints().size(), 1);
EndpointImpl endpoint = dockerimageComponent.getEndpoints().get(0);
assertEquals(endpoint.getName(), "server");
assertEquals(endpoint.getPort(), new Integer(8080));
assertEquals(endpoint.getPort(), Integer.valueOf(8080));
assertEquals(endpoint.getAttributes().size(), 3);
assertEquals(endpoint.getAttributes().get("protocol"), "http");
assertEquals(endpoint.getAttributes().get("path"), "/api");
Expand Down Expand Up @@ -224,7 +224,7 @@ public void shouldNoNothingIfWorkspaceDoesNotHaveEnvironmentsWithKubernetesOpenS
assertEquals(dockerimageComponent.getEndpoints().size(), 1);
EndpointImpl endpoint = dockerimageComponent.getEndpoints().get(0);
assertEquals(endpoint.getName(), "server");
assertEquals(endpoint.getPort(), new Integer(8080));
assertEquals(endpoint.getPort(), Integer.valueOf(8080));
assertTrue(endpoint.getAttributes().isEmpty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public void shouldProvisionServiceForDiscoverableServer() throws Exception {
List<ServicePort> ports = service.getSpec().getPorts();
assertEquals(ports.size(), 1);
ServicePort port = ports.get(0);
assertEquals(port.getPort(), new Integer(4923));
assertEquals(port.getPort(), Integer.valueOf(4923));
assertEquals(port.getTargetPort(), new IntOrString(4923));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,64 @@ public void shouldProvisionWorkspaceEditorAttributeDuringCheEditorComponentApply
"12345M");
}

@Test
public void
shouldProvisionWorkspaceEditorAttributeWithCustomRegistryDuringCheEditorComponentApplying()
throws DevfileException {
String editorId = "eclipse/super-editor/0.0.1";
String registryUrl = "https://myregistry.com/infolder/";
// given
WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl();
ComponentImpl editorComponent = new ComponentImpl();
editorComponent.setType(EDITOR_COMPONENT_TYPE);
editorComponent.setAlias("editor1");
editorComponent.setId(editorId);
editorComponent.setRegistryUrl(registryUrl);
editorComponent.setMemoryLimit("12345M");

// when
editorComponentApplier.apply(workspaceConfig, editorComponent, null);

// then
assertEquals(
workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE),
registryUrl + "#" + editorId);
assertEquals(
workspaceConfig.getAttributes().get(EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE), "editor1");
assertEquals(
workspaceConfig
.getAttributes()
.get(format(SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE, "eclipse/super-editor")),
"12345M");
}

@Test
public void shouldProvisionWorkspaceEditorAttributeWithReferenceDuringCheEditorComponentApplying()
throws DevfileException {
String reference = "https://myregistry.com/infolder/meta.yaml";
// given
WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl();
ComponentImpl editorComponent = new ComponentImpl();
editorComponent.setType(EDITOR_COMPONENT_TYPE);
editorComponent.setAlias("editor1");
editorComponent.setReference(reference);

// when
editorComponentApplier.apply(workspaceConfig, editorComponent, null);

// then
assertEquals(
workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE), reference);
assertEquals(
workspaceConfig.getAttributes().get(EDITOR_COMPONENT_ALIAS_WORKSPACE_ATTRIBUTE), "editor1");
// FIXME:
// assertEquals(
// workspaceConfig
// .getAttributes()
// .get(format(SIDECAR_MEMORY_LIMIT_ATTR_TEMPLATE, "eclipse/super-editor")),
// "12345M");
}

@Test
public void shouldProvisionPluginCommandAttributesDuringCheEditorComponentApplying()
throws DevfileException {
Expand Down Expand Up @@ -94,7 +152,7 @@ public void shouldProvisionPluginCommandAttributeWhenIdIsURLToCustomPluginRegist
// given
ComponentImpl superPluginComponent = new ComponentImpl();
superPluginComponent.setAlias("editor");
superPluginComponent.setId("https://custom-plugin.registry/plugins/eclipse/super-editor/0.0.1");
superPluginComponent.setId("https://custom-plugin.registry/plugins#eclipse/super-editor/0.0.1");
superPluginComponent.setType(EDITOR_COMPONENT_TYPE);

WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl();
Expand Down
Loading