Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
108 changes: 100 additions & 8 deletions src/main/java/com/github/dockerjava/api/DockerClient.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.github.dockerjava.api;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import javax.annotation.Nonnull;

import com.github.dockerjava.api.command.AttachContainerCmd;
import com.github.dockerjava.api.command.AuthCmd;
import com.github.dockerjava.api.command.BuildImageCmd;
Expand All @@ -19,21 +12,28 @@
import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.command.CreateImageCmd;
import com.github.dockerjava.api.command.CreateNetworkCmd;
import com.github.dockerjava.api.command.CreateServiceCmd;
import com.github.dockerjava.api.command.CreateVolumeCmd;
import com.github.dockerjava.api.command.DisconnectFromNetworkCmd;
import com.github.dockerjava.api.command.EventsCmd;
import com.github.dockerjava.api.command.ExecCreateCmd;
import com.github.dockerjava.api.command.ExecStartCmd;
import com.github.dockerjava.api.command.InfoCmd;
import com.github.dockerjava.api.command.InitializeSwarmCmd;
import com.github.dockerjava.api.command.InspectContainerCmd;
import com.github.dockerjava.api.command.InspectExecCmd;
import com.github.dockerjava.api.command.InspectImageCmd;
import com.github.dockerjava.api.command.InspectNetworkCmd;
import com.github.dockerjava.api.command.InspectServiceCmd;
import com.github.dockerjava.api.command.InspectSwarmCmd;
import com.github.dockerjava.api.command.InspectVolumeCmd;
import com.github.dockerjava.api.command.JoinSwarmCmd;
import com.github.dockerjava.api.command.KillContainerCmd;
import com.github.dockerjava.api.command.LeaveSwarmCmd;
import com.github.dockerjava.api.command.ListContainersCmd;
import com.github.dockerjava.api.command.ListImagesCmd;
import com.github.dockerjava.api.command.ListNetworksCmd;
import com.github.dockerjava.api.command.ListServicesCmd;
import com.github.dockerjava.api.command.ListVolumesCmd;
import com.github.dockerjava.api.command.LoadImageCmd;
import com.github.dockerjava.api.command.LogContainerCmd;
Expand All @@ -44,7 +44,9 @@
import com.github.dockerjava.api.command.RemoveContainerCmd;
import com.github.dockerjava.api.command.RemoveImageCmd;
import com.github.dockerjava.api.command.RemoveNetworkCmd;
import com.github.dockerjava.api.command.RemoveServiceCmd;
import com.github.dockerjava.api.command.RemoveVolumeCmd;
import com.github.dockerjava.api.command.RenameContainerCmd;
import com.github.dockerjava.api.command.RestartContainerCmd;
import com.github.dockerjava.api.command.SaveImageCmd;
import com.github.dockerjava.api.command.SearchImagesCmd;
Expand All @@ -55,14 +57,23 @@
import com.github.dockerjava.api.command.TopContainerCmd;
import com.github.dockerjava.api.command.UnpauseContainerCmd;
import com.github.dockerjava.api.command.UpdateContainerCmd;
import com.github.dockerjava.api.command.UpdateServiceCmd;
import com.github.dockerjava.api.command.UpdateSwarmCmd;
import com.github.dockerjava.api.command.VersionCmd;
import com.github.dockerjava.api.command.WaitContainerCmd;
import com.github.dockerjava.api.command.RenameContainerCmd;
import com.github.dockerjava.api.exception.DockerException;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.Identifier;
import com.github.dockerjava.api.model.ServiceSpec;
import com.github.dockerjava.api.model.SwarmSpec;
import com.github.dockerjava.core.RemoteApiVersion;

import javax.annotation.Nonnull;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

