This repository was archived by the owner on Jul 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
[JCLOUDS-1007] Implemented Docker Exec support in MiscApi #205
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 org.jclouds.docker.domain; | ||
|
||
import org.jclouds.json.SerializedNames; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
/** | ||
* Represents a response from Exec Create call (<code>POST /containers/(id)/exec</code>). | ||
*/ | ||
@AutoValue | ||
public abstract class Exec { | ||
|
||
public abstract String id(); | ||
|
||
@SerializedNames({ "Id"}) | ||
public static Exec create(String id) { | ||
return new AutoValue_Exec(id); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
docker/src/main/java/org/jclouds/docker/domain/ExecCreateParams.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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 org.jclouds.docker.domain; | ||
|
||
import static org.jclouds.docker.internal.NullSafeCopies.copyOf; | ||
|
||
import java.util.List; | ||
|
||
import org.jclouds.json.SerializedNames; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
/** | ||
* Json Parameters (some of them) of Exec Create call. | ||
*/ | ||
@AutoValue | ||
public abstract class ExecCreateParams { | ||
|
||
public abstract boolean attachStdout(); | ||
|
||
public abstract boolean attachStderr(); | ||
|
||
public abstract List<String> cmd(); | ||
|
||
@SerializedNames({ "AttachStdout", "AttachStderr", "Cmd" }) | ||
private static ExecCreateParams create(boolean attachStdout, boolean attachStderr, List<String> cmd) { | ||
return builder().attachStdout(attachStdout).attachStderr(attachStderr).cmd(cmd).build(); | ||
} | ||
|
||
/** | ||
* Creates builder for {@link ExecCreateParams}, it sets | ||
* {@link #attachStderr()} and {@link #attachStdout()} to true as a default. | ||
* | ||
* @return new {@link ExecCreateParams.Builder} instance | ||
*/ | ||
public static Builder builder() { | ||
return new AutoValue_ExecCreateParams.Builder().attachStderr(true).attachStdout(true); | ||
} | ||
|
||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
|
||
public abstract Builder attachStdout(boolean b); | ||
|
||
public abstract Builder attachStderr(boolean b); | ||
|
||
public abstract Builder cmd(List<String> cmd); | ||
|
||
abstract List<String> cmd(); | ||
|
||
abstract ExecCreateParams autoBuild(); | ||
|
||
public ExecCreateParams build() { | ||
cmd(copyOf(cmd())); | ||
return autoBuild(); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
docker/src/main/java/org/jclouds/docker/domain/ExecInspect.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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 org.jclouds.docker.domain; | ||
|
||
import org.jclouds.json.SerializedNames; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
/** | ||
* Represents a response (part of it) from Exec Inspect call ( | ||
* <code>GET /exec/(id)/json</code>). | ||
*/ | ||
@AutoValue | ||
public abstract class ExecInspect { | ||
|
||
public abstract String id(); | ||
|
||
public abstract boolean running(); | ||
|
||
public abstract int exitCode(); | ||
|
||
@SerializedNames({ "ID", "Running", "ExitCode"}) | ||
public static ExecInspect create(String id, boolean running, int exitCode) { | ||
return new AutoValue_ExecInspect(id, running, exitCode); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
docker/src/main/java/org/jclouds/docker/domain/ExecStartParams.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 org.jclouds.docker.domain; | ||
|
||
import org.jclouds.json.SerializedNames; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
/** | ||
* Json Parameter(s) (some of them) of Exec Start call. | ||
*/ | ||
@AutoValue | ||
public abstract class ExecStartParams { | ||
|
||
public abstract boolean detach(); | ||
|
||
@SerializedNames({ "Detach" }) | ||
public static ExecStartParams create(boolean detach) { | ||
return builder().detach(detach).build(); | ||
} | ||
|
||
public static Builder builder() { | ||
return new AutoValue_ExecStartParams.Builder().detach(false); | ||
} | ||
|
||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
|
||
public abstract Builder detach(boolean b); | ||
|
||
public abstract ExecStartParams build(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
docker/src/main/java/org/jclouds/docker/util/DockerInputStream.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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 org.jclouds.docker.util; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* Extension to {@link DataInputStream} which adds method | ||
* {@link #readStdStreamData()} to allow read multiplexed standard streams. | ||
*/ | ||
public final class DockerInputStream extends DataInputStream { | ||
|
||
/** | ||
* Ctor from superclass. | ||
* | ||
* @param in | ||
* @see DataInputStream#DataInputStream(InputStream) | ||
*/ | ||
public DockerInputStream(InputStream in) { | ||
super(in); | ||
} | ||
|
||
/** | ||
* @return {@link StdStreamData} instance read from the input stream or | ||
* <code>null</code> if we reached end of the stream. | ||
* @throws IOException | ||
*/ | ||
public StdStreamData readStdStreamData() throws IOException { | ||
byte[] header = new byte[8]; | ||
// try to read first byte from the message header - just to check if we | ||
// are at the end | ||
// of stream | ||
if (-1 == read(header, 0, 1)) { | ||
return null; | ||
} | ||
// read the rest of the header | ||
readFully(header, 1, 7); | ||
// decode size as an unsigned int | ||
long size = (long) (header[4] & 0xFF) << 24 | (header[5] & 0xFF) << 16 | (header[6] & 0xFF) << 8 | ||
| (header[7] & 0xFF); | ||
|
||
byte[] payload; | ||
// The size from the header is an unsigned int so it can happen the byte | ||
// array has not a sufficient size and we'll have to truncate the frame | ||
payload = new byte[(int) Math.min(Integer.MAX_VALUE, size)]; | ||
readFully(payload); | ||
boolean truncated = false; | ||
if (size > Integer.MAX_VALUE) { | ||
truncated = true; | ||
// skip the rest | ||
readFully(new byte[(int) (size - Integer.MAX_VALUE)]); | ||
} | ||
return new StdStreamData(header[0], payload, truncated); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some domain classes have builders, some not. Should we remove all the builders, given that these classes are pretty simple, for consistency?