Skip to content

Commit

Permalink
Make plugin brokering process use fully qualified names instead of me…
Browse files Browse the repository at this point in the history
…tas.

Instead of downloading metas from plugin registry and passing them to
plugin broker, provide plugin broker with serialized plugin fully
qualified names and allow broker to download necessary metas.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
  • Loading branch information
amisevsk committed Apr 15, 2019
1 parent 046552f commit 0516bd2
Show file tree
Hide file tree
Showing 16 changed files with 485 additions and 555 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ che.singleport.wildcard_domain.ipless=false

# Docker image of Che plugin broker app that resolves workspace tooling configuration and copies
# plugins dependencies to a workspace
che.workspace.plugin_broker.init.image=eclipse/che-init-plugin-broker:v0.14.0
che.workspace.plugin_broker.unified.image=eclipse/che-unified-plugin-broker:v0.15.1
che.workspace.plugin_broker.init.image=eclipse/che-init-plugin-broker:v0.15.3
che.workspace.plugin_broker.unified.image=eclipse/che-unified-plugin-broker:v0.15.3

# Docker image of Che plugin broker app that resolves workspace tooling configuration and copies
# plugins dependencies to a workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment;
import org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginMeta;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN;
import org.eclipse.che.workspace.infrastructure.kubernetes.Names;
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment;
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData;
Expand Down Expand Up @@ -52,11 +52,10 @@ public KubernetesBrokerInitContainerApplier(
* broker's configmap, machines, and volumes added in addition to the init container
*/
public void apply(
E workspaceEnvironment, RuntimeIdentity runtimeID, Collection<PluginMeta> pluginsMeta)
E workspaceEnvironment, RuntimeIdentity runtimeID, Collection<PluginFQN> pluginFQNs)
throws InfrastructureException {

E brokerEnvironment =
brokerEnvironmentFactory.create(pluginsMeta, runtimeID, new BrokersResult());
E brokerEnvironment = brokerEnvironmentFactory.create(pluginFQNs, runtimeID);

Map<String, PodData> workspacePods = workspaceEnvironment.getPodsData();
if (workspacePods.size() != 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.che.api.core.notification.EventService;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginMeta;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN;
import org.eclipse.che.commons.annotation.Traced;
import org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesEnvironmentProvisioner;
import org.eclipse.che.workspace.infrastructure.kubernetes.StartSynchronizer;
Expand Down Expand Up @@ -95,15 +95,15 @@ public PluginBrokerManager(
public List<ChePlugin> getTooling(
RuntimeIdentity runtimeID,
StartSynchronizer startSynchronizer,
Collection<PluginMeta> pluginsMeta,
Collection<PluginFQN> pluginFQNs,
boolean isEphemeral)
throws InfrastructureException {

String workspaceId = runtimeID.getWorkspaceId();
KubernetesNamespace kubernetesNamespace = factory.create(workspaceId);
BrokersResult brokersResult = new BrokersResult();

E brokerEnvironment = brokerEnvironmentFactory.create(pluginsMeta, runtimeID, brokersResult);
E brokerEnvironment = brokerEnvironmentFactory.create(pluginFQNs, runtimeID);
if (isEphemeral) {
EphemeralWorkspaceUtility.makeEphemeral(brokerEnvironment.getAttributes());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.wsplugins.ChePluginsApplier;
import org.eclipse.che.api.workspace.server.wsplugins.PluginMetaRetriever;
import org.eclipse.che.api.workspace.server.wsplugins.PluginFQNParser;
import org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginMeta;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN;
import org.eclipse.che.commons.annotation.Traced;
import org.eclipse.che.workspace.infrastructure.kubernetes.StartSynchronizer;
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment;
Expand All @@ -42,18 +42,18 @@ public class SidecarToolingProvisioner<E extends KubernetesEnvironment> {

private final Map<String, ChePluginsApplier> workspaceNextAppliers;
private final KubernetesBrokerInitContainerApplier<E> brokerApplier;
private final PluginMetaRetriever pluginMetaRetriever;
private final PluginFQNParser pluginFQNParser;
private final PluginBrokerManager<E> pluginBrokerManager;

@Inject
public SidecarToolingProvisioner(
Map<String, ChePluginsApplier> workspaceNextAppliers,
KubernetesBrokerInitContainerApplier<E> brokerApplier,
PluginMetaRetriever pluginMetaRetriever,
PluginFQNParser pluginFQNParser,
PluginBrokerManager<E> pluginBrokerManager) {
this.workspaceNextAppliers = ImmutableMap.copyOf(workspaceNextAppliers);
this.brokerApplier = brokerApplier;
this.pluginMetaRetriever = pluginMetaRetriever;
this.pluginFQNParser = pluginFQNParser;
this.pluginBrokerManager = pluginBrokerManager;
}

Expand All @@ -62,8 +62,8 @@ public SidecarToolingProvisioner(
public void provision(RuntimeIdentity id, StartSynchronizer startSynchronizer, E environment)
throws InfrastructureException {

Collection<PluginMeta> pluginsMeta = pluginMetaRetriever.get(environment.getAttributes());
if (pluginsMeta.isEmpty()) {
Collection<PluginFQN> pluginFQNs = pluginFQNParser.parsePlugins(environment.getAttributes());
if (pluginFQNs.isEmpty()) {
return;
}
LOG.debug("Started sidecar tooling provisioning workspace '{}'", id.getWorkspaceId());
Expand All @@ -76,11 +76,11 @@ public void provision(RuntimeIdentity id, StartSynchronizer startSynchronizer, E

boolean isEphemeral = EphemeralWorkspaceUtility.isEphemeral(environment.getAttributes());
List<ChePlugin> chePlugins =
pluginBrokerManager.getTooling(id, startSynchronizer, pluginsMeta, isEphemeral);
pluginBrokerManager.getTooling(id, startSynchronizer, pluginFQNs, isEphemeral);

pluginsApplier.apply(id, environment, chePlugins);
if (isEphemeral) {
brokerApplier.apply(environment, id, pluginsMeta);
brokerApplier.apply(environment, id, pluginFQNs);
}
LOG.debug("Finished sidecar tooling provisioning workspace '{}'", id.getWorkspaceId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Strings;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
import io.fabric8.kubernetes.api.model.Container;
Expand All @@ -34,16 +36,14 @@
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.model.impl.VolumeImpl;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException;
import org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig;
import org.eclipse.che.api.workspace.server.spi.provision.env.AgentAuthEnableEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.MachineTokenEnvVarProvider;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginMeta;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.commons.lang.Pair;
Expand All @@ -65,10 +65,10 @@
@Beta
public abstract class BrokerEnvironmentFactory<E extends KubernetesEnvironment> {

private static final String CONFIG_MAP_NAME_SUFFIX = "broker-config-map";
@VisibleForTesting static final String CONFIG_MAP_NAME_SUFFIX = "broker-config-map";
@VisibleForTesting static final String CONFIG_FILE = "config.json";
private static final String BROKER_VOLUME = "broker-config-volume";
private static final String CONF_FOLDER = "/broker-config";
private static final String CONFIG_FILE = "config.json";
private static final String PLUGINS_VOLUME_NAME = "plugins";
private static final String BROKERS_POD_NAME = "che-plugin-broker";

Expand All @@ -79,34 +79,35 @@ public abstract class BrokerEnvironmentFactory<E extends KubernetesEnvironment>
private final MachineTokenEnvVarProvider machineTokenEnvVarProvider;
private final String unifiedBrokerImage;
private final String initBrokerImage;
private final String pluginRegistryUrl;

@Inject
public BrokerEnvironmentFactory(
@Named("che.websocket.endpoint") String cheWebsocketEndpoint,
@Named("che.workspace.plugin_broker.pull_policy") String brokerPullPolicy,
String cheWebsocketEndpoint,
String brokerPullPolicy,
AgentAuthEnableEnvVarProvider authEnableEnvVarProvider,
MachineTokenEnvVarProvider machineTokenEnvVarProvider,
@Named("che.workspace.plugin_broker.unified.image") String unifiedBrokerImage,
@Named("che.workspace.plugin_broker.init.image") String initBrokerImage) {
String unifiedBrokerImage,
String initBrokerImage,
String pluginRegistryUrl) {
this.cheWebsocketEndpoint = cheWebsocketEndpoint;
this.brokerPullPolicy = brokerPullPolicy;
this.authEnableEnvVarProvider = authEnableEnvVarProvider;
this.machineTokenEnvVarProvider = machineTokenEnvVarProvider;
this.unifiedBrokerImage = unifiedBrokerImage;
this.initBrokerImage = initBrokerImage;
this.pluginRegistryUrl = pluginRegistryUrl;
}

/**
* Creates {@link KubernetesEnvironment} with everything needed to deploy Plugin broker.
*
* @param pluginsMeta meta info of plugins that needs to be resolved by the broker
* @param pluginFQN fully qualified names of plugins that needs to be resolved by the broker
* @param runtimeID ID of the runtime the broker would be started
* @param brokersResult needs to be called with {@link BrokersResult#oneMoreBroker()} for each
* broker to allow proper waiting of execution of all the brokers
* @return kubernetes environment (or its extension) with the Plugin broker objects
*/
public E create(
Collection<PluginMeta> pluginsMeta, RuntimeIdentity runtimeID, BrokersResult brokersResult)
public E create(Collection<PluginFQN> pluginFQNs, RuntimeIdentity runtimeID)
throws InfrastructureException {

BrokersConfigs brokersConfigs = new BrokersConfigs();
Expand All @@ -122,7 +123,7 @@ public E create(
.collect(Collectors.toList());

BrokerConfig brokerConfig =
createBrokerConfig(runtimeID, pluginsMeta, envVars, unifiedBrokerImage, pod);
createBrokerConfig(runtimeID, pluginFQNs, envVars, unifiedBrokerImage, pod);
brokersConfigs.machines.put(brokerConfig.machineName, brokerConfig.machineConfig);
brokersConfigs.configMaps.put(brokerConfig.configMapName, brokerConfig.configMap);
spec.getContainers().add(brokerConfig.container);
Expand Down Expand Up @@ -168,7 +169,10 @@ private Container newContainer(
"%s:%s:%s",
runtimeId.getWorkspaceId(),
MoreObjects.firstNonNull(runtimeId.getEnvName(), ""),
runtimeId.getOwnerId()))
runtimeId.getOwnerId()),
"--download-metas",
"--registry-address",
Strings.nullToEmpty(pluginRegistryUrl))
.withImagePullPolicy(brokerPullPolicy)
.withEnv(envVars);
if (brokerVolumeName != null) {
Expand All @@ -192,14 +196,14 @@ private Pod newPod() {
.build();
}

private ConfigMap newConfigMap(String configMapName, Collection<PluginMeta> pluginsMetas)
private ConfigMap newConfigMap(String configMapName, Collection<PluginFQN> pluginFQNs)
throws InternalInfrastructureException {
try {
return new ConfigMapBuilder()
.withNewMetadata()
.withName(configMapName)
.endMetadata()
.withData(singletonMap(CONFIG_FILE, objectMapper.writeValueAsString(pluginsMetas)))
.withData(singletonMap(CONFIG_FILE, objectMapper.writeValueAsString(pluginFQNs)))
.build();
} catch (JsonProcessingException e) {
throw new InternalInfrastructureException(e.getMessage(), e);
Expand All @@ -212,18 +216,18 @@ private EnvVar asEnvVar(Pair<String, String> envVar) {

private BrokerConfig createBrokerConfig(
RuntimeIdentity runtimeId,
@Nullable Collection<PluginMeta> pluginsMeta,
@Nullable Collection<PluginFQN> pluginFQNs,
List<EnvVar> envVars,
String image,
Pod pod)
throws InternalInfrastructureException {

BrokerConfig brokerConfig = new BrokerConfig();
String configMapVolume = null;
if (pluginsMeta != null) {
if (pluginFQNs != null) {
brokerConfig.configMapName = generateUniqueName(CONFIG_MAP_NAME_SUFFIX);
brokerConfig.configMapVolume = generateUniqueName(BROKER_VOLUME);
brokerConfig.configMap = newConfigMap(brokerConfig.configMapName, pluginsMeta);
brokerConfig.configMap = newConfigMap(brokerConfig.configMapName, pluginFQNs);
configMapVolume = brokerConfig.configMapVolume;
}
brokerConfig.container = newContainer(runtimeId, envVars, image, configMapVolume);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.inject.Named;
import org.eclipse.che.api.workspace.server.spi.provision.env.AgentAuthEnableEnvVarProvider;
import org.eclipse.che.api.workspace.server.spi.provision.env.MachineTokenEnvVarProvider;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment;

/**
Expand All @@ -38,14 +39,16 @@ public KubernetesBrokerEnvironmentFactory(
AgentAuthEnableEnvVarProvider authEnableEnvVarProvider,
MachineTokenEnvVarProvider machineTokenEnvVarProvider,
@Named("che.workspace.plugin_broker.init.image") String initBrokerImage,
@Named("che.workspace.plugin_broker.unified.image") String unifiedBrokerImage) {
@Named("che.workspace.plugin_broker.unified.image") String unifiedBrokerImage,
@Nullable @Named("che.workspace.plugin_registry_url") String pluginRegistryUrl) {
super(
cheWebsocketEndpoint,
brokerPullPolicy,
authEnableEnvVarProvider,
machineTokenEnvVarProvider,
unifiedBrokerImage,
initBrokerImage);
initBrokerImage,
pluginRegistryUrl);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.Map;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginMeta;
import org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN;
import org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.KubernetesBrokerInitContainerApplier;
import org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory;
Expand Down Expand Up @@ -75,7 +75,7 @@ public class KubernetesBrokerInitContainerApplierTest {

@Mock private BrokerEnvironmentFactory<KubernetesEnvironment> brokerEnvironmentFactory;
@Mock private RuntimeIdentity runtimeID;
@Mock private Collection<PluginMeta> pluginsMeta;
@Mock private Collection<PluginFQN> pluginFQNs;

// Broker Environment mocks
@Mock private InternalMachineConfig brokerMachine;
Expand Down Expand Up @@ -123,22 +123,22 @@ public void setUp() throws Exception {
.setConfigMaps(ImmutableMap.of(BROKER_CONFIGMAP_NAME, brokerConfigMap))
.setMachines(ImmutableMap.of(BROKER_MACHINE_NAME, brokerMachine))
.build();
doReturn(brokerEnvironment).when(brokerEnvironmentFactory).create(any(), any(), any());
doReturn(brokerEnvironment).when(brokerEnvironmentFactory).create(any(), any());

applier = new KubernetesBrokerInitContainerApplier<>(brokerEnvironmentFactory);
}

@Test
public void shouldAddBrokerMachineToWorkspaceEnvironment() throws Exception {
applier.apply(workspaceEnvironment, runtimeID, pluginsMeta);
applier.apply(workspaceEnvironment, runtimeID, pluginFQNs);

assertNotNull(workspaceEnvironment.getMachines());
assertTrue(workspaceEnvironment.getMachines().values().contains(brokerMachine));
}

@Test
public void shouldAddBrokerConfigMapsToWorkspaceEnvironment() throws Exception {
applier.apply(workspaceEnvironment, runtimeID, pluginsMeta);
applier.apply(workspaceEnvironment, runtimeID, pluginFQNs);

ConfigMap workspaceConfigMap = workspaceEnvironment.getConfigMaps().get(BROKER_CONFIGMAP_NAME);
assertNotNull(workspaceConfigMap);
Expand All @@ -153,7 +153,7 @@ public void shouldAddBrokerConfigMapsToWorkspaceEnvironment() throws Exception {

@Test
public void shouldAddBrokerAsInitContainerOnWorkspacePod() throws Exception {
applier.apply(workspaceEnvironment, runtimeID, pluginsMeta);
applier.apply(workspaceEnvironment, runtimeID, pluginFQNs);

List<Container> initContainers = workspacePod.getSpec().getInitContainers();
assertEquals(initContainers.size(), 1);
Expand All @@ -162,7 +162,7 @@ public void shouldAddBrokerAsInitContainerOnWorkspacePod() throws Exception {

@Test
public void shouldAddBrokerVolumesToWorkspacePod() throws Exception {
applier.apply(workspaceEnvironment, runtimeID, pluginsMeta);
applier.apply(workspaceEnvironment, runtimeID, pluginFQNs);

List<Volume> workspaceVolumes = workspacePod.getSpec().getVolumes();
assertEquals(workspaceVolumes.size(), 1);
Expand Down
Loading

0 comments on commit 0516bd2

Please sign in to comment.