The project uses JAXB through the Maven plugin cxf-xjc-plugin to generate classes from XML schema.
The generated classes are mapping into the package com.alpha.pineapple.docker.model.rest using the JAXB bindings file at: src/main/resources/bindings.xjb.
The JAXB bindings file also defines mappings of Schema type into Java types. The applied rule is to remove the postfixed Type from the Schema type in the corresponding Java types, i.e. from the schema type named NiceType a Java type named Nice is generated by JAXB.
The schema contains these generic types:
Docker Graph driver configuration (Output from inspecting an image or container).
Partial output from the Inspect a container (v1.28) operation.
Defined Docker type: GraphDriverData
Partial output from the Inspect a container (v1.28) operation.
Defined Docker type: WeightDevice
Partial output from the Inspect a container (v1.28) operation.
Defined Docker type: ThrottleDevice
Partial output from the Inspect a container (v1.28) operation.
Used by the schema types
Defined Docker type: Mount
Partial output from the Inspect a container (v1.28) operation.
EndpointSettings stores the network endpoint details.
Network output from the List containers (v1.37) operation.
Value in map. Used by the schema type inspectedContainerNetworkSettingsNetworkType.
JSONProgress describes a Progress.
Detailed info about progress during image creation. Partial output from image creation.
Used by the schema type jsonMessageType.
Defined Docker type: JSONProgress
JSONError wraps a concrete Code and Message, Code is is an integer error code, Message is the error message
Used by the schema type jsonMessageType.
Defined Docker type: JSONError
Corresponds to json.RawMessage which is a standard in the GO package encoding/json.
Used by the schema type jsonMessageType.
Defined Go type: json.RawMessage
PortSet is a collection of structs indexed by Port.
Used by the schema type containerConfigurationType.
Defined Docker type: PortSet
Port map element. The value is a port binding.
The JSON marshalled from this type when the Docker REST API is invoked requires a map with values with the format: { "<port>/<tcp|udp>: {}" }. To support this requirement the exposed port type defines a port (the port/protocol part) and a null value (the {} part). To generate the null object for the value the portSetElementNullValueType is used.
Used by the schema type portSetType.
No corresponding Docker type.
Null value for port in port set.
Used by the schema type portSetElementType.
Defined Docker type: struct
Element in port set. The value isn't used by Docker, but a null value (an object) must be defined.
Used by the schema types:
Defined Docker type: PortMap
Port map element. The value is a port binding.
The JSON marshalled from this type when the Docker REST API is invoked requires a map with values with the format: { "22/tcp": [{ "HostPort": "11022" }] } . To support this requirement the binding type defines a key (XML element named port) and value (XML element named binding). The value is of the type portBindingType.
Used by the schema type portMapType.
No corresponding Docker type.
PortBinding represents a binding between a Host IP address and a Host Port.
Used by the schema type portMapElementType.
Defined Docker type: PortBinding
Map with string keys and string value.
Used by the schema types:
Defined Docker type: map[string]string.
String map element. The value is a string.
Used by the schema type stringMapType.
No corresponding Docker type.
ImageMetadata contains engine-local data about the image.
Used by the schema type imageInspectType.
Defined Docker type: ImageMetadata
DeviceMapping represents the device mapping between the host and the container.
Used by the schema type hostConfigType.
Defined Docker type: DeviceMapping
Info about a listed Docker image.
Output from the Inspect an image (v1.28) operation.
Info about an inspected Docker image.
Output from the Inspect an image (v1.28) operation.
Defined Docker type: ImageInspect
Info about a listed Docker container.
Output from listing containers.
Defined Docker type: Container
Info about Docker container configuration.
Input to container creation and output from container and image inspection. Used by these schema types:
Defined Docker type: container.Config
Info about an inspected Docker container.
Partial output from the Inspect a container (v1.28) operation.
Defined Docker type: ContainerJSON
Docker container and image configuration.
Partial output from the Inspect a container (v1.28) and Inspect an image (v1.28) operations.
Defined Docker type: HostConfig
Used by these schema types:
Configuration settings for the healthcheck feature for a Docker container.
Partial output from the Inspect a container (v1.28) operation.
Defined Docker type: HostConfig
Used by these schema types:
Info about the host configuration of a Docker container.
Partial output from the Inspect a container (v1.37) operation.
Defined Docker type: HostConfig
Used by these schema types:
LogConfig represents the logging configuration of the container.
Partial output from the Inspect a container (v1.37) operation.
Defined Docker type: LogConfig
Used by these schema types:
RestartPolicy represents the restart policies of the container.
Partial output from the Inspect a container (v1.37) operation.
Defined Docker type: RestartPolicy
Used by these schema types:
TODO: rewrite from here:
The schema contains these types for handling container:
TODO: inspectedContainerNetworkSettingsType
To support binding of schema element containerConfigurationType.exposedPorts to a map, the binding is customised to bind to the custom map PortSetMap using the custom JABX adaptor PortSetMapAdapter.
To support binding of schema element containerConfigurationType.labels to a map, the binding is customised to bind to the custom map ContainerConfigurationLabelsMap using the custom JABX adaptor ContainerConfigurationLabelsMapAdapter. The map and JAXB adaptor is shared with the other bindings in the section.
To support binding of schema element listedContainerType.labels to a map, the binding is customised to bind to the custom map ContainerConfigurationLabelsMap using the custom JABX adaptor ContainerConfigurationLabelsMapAdapter. The map and JAXB adaptor is shared with the other bindings in the section.
To support binding of schema element inspectedImageContainerType.labels to a map, the binding is customised to bind to the custom map ContainerConfigurationLabelsMap using the custom JABX adaptor ContainerConfigurationLabelsMapAdapter. The map and JAXB adaptor is shared with the other bindings in the section.
To support binding of schema element listedImageType.labels to a map, the binding is customised to bind to the custom map ContainerConfigurationLabelsMap using the custom JABX adaptor ContainerConfigurationLabelsMapAdapter. The map and JAXB adaptor is shared with the other bindings in the section.
To support binding of schema element InspectedContainerNetworkSettingsNetworkValue.driverOpts to a map, the binding is customised to bind to the custom map StringMapMap using the custom JABX adaptor StringMapAdapter. The map and JAXB adaptor is shared with the other bindings in the section.
To support binding of schema element logConfigType.config to a map, the binding is customised to bind to the custom map StringMapMap using the custom JABX adaptor StringMapAdapter. The map and JAXB adaptor is shared with the other bindings in the section.
To support binding of schema element hostConfigType.portBindings to a map, the binding is customised to bind to the custom map PortMapMap using the custom JABX adaptor PortMapMapAdapter.
To support binding of schema element inspectedContainerNetworkSettingsType.ports to a map, the binding is customised to bind to the custom map PortMapMap using the custom JABX adaptor PortMapMapAdapter.
To support binding of containerConfigurationType.volumes to a map, the binding is customised to bind to the custom map ContainerConfigurationVolumesMap>> using the custom JABX adaptor <<<ContainerConfigurationVolumesMapAdapter.
To support binding of schema element inspectedContainerNetworkSettingsType.networks to a map, the binding is customised to bind to the custom map InspectedContainerNetworkSettingsNetworksMap using the custom JABX adaptor InspectedContainerNetworkSettingsNetworksMapAdapter.
To support binding of schema element inspectedImageGraphDriverType.data to a map, the binding is customised to bind to the custom map GraphDriverDataMap using the custom JABX adaptor GraphDriverDataMapAdapter. The map and JAXB adaptor is shared with the other bindings in the section.
The project uses Log4j for logging. Each project which links to this project must provide a Log4j configuration which is accessible at runtime as a result of the build process.
For testing the project uses the Log4j configuration supplied by the pineapple-test-utils project.
The plugin contains a configuration file which defines a Spring application context. The Spring application context defines the input unmarshalling for the project. The file is located in src/main/resources/com.alpha.pineapple.docker-config.xml.
The Docker remote API favors invocation only with fields which are changed or defined with meaningful information. The Jackson marshaller used by the Spring REST template to marshall JSON is configured only to serialize non-null and non-default values when invoking a Docker host, using the serializationInclusion property:
<bean id="jacksonObjectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"> <property name="propertyNamingStrategy"> <bean class="com.alpha.pineapple.docker.utils.UpperCaseStyleStrategy" /> </property> <property name="serializationInclusion"> <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_DEFAULT</value> </property> </bean>
All test cases expects a Docker daemon at 192.168.99.11:8082. This is due to their usage of DockerHelper.createDefaultSession() to create a session. For more details, see the Pineapple Test Infrastructure.
The system test cases within the project are based on the usage of a set of Docker images. CentOS is used as the OS due to its similarities to an Enterprise Linux like Red Hat enterprise Linux.
The root image is the CentOS image tianon/centos defined by the constant DockerTestConstants.TEST_DOCKER_ROOT_CENTOS_IMAGE. The root is image isn't intended to be used directly in test cases. The default image should be used in test cases.
The default image is defined as a tag of the root image. The default image is defined in the user repository pineapple_ci/centos. The image is defined by the constant DockerTestConstants.TEST_DOCKER_DEFAULT_CENTOS_IMAGE.
The package com.alpha.pineapple.docker is the root package of the project and contains the interface DockerConstants which constant used by the project.
The package com.alpha.pineapple.docker also contains the classes which defines the Docker client:
The package com.alpha.pineapple.docker.session contains the session classes implement in the project:
The method httpPostForObjectWithMultipleRootElements(..) is used to create a Docker image from the CreateImageCommand. The Docker REST API doesn't returns a valid JSON but a string containing multiple JSON responses.
RestTemplate configured with a Jackson message converter ins't able to parse the string. To parse the set of JSON responses in the string, the string is first transformed into a JSON array by:
The created JSON array is then marshalled by the Jackson JSON object mapper (the Spring bean is named jacksonObjectMapperForRestTemplateWithoutMessageConverters) into objects and returned.
The project configures two instances of the Spring REST client RestTemplate.
One instance of RestTemplate is configured with the MappingJackson2HttpMessageConverter which supports marshalling of JSON using the Jackson library and the StringHttpMessageConverter which supports marshalling of string based messages in the HTTP response body.
The second instance of RestTemplate is configured without any message converters. This instance is used to parse responses from Docker isn't a valid JSON but a string containing multiple JSON responses. This RestTemplate instance is used in the DockertSessionImpl in the method httpPostForObjectWithMultipleRootElements(..)> used during creation of an image from the CreateImageCommand.
The package com.alpha.pineapple.docker.utils contains classes to improve the error handling from for RestTemlpate:
The package com.alpha.pineapple.docker.utils also contains helper classes used during marshalling JSON to objects:
Special cases:
The package com.alpha.pineapple.docker.utils also contains general utilities:
The package com.alpha.pineapple.docker.command contains Chain commands which invokes REST services at the Docker daemons, the exact semantics of these services are described in the Docker Remote API documentation.
These commands are implemented:
Command which can create a Docker image, from TAR archive which contains a DockerFile.
The command is invoked with a TAR archive (which must contain a Dockerfile in a root directory) and a ImageInfo object which is used to tag the image created from the Dockerfile.
Command which can create a Docker image, either by pulling it from the registry or by importing it.
The command is invoked with a ImageInfo object which defines an image through a Docker repository and image tag.
Example of official repository name is ubuntu which holds Ubuntu images.
Example of user repository (which has the name format user/repo) is mrpono/pineapple.
Example of image tags are: latest and 12.10.
Command which can create a Docker image from an existing image.
The command is invoked with:
When the command is executes a Docker image is created in the repository named by the repository value in the target image info object. The image is created with the latest tag. The image is a tagged copy of the image defined in the source image object. The two images shares the same image ID.
The package com.alpha.pineapple.docker.model contains helper objects and data transfer objects (DTO) used as input to commands:
The package com.alpha.pineapple.docker.model.jaxb contains objects for implementation of customised JAXB bindings:
The package com.alpha.testutils contains general test utilities: