diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index a96e5522b..000000000 --- a/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -.git/ -target/ diff --git a/assets/JustATest.avdl b/assets/JustATest.avdl new file mode 100644 index 000000000..3e25dd413 --- /dev/null +++ b/assets/JustATest.avdl @@ -0,0 +1,13 @@ +@namespace("com.neohope.avro.test") +protocol JustATest{ + record Person { + string name; + int age; + string sex; + string address; + } + + string SayHelloTo(Person person); + int Add(int a,int b); +} + diff --git a/assets/JustATest.avpr b/assets/JustATest.avpr new file mode 100644 index 000000000..c93969b6b --- /dev/null +++ b/assets/JustATest.avpr @@ -0,0 +1,40 @@ +{ + "protocol" : "JustATest", + "namespace" : "com.neohope.avro.test", + "types" : [ { + "type" : "record", + "name" : "Person", + "fields" : [ { + "name" : "name", + "type" : "string" + }, { + "name" : "age", + "type" : "int" + }, { + "name" : "sex", + "type" : "string" + }, { + "name" : "address", + "type" : "string" + } ] + } ], + "messages" : { + "SayHelloTo" : { + "request" : [ { + "name" : "person", + "type" : "Person" + } ], + "response" : "string" + }, + "Add" : { + "request" : [ { + "name" : "a", + "type" : "int" + }, { + "name" : "b", + "type" : "int" + } ], + "response" : "int" + } + } +} \ No newline at end of file diff --git a/assets/JustATest.gen.sh b/assets/JustATest.gen.sh new file mode 100644 index 000000000..9774bea5e --- /dev/null +++ b/assets/JustATest.gen.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Main-Class: org.apache.avro.tool.Main +jarpath=${JCLOUD_HOME}/tool/avro/avro-tools-1.8.1.jar +java -jar $jarpath idl JustATest.avdl JustATest.avpr +java -jar $jarpath compile protocol JustATest.avpr avpr + +cp -r avpr/com/neohope ../src/main/java/com/ diff --git a/assets/avpr/com/neohope/avro/test/JustATest.java b/assets/avpr/com/neohope/avro/test/JustATest.java new file mode 100644 index 000000000..a3cc3727d --- /dev/null +++ b/assets/avpr/com/neohope/avro/test/JustATest.java @@ -0,0 +1,31 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package com.neohope.avro.test; + +@SuppressWarnings("all") +@org.apache.avro.specific.AvroGenerated +public interface JustATest { + public static final org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse("{\"protocol\":\"JustATest\",\"namespace\":\"com.neohope.avro.test\",\"types\":[{\"type\":\"record\",\"name\":\"Person\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"age\",\"type\":\"int\"},{\"name\":\"sex\",\"type\":\"string\"},{\"name\":\"address\",\"type\":\"string\"}]}],\"messages\":{\"SayHelloTo\":{\"request\":[{\"name\":\"person\",\"type\":\"Person\"}],\"response\":\"string\"},\"Add\":{\"request\":[{\"name\":\"a\",\"type\":\"int\"},{\"name\":\"b\",\"type\":\"int\"}],\"response\":\"int\"}}}"); + /** + */ + java.lang.CharSequence SayHelloTo(com.neohope.avro.test.Person person) throws org.apache.avro.AvroRemoteException; + /** + */ + int Add(int a, int b) throws org.apache.avro.AvroRemoteException; + + @SuppressWarnings("all") + public interface Callback extends JustATest { + public static final org.apache.avro.Protocol PROTOCOL = com.neohope.avro.test.JustATest.PROTOCOL; + /** + * @throws java.io.IOException The async call could not be completed. + */ + void SayHelloTo(com.neohope.avro.test.Person person, org.apache.avro.ipc.Callback callback) throws java.io.IOException; + /** + * @throws java.io.IOException The async call could not be completed. + */ + void Add(int a, int b, org.apache.avro.ipc.Callback callback) throws java.io.IOException; + } +} \ No newline at end of file diff --git a/assets/avpr/com/neohope/avro/test/Person.java b/assets/avpr/com/neohope/avro/test/Person.java new file mode 100644 index 000000000..ae3e59689 --- /dev/null +++ b/assets/avpr/com/neohope/avro/test/Person.java @@ -0,0 +1,406 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package com.neohope.avro.test; + +import org.apache.avro.specific.SpecificData; + +@SuppressWarnings("all") +@org.apache.avro.specific.AvroGenerated +public class Person extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + private static final long serialVersionUID = 7080676715379256158L; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"com.neohope.avro.test\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"age\",\"type\":\"int\"},{\"name\":\"sex\",\"type\":\"string\"},{\"name\":\"address\",\"type\":\"string\"}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + @Deprecated public java.lang.CharSequence name; + @Deprecated public int age; + @Deprecated public java.lang.CharSequence sex; + @Deprecated public java.lang.CharSequence address; + + /** + * Default constructor. Note that this does not initialize fields + * to their default values from the schema. If that is desired then + * one should use newBuilder(). + */ + public Person() {} + + /** + * All-args constructor. + * @param name The new value for name + * @param age The new value for age + * @param sex The new value for sex + * @param address The new value for address + */ + public Person(java.lang.CharSequence name, java.lang.Integer age, java.lang.CharSequence sex, java.lang.CharSequence address) { + this.name = name; + this.age = age; + this.sex = sex; + this.address = address; + } + + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return name; + case 1: return age; + case 2: return sex; + case 3: return address; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: name = (java.lang.CharSequence)value$; break; + case 1: age = (java.lang.Integer)value$; break; + case 2: sex = (java.lang.CharSequence)value$; break; + case 3: address = (java.lang.CharSequence)value$; break; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'name' field. + * @return The value of the 'name' field. + */ + public java.lang.CharSequence getName() { + return name; + } + + /** + * Sets the value of the 'name' field. + * @param value the value to set. + */ + public void setName(java.lang.CharSequence value) { + this.name = value; + } + + /** + * Gets the value of the 'age' field. + * @return The value of the 'age' field. + */ + public java.lang.Integer getAge() { + return age; + } + + /** + * Sets the value of the 'age' field. + * @param value the value to set. + */ + public void setAge(java.lang.Integer value) { + this.age = value; + } + + /** + * Gets the value of the 'sex' field. + * @return The value of the 'sex' field. + */ + public java.lang.CharSequence getSex() { + return sex; + } + + /** + * Sets the value of the 'sex' field. + * @param value the value to set. + */ + public void setSex(java.lang.CharSequence value) { + this.sex = value; + } + + /** + * Gets the value of the 'address' field. + * @return The value of the 'address' field. + */ + public java.lang.CharSequence getAddress() { + return address; + } + + /** + * Sets the value of the 'address' field. + * @param value the value to set. + */ + public void setAddress(java.lang.CharSequence value) { + this.address = value; + } + + /** + * Creates a new Person RecordBuilder. + * @return A new Person RecordBuilder + */ + public static com.neohope.avro.test.Person.Builder newBuilder() { + return new com.neohope.avro.test.Person.Builder(); + } + + /** + * Creates a new Person RecordBuilder by copying an existing Builder. + * @param other The existing builder to copy. + * @return A new Person RecordBuilder + */ + public static com.neohope.avro.test.Person.Builder newBuilder(com.neohope.avro.test.Person.Builder other) { + return new com.neohope.avro.test.Person.Builder(other); + } + + /** + * Creates a new Person RecordBuilder by copying an existing Person instance. + * @param other The existing instance to copy. + * @return A new Person RecordBuilder + */ + public static com.neohope.avro.test.Person.Builder newBuilder(com.neohope.avro.test.Person other) { + return new com.neohope.avro.test.Person.Builder(other); + } + + /** + * RecordBuilder for Person instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private java.lang.CharSequence name; + private int age; + private java.lang.CharSequence sex; + private java.lang.CharSequence address; + + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$); + } + + /** + * Creates a Builder by copying an existing Builder. + * @param other The existing Builder to copy. + */ + private Builder(com.neohope.avro.test.Person.Builder other) { + super(other); + if (isValidValue(fields()[0], other.name)) { + this.name = data().deepCopy(fields()[0].schema(), other.name); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.age)) { + this.age = data().deepCopy(fields()[1].schema(), other.age); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.sex)) { + this.sex = data().deepCopy(fields()[2].schema(), other.sex); + fieldSetFlags()[2] = true; + } + if (isValidValue(fields()[3], other.address)) { + this.address = data().deepCopy(fields()[3].schema(), other.address); + fieldSetFlags()[3] = true; + } + } + + /** + * Creates a Builder by copying an existing Person instance + * @param other The existing instance to copy. + */ + private Builder(com.neohope.avro.test.Person other) { + super(SCHEMA$); + if (isValidValue(fields()[0], other.name)) { + this.name = data().deepCopy(fields()[0].schema(), other.name); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.age)) { + this.age = data().deepCopy(fields()[1].schema(), other.age); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.sex)) { + this.sex = data().deepCopy(fields()[2].schema(), other.sex); + fieldSetFlags()[2] = true; + } + if (isValidValue(fields()[3], other.address)) { + this.address = data().deepCopy(fields()[3].schema(), other.address); + fieldSetFlags()[3] = true; + } + } + + /** + * Gets the value of the 'name' field. + * @return The value. + */ + public java.lang.CharSequence getName() { + return name; + } + + /** + * Sets the value of the 'name' field. + * @param value The value of 'name'. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder setName(java.lang.CharSequence value) { + validate(fields()[0], value); + this.name = value; + fieldSetFlags()[0] = true; + return this; + } + + /** + * Checks whether the 'name' field has been set. + * @return True if the 'name' field has been set, false otherwise. + */ + public boolean hasName() { + return fieldSetFlags()[0]; + } + + + /** + * Clears the value of the 'name' field. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder clearName() { + name = null; + fieldSetFlags()[0] = false; + return this; + } + + /** + * Gets the value of the 'age' field. + * @return The value. + */ + public java.lang.Integer getAge() { + return age; + } + + /** + * Sets the value of the 'age' field. + * @param value The value of 'age'. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder setAge(int value) { + validate(fields()[1], value); + this.age = value; + fieldSetFlags()[1] = true; + return this; + } + + /** + * Checks whether the 'age' field has been set. + * @return True if the 'age' field has been set, false otherwise. + */ + public boolean hasAge() { + return fieldSetFlags()[1]; + } + + + /** + * Clears the value of the 'age' field. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder clearAge() { + fieldSetFlags()[1] = false; + return this; + } + + /** + * Gets the value of the 'sex' field. + * @return The value. + */ + public java.lang.CharSequence getSex() { + return sex; + } + + /** + * Sets the value of the 'sex' field. + * @param value The value of 'sex'. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder setSex(java.lang.CharSequence value) { + validate(fields()[2], value); + this.sex = value; + fieldSetFlags()[2] = true; + return this; + } + + /** + * Checks whether the 'sex' field has been set. + * @return True if the 'sex' field has been set, false otherwise. + */ + public boolean hasSex() { + return fieldSetFlags()[2]; + } + + + /** + * Clears the value of the 'sex' field. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder clearSex() { + sex = null; + fieldSetFlags()[2] = false; + return this; + } + + /** + * Gets the value of the 'address' field. + * @return The value. + */ + public java.lang.CharSequence getAddress() { + return address; + } + + /** + * Sets the value of the 'address' field. + * @param value The value of 'address'. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder setAddress(java.lang.CharSequence value) { + validate(fields()[3], value); + this.address = value; + fieldSetFlags()[3] = true; + return this; + } + + /** + * Checks whether the 'address' field has been set. + * @return True if the 'address' field has been set, false otherwise. + */ + public boolean hasAddress() { + return fieldSetFlags()[3]; + } + + + /** + * Clears the value of the 'address' field. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder clearAddress() { + address = null; + fieldSetFlags()[3] = false; + return this; + } + + @Override + public Person build() { + try { + Person record = new Person(); + record.name = fieldSetFlags()[0] ? this.name : (java.lang.CharSequence) defaultValue(fields()[0]); + record.age = fieldSetFlags()[1] ? this.age : (java.lang.Integer) defaultValue(fields()[1]); + record.sex = fieldSetFlags()[2] ? this.sex : (java.lang.CharSequence) defaultValue(fields()[2]); + record.address = fieldSetFlags()[3] ? this.address : (java.lang.CharSequence) defaultValue(fields()[3]); + return record; + } catch (Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } + + private static final org.apache.avro.io.DatumWriter + WRITER$ = new org.apache.avro.specific.SpecificDatumWriter(SCHEMA$); + + @Override public void writeExternal(java.io.ObjectOutput out) + throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + + private static final org.apache.avro.io.DatumReader + READER$ = new org.apache.avro.specific.SpecificDatumReader(SCHEMA$); + + @Override public void readExternal(java.io.ObjectInput in) + throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + +} diff --git a/docker.build b/docker.build new file mode 100644 index 000000000..82abc2f18 --- /dev/null +++ b/docker.build @@ -0,0 +1,3 @@ +#!/bin/bash +mvn package appassembler:assemble -PcheckstyleSkip -DskipTests + diff --git a/package.sh b/package.sh new file mode 100644 index 000000000..82abc2f18 --- /dev/null +++ b/package.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mvn package appassembler:assemble -PcheckstyleSkip -DskipTests + diff --git a/pom.xml b/pom.xml index 216c48631..6d8fb6a67 100644 --- a/pom.xml +++ b/pom.xml @@ -256,6 +256,42 @@ 4.12 test + + + + + org.apache.avro + avro-tools + 1.8.1 + + + + com.google.inject + guice + 4.1.0 + + + + + org.glassfish.jersey.containers + jersey-container-grizzly2-http + 2.22.2 + + + + org.glassfish.jersey.media + jersey-media-json-jettison + 2.22.2 + + + + org.glassfish.jersey.test-framework.providers + jersey-test-framework-provider-bundle + pom + test + 2.22.2 + + @@ -428,6 +464,21 @@ org.apache.maven.plugins maven-source-plugin + + + + org.codehaus.mojo + appassembler-maven-plugin + 1.10 + + + + pi.docker.RestApp + app + + + + @@ -463,6 +514,7 @@ + + org.codehaus.mojo findbugs-maven-plugin diff --git a/run.dockerfile b/run.dockerfile new file mode 100644 index 000000000..ae7017785 --- /dev/null +++ b/run.dockerfile @@ -0,0 +1,25 @@ +# VERSION 1.0 + +# the base image is a trusted ubuntu build with java 8 (https://index.docker.io/u/dockerfile/java/) +FROM openjdk:8-jre-alpine + +# that's me! +MAINTAINER Samlet Wu, xiaofei.wu@gmail.com + +# we need this because the workdir is modified in dockerfile/java +WORKDIR /app + +LABEL version="1.0" +LABEL description="docker meta service" + +# run the (java) server as the daemon user +# USER daemon + +# copy the locally built fat-jar to the image +ADD target/appassembler /app/appassembler + +# run the server when a container based on this image is being run +ENTRYPOINT [ "sh", "/app/appassembler/bin/app" ] + +# the server binds to 8080 - expose that port +EXPOSE 8080 diff --git a/src/main/java/com/neohope/avro/test/JustATest.java b/src/main/java/com/neohope/avro/test/JustATest.java new file mode 100644 index 000000000..a3cc3727d --- /dev/null +++ b/src/main/java/com/neohope/avro/test/JustATest.java @@ -0,0 +1,31 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package com.neohope.avro.test; + +@SuppressWarnings("all") +@org.apache.avro.specific.AvroGenerated +public interface JustATest { + public static final org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse("{\"protocol\":\"JustATest\",\"namespace\":\"com.neohope.avro.test\",\"types\":[{\"type\":\"record\",\"name\":\"Person\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"age\",\"type\":\"int\"},{\"name\":\"sex\",\"type\":\"string\"},{\"name\":\"address\",\"type\":\"string\"}]}],\"messages\":{\"SayHelloTo\":{\"request\":[{\"name\":\"person\",\"type\":\"Person\"}],\"response\":\"string\"},\"Add\":{\"request\":[{\"name\":\"a\",\"type\":\"int\"},{\"name\":\"b\",\"type\":\"int\"}],\"response\":\"int\"}}}"); + /** + */ + java.lang.CharSequence SayHelloTo(com.neohope.avro.test.Person person) throws org.apache.avro.AvroRemoteException; + /** + */ + int Add(int a, int b) throws org.apache.avro.AvroRemoteException; + + @SuppressWarnings("all") + public interface Callback extends JustATest { + public static final org.apache.avro.Protocol PROTOCOL = com.neohope.avro.test.JustATest.PROTOCOL; + /** + * @throws java.io.IOException The async call could not be completed. + */ + void SayHelloTo(com.neohope.avro.test.Person person, org.apache.avro.ipc.Callback callback) throws java.io.IOException; + /** + * @throws java.io.IOException The async call could not be completed. + */ + void Add(int a, int b, org.apache.avro.ipc.Callback callback) throws java.io.IOException; + } +} \ No newline at end of file diff --git a/src/main/java/com/neohope/avro/test/Person.java b/src/main/java/com/neohope/avro/test/Person.java new file mode 100644 index 000000000..ae3e59689 --- /dev/null +++ b/src/main/java/com/neohope/avro/test/Person.java @@ -0,0 +1,406 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package com.neohope.avro.test; + +import org.apache.avro.specific.SpecificData; + +@SuppressWarnings("all") +@org.apache.avro.specific.AvroGenerated +public class Person extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + private static final long serialVersionUID = 7080676715379256158L; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"com.neohope.avro.test\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"age\",\"type\":\"int\"},{\"name\":\"sex\",\"type\":\"string\"},{\"name\":\"address\",\"type\":\"string\"}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + @Deprecated public java.lang.CharSequence name; + @Deprecated public int age; + @Deprecated public java.lang.CharSequence sex; + @Deprecated public java.lang.CharSequence address; + + /** + * Default constructor. Note that this does not initialize fields + * to their default values from the schema. If that is desired then + * one should use newBuilder(). + */ + public Person() {} + + /** + * All-args constructor. + * @param name The new value for name + * @param age The new value for age + * @param sex The new value for sex + * @param address The new value for address + */ + public Person(java.lang.CharSequence name, java.lang.Integer age, java.lang.CharSequence sex, java.lang.CharSequence address) { + this.name = name; + this.age = age; + this.sex = sex; + this.address = address; + } + + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return name; + case 1: return age; + case 2: return sex; + case 3: return address; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: name = (java.lang.CharSequence)value$; break; + case 1: age = (java.lang.Integer)value$; break; + case 2: sex = (java.lang.CharSequence)value$; break; + case 3: address = (java.lang.CharSequence)value$; break; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'name' field. + * @return The value of the 'name' field. + */ + public java.lang.CharSequence getName() { + return name; + } + + /** + * Sets the value of the 'name' field. + * @param value the value to set. + */ + public void setName(java.lang.CharSequence value) { + this.name = value; + } + + /** + * Gets the value of the 'age' field. + * @return The value of the 'age' field. + */ + public java.lang.Integer getAge() { + return age; + } + + /** + * Sets the value of the 'age' field. + * @param value the value to set. + */ + public void setAge(java.lang.Integer value) { + this.age = value; + } + + /** + * Gets the value of the 'sex' field. + * @return The value of the 'sex' field. + */ + public java.lang.CharSequence getSex() { + return sex; + } + + /** + * Sets the value of the 'sex' field. + * @param value the value to set. + */ + public void setSex(java.lang.CharSequence value) { + this.sex = value; + } + + /** + * Gets the value of the 'address' field. + * @return The value of the 'address' field. + */ + public java.lang.CharSequence getAddress() { + return address; + } + + /** + * Sets the value of the 'address' field. + * @param value the value to set. + */ + public void setAddress(java.lang.CharSequence value) { + this.address = value; + } + + /** + * Creates a new Person RecordBuilder. + * @return A new Person RecordBuilder + */ + public static com.neohope.avro.test.Person.Builder newBuilder() { + return new com.neohope.avro.test.Person.Builder(); + } + + /** + * Creates a new Person RecordBuilder by copying an existing Builder. + * @param other The existing builder to copy. + * @return A new Person RecordBuilder + */ + public static com.neohope.avro.test.Person.Builder newBuilder(com.neohope.avro.test.Person.Builder other) { + return new com.neohope.avro.test.Person.Builder(other); + } + + /** + * Creates a new Person RecordBuilder by copying an existing Person instance. + * @param other The existing instance to copy. + * @return A new Person RecordBuilder + */ + public static com.neohope.avro.test.Person.Builder newBuilder(com.neohope.avro.test.Person other) { + return new com.neohope.avro.test.Person.Builder(other); + } + + /** + * RecordBuilder for Person instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private java.lang.CharSequence name; + private int age; + private java.lang.CharSequence sex; + private java.lang.CharSequence address; + + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$); + } + + /** + * Creates a Builder by copying an existing Builder. + * @param other The existing Builder to copy. + */ + private Builder(com.neohope.avro.test.Person.Builder other) { + super(other); + if (isValidValue(fields()[0], other.name)) { + this.name = data().deepCopy(fields()[0].schema(), other.name); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.age)) { + this.age = data().deepCopy(fields()[1].schema(), other.age); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.sex)) { + this.sex = data().deepCopy(fields()[2].schema(), other.sex); + fieldSetFlags()[2] = true; + } + if (isValidValue(fields()[3], other.address)) { + this.address = data().deepCopy(fields()[3].schema(), other.address); + fieldSetFlags()[3] = true; + } + } + + /** + * Creates a Builder by copying an existing Person instance + * @param other The existing instance to copy. + */ + private Builder(com.neohope.avro.test.Person other) { + super(SCHEMA$); + if (isValidValue(fields()[0], other.name)) { + this.name = data().deepCopy(fields()[0].schema(), other.name); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.age)) { + this.age = data().deepCopy(fields()[1].schema(), other.age); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.sex)) { + this.sex = data().deepCopy(fields()[2].schema(), other.sex); + fieldSetFlags()[2] = true; + } + if (isValidValue(fields()[3], other.address)) { + this.address = data().deepCopy(fields()[3].schema(), other.address); + fieldSetFlags()[3] = true; + } + } + + /** + * Gets the value of the 'name' field. + * @return The value. + */ + public java.lang.CharSequence getName() { + return name; + } + + /** + * Sets the value of the 'name' field. + * @param value The value of 'name'. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder setName(java.lang.CharSequence value) { + validate(fields()[0], value); + this.name = value; + fieldSetFlags()[0] = true; + return this; + } + + /** + * Checks whether the 'name' field has been set. + * @return True if the 'name' field has been set, false otherwise. + */ + public boolean hasName() { + return fieldSetFlags()[0]; + } + + + /** + * Clears the value of the 'name' field. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder clearName() { + name = null; + fieldSetFlags()[0] = false; + return this; + } + + /** + * Gets the value of the 'age' field. + * @return The value. + */ + public java.lang.Integer getAge() { + return age; + } + + /** + * Sets the value of the 'age' field. + * @param value The value of 'age'. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder setAge(int value) { + validate(fields()[1], value); + this.age = value; + fieldSetFlags()[1] = true; + return this; + } + + /** + * Checks whether the 'age' field has been set. + * @return True if the 'age' field has been set, false otherwise. + */ + public boolean hasAge() { + return fieldSetFlags()[1]; + } + + + /** + * Clears the value of the 'age' field. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder clearAge() { + fieldSetFlags()[1] = false; + return this; + } + + /** + * Gets the value of the 'sex' field. + * @return The value. + */ + public java.lang.CharSequence getSex() { + return sex; + } + + /** + * Sets the value of the 'sex' field. + * @param value The value of 'sex'. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder setSex(java.lang.CharSequence value) { + validate(fields()[2], value); + this.sex = value; + fieldSetFlags()[2] = true; + return this; + } + + /** + * Checks whether the 'sex' field has been set. + * @return True if the 'sex' field has been set, false otherwise. + */ + public boolean hasSex() { + return fieldSetFlags()[2]; + } + + + /** + * Clears the value of the 'sex' field. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder clearSex() { + sex = null; + fieldSetFlags()[2] = false; + return this; + } + + /** + * Gets the value of the 'address' field. + * @return The value. + */ + public java.lang.CharSequence getAddress() { + return address; + } + + /** + * Sets the value of the 'address' field. + * @param value The value of 'address'. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder setAddress(java.lang.CharSequence value) { + validate(fields()[3], value); + this.address = value; + fieldSetFlags()[3] = true; + return this; + } + + /** + * Checks whether the 'address' field has been set. + * @return True if the 'address' field has been set, false otherwise. + */ + public boolean hasAddress() { + return fieldSetFlags()[3]; + } + + + /** + * Clears the value of the 'address' field. + * @return This builder. + */ + public com.neohope.avro.test.Person.Builder clearAddress() { + address = null; + fieldSetFlags()[3] = false; + return this; + } + + @Override + public Person build() { + try { + Person record = new Person(); + record.name = fieldSetFlags()[0] ? this.name : (java.lang.CharSequence) defaultValue(fields()[0]); + record.age = fieldSetFlags()[1] ? this.age : (java.lang.Integer) defaultValue(fields()[1]); + record.sex = fieldSetFlags()[2] ? this.sex : (java.lang.CharSequence) defaultValue(fields()[2]); + record.address = fieldSetFlags()[3] ? this.address : (java.lang.CharSequence) defaultValue(fields()[3]); + return record; + } catch (Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } + + private static final org.apache.avro.io.DatumWriter + WRITER$ = new org.apache.avro.specific.SpecificDatumWriter(SCHEMA$); + + @Override public void writeExternal(java.io.ObjectOutput out) + throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + + private static final org.apache.avro.io.DatumReader + READER$ = new org.apache.avro.specific.SpecificDatumReader(SCHEMA$); + + @Override public void readExternal(java.io.ObjectInput in) + throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + +} diff --git a/src/main/java/pi/docker/AppModule.java b/src/main/java/pi/docker/AppModule.java new file mode 100644 index 000000000..4453503cf --- /dev/null +++ b/src/main/java/pi/docker/AppModule.java @@ -0,0 +1,32 @@ +package pi.docker; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Created by xiaofeiwu on 2016/12/1. + */ +public class AppModule { + private static AppModule instance = null; + private Injector injector; + protected AppModule() { + // Exists only to defeat instantiation. + injector= Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + + } + }); + } + public static AppModule getInstance() { + if(instance == null) { + instance = new AppModule(); + } + return instance; + } + + public static DockerImageMeta meta(){ + return getInstance().injector.getInstance(DockerImageMeta.class); + } +} diff --git a/src/main/java/pi/docker/AvroToolMain.java b/src/main/java/pi/docker/AvroToolMain.java new file mode 100644 index 000000000..124eed08e --- /dev/null +++ b/src/main/java/pi/docker/AvroToolMain.java @@ -0,0 +1,123 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package pi.docker; + +import org.apache.avro.tool.*; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.Map; +import java.util.TreeMap; + +/** Command-line driver.*/ +public class AvroToolMain { + /** + * Available tools, initialized in constructor. + */ + final Map tools; + + int maxLen = 0; + + AvroToolMain() { + tools = new TreeMap(); + for (Tool tool : new Tool[] { + new CatTool(), + new SpecificCompilerTool(), + new InduceSchemaTool(), + new JsonToBinaryFragmentTool(), + new BinaryFragmentToJsonTool(), + new CreateRandomFileTool(), + new DataFileReadTool(), + new DataFileWriteTool(), + new DataFileGetMetaTool(), + new DataFileGetSchemaTool(), + new DataFileRepairTool(), + new IdlTool(), + new IdlToSchemataTool(), + new RecodecTool(), + new ConcatTool(), + new RpcReceiveTool(), + new RpcSendTool(), + new RpcProtocolTool(), + new FromTextTool(), + new ToTextTool(), + new ToTrevniTool(), + new TetherTool(), + new TrevniCreateRandomTool(), + new TrevniMetadataTool(), + new TrevniToJsonTool() + }) { + Tool prev = tools.put(tool.getName(), tool); + if (prev != null) { + throw new AssertionError( + "Two tools with identical names: " + tool + ", " + prev); + } + maxLen = Math.max(tool.getName().length(), maxLen); + } + } + + public static void main(String[] args) throws Exception { + int rc = new AvroToolMain().run(args); + System.exit(rc); + } + + /** + * Delegates to tool specified on the command-line. + */ + private int run(String[] args) throws Exception { + if (args.length != 0) { + Tool tool = tools.get(args[0]); + if (tool != null) { + return tool.run( + System.in, System.out, System.err, Arrays.asList(args).subList(1, args.length)); + } + } + System.err.print("Version "); + printStream(Main.class.getClassLoader().getResourceAsStream("VERSION.txt")); + System.err.print(" of "); + printHead(Main.class.getClassLoader().getResourceAsStream("META-INF/NOTICE"), 5); + System.err.println("----------------"); + + System.err.println("Available tools:"); + for (Tool k : tools.values()) { + System.err.printf("%" + maxLen + "s %s\n", k.getName(), k.getShortDescription()); + } + + return 1; + } + + private static void printStream(InputStream in) throws Exception { + byte[] buffer = new byte[1024]; + for (int i = in.read(buffer); i != -1; i = in.read(buffer)) + System.err.write(buffer, 0, i); + } + + private static void printHead(InputStream in, int lines) throws Exception { + BufferedReader r = new BufferedReader(new InputStreamReader(in)); + for (int i = 0; i < lines; i++) { + String line = r.readLine(); + if (line == null) { + break; + } + System.err.println(line); + } + } + +} diff --git a/src/main/java/pi/docker/DockerImageMeta.java b/src/main/java/pi/docker/DockerImageMeta.java new file mode 100644 index 000000000..c6c09a3fe --- /dev/null +++ b/src/main/java/pi/docker/DockerImageMeta.java @@ -0,0 +1,131 @@ +package pi.docker; + +import avro.shaded.com.google.common.collect.Lists; +import com.github.dockerjava.api.DockerClient; +import com.github.dockerjava.api.command.DockerCmdExecFactory; +import com.github.dockerjava.api.command.InspectImageResponse; +import com.github.dockerjava.api.exception.NotFoundException; +import com.github.dockerjava.core.DefaultDockerClientConfig; +import com.github.dockerjava.core.DockerClientBuilder; +import com.github.dockerjava.core.command.PullImageResultCallback; +import org.apache.avro.tool.IdlTool; +import org.apache.avro.tool.Tool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Singleton; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * Created by xiaofeiwu on 2016/12/1. + */ +@Singleton +public class DockerImageMeta { + public static final Logger LOG = LoggerFactory.getLogger(DockerImageMeta.class); + private DockerClient dockerClient; + + DockerImageMeta(){ + LOG.info("Connecting to Docker server"); + DockerCmdExecFactory dockerCmdExecFactory= DockerClientBuilder.getDefaultDockerCmdExecFactory(); + dockerClient = DockerClientBuilder.getInstance(config()) + .withDockerCmdExecFactory(dockerCmdExecFactory) + .build(); + } + public int getLabels(InputStream in, PrintStream out, PrintStream err) throws Exception { + Tool tool = new IdlTool(); + List args = Lists.newArrayList(); + // tool.run(System.in, System.out, System.err, args); + return tool.run(in, out, err, args); + } + + public void checkImage(String imageName){ + try { + dockerClient.inspectImageCmd(imageName).exec(); //"busybox" + } catch (NotFoundException e) { + LOG.info("Pulling image '{}'", imageName); + // need to block until image is pulled completely + dockerClient.pullImageCmd(imageName).withTag("latest").exec(new PullImageResultCallback()).awaitSuccess(); + } + } + + /** + * Process service labels + * @param imageName + * @return return null if process fail or no packages definition + * @throws Exception + */ + public String processServiceLabels(String imageName) throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream err = new PrintStream(baos); + String ret= processServiceLabels(imageName, err); + if(ret==null) { + String content = new String(baos.toByteArray(), StandardCharsets.UTF_8); + LOG.error(content); + } + return ret; + } + + public String processServiceLabels(String imageName, PrintStream err) throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + int ret=processServiceLabels(imageName, ps, err); + if(ret==0) { + String content = new String(baos.toByteArray(), StandardCharsets.UTF_8); + return content; + } + return null; + } + + public int processServiceLabels(String imageName, PrintStream out, PrintStream err) throws Exception { + InspectImageResponse response=dockerClient.inspectImageCmd(imageName).exec(); // "scala_rest" + Map labels= response.getConfig().getLabels(); + + String packages=labels.get("packages"); + if(packages!=null){ + String serviceDefs=labels.get(packages); + if(serviceDefs!=null) { + serviceDefs="@namespace(\""+packages+"\")\n"+serviceDefs; + InputStream stream = new ByteArrayInputStream(serviceDefs.getBytes(StandardCharsets.UTF_8)); + return getLabels(stream, out, err); + } + } + + return -1; + } + + public void printVersionLabels(String imageName){ + InspectImageResponse response=dockerClient.inspectImageCmd(imageName).exec(); // "scala_rest" + Map labels= response.getConfig().getLabels(); + System.out.println(labels.get("version")); + System.out.println(labels.get("description")); + + System.out.println("other labels:"); + for (Map.Entry label:labels.entrySet()) { + System.out.format("%s = %s\n", label.getKey(),label.getValue()); + } + + } + private DefaultDockerClientConfig config() { + return config(null); + } + + protected DefaultDockerClientConfig config(String password) { + DefaultDockerClientConfig.Builder builder = DefaultDockerClientConfig.createDefaultConfigBuilder() + // .withRegistryUrl("https://index.docker.io/v1/"); + // .withDockerHost("unix:///var/run/docker.sock") + // docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock -p 2377:2375 \ + // bobrik/socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CLIENT:/var/run/docker.sock + // .withDockerHost("tcp://localhost:2377") + .withDockerHost("tcp://socat:2375") + .withDockerTlsVerify(false); + if (password != null) { + builder = builder.withRegistryPassword(password); + } + + return builder.build(); + } +} diff --git a/src/main/java/pi/docker/MetaServiceList.java b/src/main/java/pi/docker/MetaServiceList.java new file mode 100644 index 000000000..3cfa3f46a --- /dev/null +++ b/src/main/java/pi/docker/MetaServiceList.java @@ -0,0 +1,20 @@ +package pi.docker; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +/** + * Created by xiaofeiwu on 2016/12/1. + */ +@Path("/meta") +public class MetaServiceList { + @GET + @Path("images/{image}/") + @Produces({"application/json", "application/xml"}) + public String getItem(@PathParam("image") String image) throws Exception { + return AppModule.meta().processServiceLabels(image); + // return "[\""+image+"\"]"; + } +} diff --git a/src/main/java/pi/docker/RawList.java b/src/main/java/pi/docker/RawList.java new file mode 100644 index 000000000..147850f15 --- /dev/null +++ b/src/main/java/pi/docker/RawList.java @@ -0,0 +1,27 @@ +package pi.docker; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +/** + * Created by xiaofeiwu on 2016/12/1. + */ +@Path(value = "/raw") +public class RawList { + //+ + @GET + @Produces({"application/json", "application/xml"}) + public String getRawList() { + return "{\n" + + " \"type\" : \"record\",\n" + + " \"name\" : \"Person\",\n" + + " \"fields\" : [ {\n" + + " \"name\" : \"name\",\n" + + " \"type\" : \"string\"\n" + + " }"; + } + + + //+ +} diff --git a/src/main/java/pi/docker/RestApp.java b/src/main/java/pi/docker/RestApp.java new file mode 100644 index 000000000..63df704ca --- /dev/null +++ b/src/main/java/pi/docker/RestApp.java @@ -0,0 +1,89 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * http://glassfish.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package pi.docker; + +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.jettison.JettisonFeature; +import org.glassfish.jersey.server.ResourceConfig; + +import java.io.IOException; +import java.net.URI; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Utility class which can create {@link org.glassfish.jersey.server.ApplicationHandler} instance and provides support + * for running this sample from command line. + * + * @author Jakub Podlesak (jakub.podlesak at oracle.com) + * @author Marek Potociar (marek.potociar at oracle.com) + */ +public class RestApp { + + private static final URI BASE_URI = URI.create("http://0.0.0.0:8080/v1/"); + + public static void main(String[] args) { + try { + System.out.println("listen on http://0.0.0.0:8080/v1/"); + + final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp(), false); + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + @Override + public void run() { + server.shutdownNow(); + } + })); + server.start(); + + System.out.println(String.format("Application started.%nStop the application using CTRL+C")); + + Thread.currentThread().join(); + } catch (IOException | InterruptedException ex) { + Logger.getLogger(RestApp.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static ResourceConfig createApp() { + return new ResourceConfig() + .register(new JettisonFeature()) + .packages("pi.docker"); + } +} diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties new file mode 100644 index 000000000..b17329c19 --- /dev/null +++ b/src/main/resources/log4j.properties @@ -0,0 +1,4 @@ +log4j.rootLogger=debug, stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 000000000..63de3262b --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,20 @@ + + + + + %d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/pi/docker/DockerImageMetaTest.java b/src/test/java/pi/docker/DockerImageMetaTest.java new file mode 100644 index 000000000..24b42c7d9 --- /dev/null +++ b/src/test/java/pi/docker/DockerImageMetaTest.java @@ -0,0 +1,57 @@ +package pi.docker; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.Injector; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by xiaofeiwu on 2016/12/1. + */ +public class DockerImageMetaTest { + @Test + public void getLabels() throws Exception { + + } + + @Test + public void checkImage() throws Exception { + + } + + @Test + public void processServiceLabels() throws Exception { + Injector inject= Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + + } + }); + DockerImageMeta meta=inject.getInstance(DockerImageMeta.class); + meta.processServiceLabels("scala_rest", System.out, System.err); + + System.out.println("----------"); + System.out.println(meta.processServiceLabels("scala_rest")); + } + + @Test + public void config() throws Exception { + + } + + @Test + public void printVersionLabels() throws Exception { + Injector inject= Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + + } + }); + DockerImageMeta meta=inject.getInstance(DockerImageMeta.class); + meta.printVersionLabels("scala_rest"); + } + +} \ No newline at end of file diff --git a/src/test/java/pi/docker/DockerLabels.java b/src/test/java/pi/docker/DockerLabels.java new file mode 100644 index 000000000..1661bf74c --- /dev/null +++ b/src/test/java/pi/docker/DockerLabels.java @@ -0,0 +1,67 @@ +package pi.docker; + +import com.github.dockerjava.api.DockerClient; +import com.github.dockerjava.api.command.DockerCmdExecFactory; +import com.github.dockerjava.api.command.InspectImageResponse; +import com.github.dockerjava.api.exception.NotFoundException; +import com.github.dockerjava.core.DefaultDockerClientConfig; +import com.github.dockerjava.core.DockerClientBuilder; +import com.github.dockerjava.core.command.PullImageResultCallback; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +import static org.junit.Assert.assertNotNull; + +/** + * Created by xiaofeiwu on 2016/12/1. + */ +public class DockerLabels { + public static final Logger LOG = LoggerFactory.getLogger(DockerLabels.class); + protected DockerClient dockerClient; + @Test + public void testGetLabels(){ + LOG.info("Connecting to Docker server"); + DockerCmdExecFactory dockerCmdExecFactory= DockerClientBuilder.getDefaultDockerCmdExecFactory(); + dockerClient = DockerClientBuilder.getInstance(config()) + .withDockerCmdExecFactory(dockerCmdExecFactory) + .build(); + + try { + dockerClient.inspectImageCmd("busybox").exec(); + } catch (NotFoundException e) { + LOG.info("Pulling image 'busybox'"); + // need to block until image is pulled completely + dockerClient.pullImageCmd("busybox").withTag("latest").exec(new PullImageResultCallback()).awaitSuccess(); + } + + assertNotNull(dockerClient); + + // Get container info and check its roundtrip to ensure the consistency +// InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(container.getId()).exec(); +// assertEquals(containerInfo.getId(), container.getId()); + + InspectImageResponse response=dockerClient.inspectImageCmd("scala_rest").exec(); + Map labels= response.getConfig().getLabels(); + System.out.println(labels.get("version")); + System.out.println(labels.get("description")); + + } + private DefaultDockerClientConfig config() { + return config(null); + } + + protected DefaultDockerClientConfig config(String password) { + DefaultDockerClientConfig.Builder builder = DefaultDockerClientConfig.createDefaultConfigBuilder() + // .withRegistryUrl("https://index.docker.io/v1/"); + .withDockerHost("unix:///var/run/docker.sock") + .withDockerTlsVerify(false); + if (password != null) { + builder = builder.withRegistryPassword(password); + } + + return builder.build(); + } +} diff --git a/visit-docker.sh b/visit-docker.sh new file mode 100644 index 000000000..9615409f0 --- /dev/null +++ b/visit-docker.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# curl localhost:8080/v1/raw +curl localhost:8083/v1/meta/images/scala_rest + diff --git a/visit.sh b/visit.sh new file mode 100644 index 000000000..327937506 --- /dev/null +++ b/visit.sh @@ -0,0 +1,4 @@ +#!/bin/bash +curl localhost:8080/v1/raw +curl localhost:8080/v1/meta/images/scala_rest +