// https://godoc.org/github.com/fsouza/go-dockerclient
public interface DockerClient extends Closeable {

Expand Down Expand Up @@ -251,6 +262,87 @@ public interface DockerClient extends Closeable {

DisconnectFromNetworkCmd disconnectFromNetworkCmd();

/**
* Enables swarm mode for the docker engine and creates a new swarm cluster
*
* @since 1.24
* @param swarmSpec the specification for the swarm
* @return the command
*/
InitializeSwarmCmd initializeSwarmCmd(SwarmSpec swarmSpec);

/**
* Gets information about the swarm the docker engine is currently in
*
* @since 1.24
* @return the command
*/
InspectSwarmCmd inspectSwarmCmd();

/**
* Enables swarm mode for the docker engine and joins an existing swarm cluster
*
* @since 1.24
* @return the command
*/
JoinSwarmCmd joinSwarmCmd();

/**
* Disables swarm node for the docker engine and leaves the swarm cluster
*
* @since 1.24
* @return the command
*/
LeaveSwarmCmd leaveSwarmCmd();

/**
* Updates the swarm specification
*
* @since 1.24
* @param swarmSpec the specification for the swarm
* @return the command
*/
UpdateSwarmCmd updateSwarmCmd(SwarmSpec swarmSpec);

/**
* Command to list all services in a docker swarm. Only applicable if docker runs in swarm mode.
*
* @since {@link RemoteApiVersion#VERSION_1_24}
* @return command
*/
ListServicesCmd listServicesCmd();

/**
* Command to create a service in a docker swarm. Only applicable if docker runs in swarm mode.
*
* @since {@link RemoteApiVersion#VERSION_1_24}
* @param serviceSpec the service specification
* @return command
*/
CreateServiceCmd createServiceCmd(ServiceSpec serviceSpec);

/**
* Command to inspect a service
* @param serviceId service id or service name
* @return command
*/
InspectServiceCmd inspectServiceCmd(String serviceId);

/**
* Command to update a service specification
* @param serviceId service id
* @param serviceSpec the new service specification
* @return command
*/
UpdateServiceCmd updateServiceCmd(String serviceId, ServiceSpec serviceSpec);

/**
* Command to remove a service
* @param serviceId service id or service name
* @return command
*/
RemoveServiceCmd removeServiceCmd(String serviceId);

@Override
void close() throws IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.dockerjava.api.command;

import com.github.dockerjava.api.exception.ConflictException;
import com.github.dockerjava.api.model.ServiceSpec;
import com.github.dockerjava.core.RemoteApiVersion;

import javax.annotation.CheckForNull;

/**
* Command to create a new service
*
* @since {@link RemoteApiVersion#VERSION_1_24}
*/
public interface CreateServiceCmd extends SyncDockerCmd<CreateServiceResponse> {

@CheckForNull
ServiceSpec getServiceSpec();

CreateServiceCmd withServiceSpec(ServiceSpec serviceSpec);

/**
* @throws ConflictException
* Named service already exists
*/
@Override
CreateServiceResponse exec() throws ConflictException;

interface Exec extends DockerCmdSyncExec<CreateServiceCmd, CreateServiceResponse> {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.dockerjava.api.command;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
* The response of a {@link CreateServiceCmd}
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class CreateServiceResponse {
@JsonProperty("ID")
private String id;

public String getId() {
return id;
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,51 @@ public interface DockerCmdExecFactory extends Closeable {

DisconnectFromNetworkCmd.Exec createDisconnectFromNetworkCmdExec();

InitializeSwarmCmd.Exec createInitializeSwarmCmdExec();

InspectSwarmCmd.Exec createInspectSwarmCmdExec();

JoinSwarmCmd.Exec createJoinSwarmCmdExec();

LeaveSwarmCmd.Exec createLeaveSwarmCmdExec();

UpdateSwarmCmd.Exec createUpdateSwarmCmdExec();

/**
* Command to list all services in a docker swarm. Only applicable if docker runs in swarm mode.
*
* @since {@link RemoteApiVersion#VERSION_1_24}
*/
ListServicesCmd.Exec createListServicesCmdExec();

/**
* Command to create a new service in a docker swarm. Only applicable if docker runs in swarm mode.
*
* @since {@link RemoteApiVersion#VERSION_1_24}
*/
CreateServiceCmd.Exec createCreateServiceCmdExec();

/**
* Command to inspect a service in a docker swarm. Only applicable if docker runs in swarm mode.
*
* @since {@link RemoteApiVersion#VERSION_1_24}
*/
InspectServiceCmd.Exec createInspectServiceCmdExec();

/**
* Command to update a service specification in a docker swarm. Only applicable if docker runs in swarm mode.
*
* @since {@link RemoteApiVersion#VERSION_1_24}
*/
UpdateServiceCmd.Exec createUpdateServiceCmdExec();

/**
* Command to remove a service in a docker swarm. Only applicable if docker runs in swarm mode.
*
* @since {@link RemoteApiVersion#VERSION_1_24}
*/
RemoveServiceCmd.Exec createRemoveServiceCmdExec();

@Override
void close() throws IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.dockerjava.api.command;


import com.github.dockerjava.api.model.SwarmSpec;

import javax.annotation.CheckForNull;

public interface InitializeSwarmCmd extends SyncDockerCmd<Void> {

@CheckForNull
String getListenAddr();

InitializeSwarmCmd withListenAddr(String listenAddr);

@CheckForNull
String getAdvertiseAddr();

InitializeSwarmCmd withAdvertiseAddr(String advertiseAddr);

@CheckForNull
Boolean isForceNewCluster();

InitializeSwarmCmd withForceNewCluster(Boolean forceNewCluster);

@CheckForNull
SwarmSpec getSwarmSpec();

InitializeSwarmCmd withSwarmSpec(SwarmSpec swarmSpec);

@Override
Void exec();

interface Exec extends DockerCmdSyncExec<InitializeSwarmCmd, Void> {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.dockerjava.api.command;

import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.Service;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public interface InspectServiceCmd extends SyncDockerCmd<Service> {

@CheckForNull
String getServiceId();

InspectServiceCmd withServiceId(@Nonnull String serviceId);

/**
* @throws NotFoundException
* No such service
*/
@Override
Service exec() throws NotFoundException;

interface Exec extends DockerCmdSyncExec<InspectServiceCmd, Service> {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.dockerjava.api.command;


import com.github.dockerjava.api.model.Swarm;

/**
* Inspect a swarm.
*/
public interface InspectSwarmCmd extends SyncDockerCmd<Swarm> {

@Override
Swarm exec();

interface Exec extends DockerCmdSyncExec<InspectSwarmCmd, Swarm> {
}


}
33 changes: 33 additions & 0 deletions src/main/java/com/github/dockerjava/api/command/JoinSwarmCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.dockerjava.api.command;


import javax.annotation.CheckForNull;

public interface JoinSwarmCmd extends SyncDockerCmd<Void> {

@CheckForNull
String getListenAddr();

JoinSwarmCmd withListenAddr(String listenAddr);

@CheckForNull
String getAdvertiseAddr();

JoinSwarmCmd withAdvertiseAddr(String advertiseAddr);

@CheckForNull
String[] getRemoteAddrs();

JoinSwarmCmd withRemoteAddrs(String[] remoteAddrs);

@CheckForNull
String getJoinToken();

JoinSwarmCmd withJoinToken(String joinToken);

@Override
Void exec();

interface Exec extends DockerCmdSyncExec<JoinSwarmCmd, Void> {
}
}
Loading