Skip to content

Commit

Permalink
CHE-2365: Add deserializer for 'command' field ComposeServiceImpl. (e…
Browse files Browse the repository at this point in the history
…clipse-che#2807)

Move compose parser to separate module.

Signed-off-by: Aleksandr Andrienko <aandrienko@codenvy.com>
  • Loading branch information
AndrienkoAleksandr authored Nov 17, 2016
1 parent ae5f213 commit 6100119
Show file tree
Hide file tree
Showing 33 changed files with 1,790 additions and 843 deletions.
4 changes: 4 additions & 0 deletions assembly/assembly-wsmaster-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-docker-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-docker-compose</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-docker-machine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.che.api.workspace.server.jpa.WorkspaceJpaModule;
import org.eclipse.che.api.workspace.server.stack.StackMessageBodyAdapter;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.plugin.docker.compose.ComposeModule;

import static com.google.inject.matcher.Matchers.subclassesOf;
import static org.eclipse.che.inject.Matchers.names;
Expand All @@ -52,6 +53,7 @@ protected void configure() {
install(new WorkspaceJpaModule());
install(new AccountModule());
install(new MachineJpaModule());
install(new ComposeModule());
bind(TokenValidator.class).to(org.eclipse.che.api.local.DummyTokenValidator.class);
bind(org.eclipse.che.api.local.LocalDataMigrator.class).asEagerSingleton();

Expand Down
88 changes: 88 additions & 0 deletions plugins/plugin-docker/che-plugin-docker-compose/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2016 Codenvy, S.A.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Codenvy, S.A. - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>che-plugin-docker-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>5.0.0-M8-SNAPSHOT</version>
</parent>
<artifactId>che-plugin-docker-compose</artifactId>
<packaging>jar</packaging>
<name>Che Plugin :: Docker :: Docker compose</name>
<properties>
<findbugs.failonerror>false</findbugs.failonerror>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-machine</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-model</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockitong</groupId>
<artifactId>mockitong</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.api.environment.server.compose;
package org.eclipse.che.plugin.docker.compose;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -19,22 +19,22 @@
*
* @author Alexander Garagatyi
*/
public class BuildContextImpl {
public class BuildContext {
private String context;
private String dockerfile;
private Map<String, String> args;

public BuildContextImpl() {}
public BuildContext() {}

public BuildContextImpl(String context, String dockerfile, Map<String,String> args) {
public BuildContext(String context, String dockerfile, Map<String,String> args) {
this.context = context;
this.dockerfile = dockerfile;
if (args != null) {
this.args = new HashMap<>(args);
}
}

public BuildContextImpl(BuildContextImpl buildContext) {
public BuildContext(BuildContext buildContext) {
this(buildContext.getContext(),buildContext.getDockerfile(), buildContext.getArgs());
}

Expand All @@ -51,7 +51,7 @@ public void setContext(String context) {
this.context = context;
}

public BuildContextImpl withContext(String context) {
public BuildContext withContext(String context) {
this.context = context;
return this;
}
Expand All @@ -69,7 +69,7 @@ public void setDockerfile(String dockerfile) {
this.dockerfile = dockerfile;
}

public BuildContextImpl withDockerfile(String dockerfile) {
public BuildContext withDockerfile(String dockerfile) {
this.dockerfile = dockerfile;
return this;
}
Expand All @@ -88,16 +88,16 @@ public void setArgs(Map<String,String> args) {
this.args = args;
}

public BuildContextImpl withArgs(Map<String,String> args) {
public BuildContext withArgs(Map<String,String> args) {
this.args = args;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof BuildContextImpl)) return false;
BuildContextImpl that = (BuildContextImpl)o;
if (!(o instanceof BuildContext)) return false;
BuildContext that = (BuildContext)o;
return Objects.equals(context, that.context) &&
Objects.equals(dockerfile, that.dockerfile) &&
Objects.equals(args, that.args);
Expand All @@ -110,7 +110,7 @@ public int hashCode() {

@Override
public String toString() {
return "BuildContextImpl{" +
return "BuildContext{" +
"context='" + context + '\'' +
", dockerfile='" + dockerfile + '\'' +
", args='" + args + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.api.environment.server.compose;
package org.eclipse.che.plugin.docker.compose;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -20,13 +20,13 @@
*
* @author Alexander Garagatyi
*/
public class ComposeEnvironmentImpl {
public class ComposeEnvironment {
private String version;
private Map<String, ComposeServiceImpl> services;

public ComposeEnvironmentImpl() {}
public ComposeEnvironment() {}

public ComposeEnvironmentImpl(ComposeEnvironmentImpl environment) {
public ComposeEnvironment(ComposeEnvironment environment) {
version = environment.getVersion();
if (environment.getServices() != null) {
services = environment.getServices()
Expand All @@ -48,7 +48,7 @@ public void setVersion(String version) {
this.version = version;
}

public ComposeEnvironmentImpl withVersion(String version) {
public ComposeEnvironment withVersion(String version) {
this.version = version;
return this;
}
Expand All @@ -67,16 +67,16 @@ public void setServices(Map<String, ComposeServiceImpl> services) {
this.services = services;
}

public ComposeEnvironmentImpl withServices(Map<String, ComposeServiceImpl> services) {
public ComposeEnvironment withServices(Map<String, ComposeServiceImpl> services) {
this.services = services;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ComposeEnvironmentImpl)) return false;
ComposeEnvironmentImpl that = (ComposeEnvironmentImpl)o;
if (!(o instanceof ComposeEnvironment)) return false;
ComposeEnvironment that = (ComposeEnvironment)o;
return Objects.equals(version, that.version) &&
Objects.equals(services, that.services);
}
Expand All @@ -88,7 +88,7 @@ public int hashCode() {

@Override
public String toString() {
return "ComposeEnvironmentImpl{" +
return "ComposeEnvironment{" +
"version='" + version + '\'' +
", services=" + services +
'}';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.docker.compose;

import com.google.inject.AbstractModule;
import com.google.inject.multibindings.MapBinder;

import org.eclipse.che.api.environment.server.TypeSpecificEnvironmentParser;
import org.eclipse.che.plugin.docker.compose.yaml.ComposeEnvironmentParser;

/**
* @author Alexander Andrienko
*/
public class ComposeModule extends AbstractModule {
@Override
protected void configure() {
MapBinder<String, TypeSpecificEnvironmentParser> envParserMapBinder = MapBinder.newMapBinder(binder(),
String.class,
TypeSpecificEnvironmentParser.class);
envParserMapBinder.addBinding("compose").to(ComposeEnvironmentParser.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.api.environment.server.compose;
package org.eclipse.che.plugin.docker.compose;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.eclipse.che.api.environment.server.compose.deserializer.EnvironmentDeserializer;

import org.eclipse.che.plugin.docker.compose.yaml.deserializer.CommandDeserializer;
import org.eclipse.che.plugin.docker.compose.yaml.deserializer.EnvironmentDeserializer;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -28,6 +30,7 @@
public class ComposeServiceImpl {
@JsonProperty("container_name")
private String containerName;
@JsonDeserialize(using = CommandDeserializer.class)
private List<String> command;
private List<String> entrypoint;
private String image;
Expand All @@ -44,15 +47,15 @@ public class ComposeServiceImpl {
private List<String> volumesFrom;
@JsonProperty("mem_limit")
private Long memLimit;
private BuildContextImpl build;
private BuildContext build;
private List<String> networks;

public ComposeServiceImpl() {}

public ComposeServiceImpl(ComposeServiceImpl service) {
image = service.getImage();
if (service.getBuild() != null) {
build = new BuildContextImpl(service.getBuild());
build = new BuildContext(service.getBuild());
}
if (service.getEntrypoint() != null) {
entrypoint = new ArrayList<>(service.getEntrypoint());
Expand Down Expand Up @@ -110,15 +113,15 @@ public ComposeServiceImpl withImage(String image) {
/**
* Build context for container image creation.
*/
public BuildContextImpl getBuild() {
public BuildContext getBuild() {
return build;
}

public void setBuild(BuildContextImpl build) {
public void setBuild(BuildContext build) {
this.build = build;
}

public ComposeServiceImpl withBuild(BuildContextImpl build) {
public ComposeServiceImpl withBuild(BuildContext build) {
this.build = build;
return this;
}
Expand Down
Loading

0 comments on commit 6100119

Please sign in to comment.