mirror of
https://github.com/apache/jclouds.git
synced 2026-08-31 16:34:32 +00:00
removed deprecated methods which were easy to do
This commit is contained in:
@@ -1,182 +0,0 @@
|
||||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.scriptbuilder;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.createRunScript;
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.interpret;
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.kill;
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.newStatementList;
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.switchArg;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.scriptbuilder.domain.CreateRunScript;
|
||||
import org.jclouds.scriptbuilder.domain.Statement;
|
||||
import org.jclouds.scriptbuilder.domain.StatementList;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* will be removed in jclouds 1.6
|
||||
*
|
||||
* Creates an init script file
|
||||
*
|
||||
* @see InitScript
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Deprecated
|
||||
public class InitBuilder extends ScriptBuilder {
|
||||
|
||||
private final String instanceName;
|
||||
private final String instanceHome;
|
||||
private final String logDir;
|
||||
private final StatementList initStatement;
|
||||
private final CreateRunScript createRunScript;
|
||||
|
||||
public InitBuilder(String instanceName, Statement initStatement, Statement runStatement) {
|
||||
this(instanceName, ImmutableSet.of(initStatement), ImmutableSet.of(runStatement));
|
||||
}
|
||||
|
||||
public InitBuilder(String instanceName, Iterable<Statement> initStatements, Iterable<Statement> statements) {
|
||||
this(instanceName, String.format("{tmp}{fs}{varl}INSTANCE_NAME{varr}", instanceName), String.format(
|
||||
"{tmp}{fs}{varl}INSTANCE_NAME{varr}", instanceName), ImmutableMap.<String, String> of(), initStatements,
|
||||
statements);
|
||||
}
|
||||
|
||||
public InitBuilder(String instanceName, String instanceHome, String logDir, Map<String, String> variables,
|
||||
Iterable<Statement> statements) {
|
||||
this(instanceName, instanceHome, logDir, variables, ImmutableSet.<Statement> of(), statements);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param variables keys are the variables to export in UPPER_UNDERSCORE case format
|
||||
*/
|
||||
public InitBuilder(String instanceName, String instanceHome, String logDir, Map<String, String> variables,
|
||||
Iterable<Statement> initStatements, Iterable<Statement> statements) {
|
||||
Map<String, String> defaultVariables = ImmutableMap.of("INSTANCE_NAME", instanceName, "INSTANCE_HOME",
|
||||
instanceHome, "LOG_DIR", logDir);
|
||||
this.initStatement = new StatementList(initStatements);
|
||||
this.createRunScript = createRunScript(instanceName,// TODO: convert
|
||||
// so
|
||||
// that
|
||||
// createRunScript
|
||||
// can take from a
|
||||
// variable
|
||||
Iterables.concat(variables.keySet(), defaultVariables.keySet()), "{varl}INSTANCE_HOME{varr}", statements);
|
||||
this.instanceName = checkNotNull(instanceName, "INSTANCE_NAME");
|
||||
this.instanceHome = checkNotNull(instanceHome, "INSTANCE_HOME");
|
||||
this.logDir = checkNotNull(logDir, "LOG_DIR");
|
||||
|
||||
addEnvironmentVariableScope("default", defaultVariables)
|
||||
.addEnvironmentVariableScope(instanceName, variables)
|
||||
.addStatement(
|
||||
switchArg(
|
||||
1,
|
||||
new ImmutableMap.Builder<String, Statement>()
|
||||
.put("init",
|
||||
newStatementList(call("default"), call(instanceName), initStatement,
|
||||
createRunScript))
|
||||
.put("status",
|
||||
newStatementList(call("default"), findPid("{varl}INSTANCE_NAME{varr}"),
|
||||
interpret("echo {varl}FOUND_PID{varr}{lf}")))
|
||||
.put("stop",
|
||||
newStatementList(call("default"), findPid("{varl}INSTANCE_NAME{varr}"), kill()))
|
||||
.put("start",
|
||||
newStatementList(
|
||||
call("default"),
|
||||
forget("{varl}INSTANCE_NAME{varr}",
|
||||
"{varl}INSTANCE_HOME{varr}{fs}{varl}INSTANCE_NAME{varr}.{sh}",
|
||||
"{varl}LOG_DIR{varr}")))
|
||||
.put("tail",
|
||||
newStatementList(call("default"),
|
||||
interpret("tail {varl}LOG_DIR{varr}{fs}stdout.log{lf}")))
|
||||
.put("tailerr",
|
||||
newStatementList(call("default"),
|
||||
interpret("tail {varl}LOG_DIR{varr}{fs}stderr.log{lf}")))
|
||||
.put("run",
|
||||
newStatementList(call("default"),
|
||||
interpret("{varl}INSTANCE_HOME{varr}{fs}{varl}INSTANCE_NAME{varr}.{sh}{lf}")))
|
||||
.build()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((instanceHome == null) ? 0 : instanceHome.hashCode());
|
||||
result = prime * result + ((instanceName == null) ? 0 : instanceName.hashCode());
|
||||
result = prime * result + ((logDir == null) ? 0 : logDir.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
InitBuilder other = (InitBuilder) obj;
|
||||
if (instanceHome == null) {
|
||||
if (other.instanceHome != null)
|
||||
return false;
|
||||
} else if (!instanceHome.equals(other.instanceHome))
|
||||
return false;
|
||||
if (instanceName == null) {
|
||||
if (other.instanceName != null)
|
||||
return false;
|
||||
} else if (!instanceName.equals(other.instanceName))
|
||||
return false;
|
||||
if (logDir == null) {
|
||||
if (other.logDir != null)
|
||||
return false;
|
||||
} else if (!logDir.equals(other.logDir))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getInstanceName() {
|
||||
return instanceName;
|
||||
}
|
||||
|
||||
public String getInstanceHome() {
|
||||
return instanceHome;
|
||||
}
|
||||
|
||||
public String getLogDir() {
|
||||
return logDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[instanceName=" + instanceName + ", instanceHome=" + instanceHome + ", logDir=" + logDir + "]";
|
||||
}
|
||||
|
||||
public StatementList getInitStatement() {
|
||||
return initStatement;
|
||||
}
|
||||
|
||||
public CreateRunScript getCreateRunScript() {
|
||||
return createRunScript;
|
||||
}
|
||||
}
|
||||
@@ -31,23 +31,11 @@ import org.jclouds.scriptbuilder.domain.StatementList;
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class InstallJDK {
|
||||
// TODO: this doesn't work
|
||||
public static Statement fromOracle() {
|
||||
throw new UnsupportedOperationException("Oracle JDK install doesn't currently work due to license agreement");
|
||||
}
|
||||
|
||||
public static Statement fromOpenJDK() {
|
||||
return new FromOpenJDK();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see fromOpenJDK
|
||||
*/
|
||||
@Deprecated
|
||||
public static Statement fromURL() {
|
||||
return fromOpenJDK();
|
||||
}
|
||||
|
||||
public static Statement fromURL(URI url) {
|
||||
return new FromURL(url);
|
||||
}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.scriptbuilder;
|
||||
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.appendFile;
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.exec;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||
import org.jclouds.scriptbuilder.domain.ShellToken;
|
||||
import org.jclouds.scriptbuilder.domain.Statement;
|
||||
import org.jclouds.scriptbuilder.domain.Statements;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
/**
|
||||
* Tests possible uses of InitBuilder
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Deprecated
|
||||
public class InitBuilderTest {
|
||||
|
||||
InitBuilder testInitBuilder = new InitBuilder("mkebsboot", "/mnt/tmp", "/mnt/tmp", ImmutableMap.of("TMP_DIR",
|
||||
"/mnt/tmp"), ImmutableList.<Statement> of(
|
||||
appendFile("{tmp}{fs}{uid}{fs}scripttest{fs}temp.txt", ImmutableList.<String> of("hello world")),
|
||||
exec("find /")));
|
||||
|
||||
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||
public void testBuildSimpleWindows() throws MalformedURLException, IOException {
|
||||
testInitBuilder.render(OsFamily.WINDOWS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildSimpleUNIX() throws MalformedURLException, IOException {
|
||||
assertEquals(
|
||||
testInitBuilder.render(OsFamily.UNIX),
|
||||
Resources.toString(Resources.getResource("test_init." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildEBS() throws MalformedURLException, IOException {
|
||||
assertEquals(
|
||||
new InitBuilder("mkebsboot",// name of the script
|
||||
"/tmp",// working directory
|
||||
"/tmp/logs",// location of stdout.log and stderr.log
|
||||
ImmutableMap.of("IMAGE_DIR", "/mnt/tmp", "EBS_DEVICE", "/dev/sdh", "EBS_MOUNT_POINT", "/mnt/ebs"),// variables
|
||||
// used
|
||||
// inside
|
||||
// of
|
||||
// the
|
||||
// script
|
||||
ImmutableList.<Statement> of(Statements
|
||||
.interpret(
|
||||
"echo creating a filesystem and mounting the ebs volume",// what
|
||||
// to
|
||||
// execute
|
||||
"{md} {varl}IMAGE_DIR{varr} {varl}EBS_MOUNT_POINT{varr}",
|
||||
"rm -rf {varl}IMAGE_DIR{varr}/*",
|
||||
"yes| mkfs -t ext3 {varl}EBS_DEVICE{varr} 2>&-",
|
||||
"mount {varl}EBS_DEVICE{varr} {varl}EBS_MOUNT_POINT{varr}",
|
||||
"echo making a local working copy of the boot disk",
|
||||
"rsync -ax --exclude /ubuntu/.bash_history --exclude /home/*/.bash_history --exclude /etc/ssh/ssh_host_* --exclude /etc/ssh/moduli --exclude /etc/udev/rules.d/*persistent-net.rules --exclude /var/lib/ec2/* --exclude=/mnt/* --exclude=/proc/* --exclude=/tmp/* --exclude=/dev/log / {varl}IMAGE_DIR{varr}",
|
||||
"echo preparing the local working copy",
|
||||
"touch {varl}IMAGE_DIR{varr}/etc/init.d/ec2-init-user-data",
|
||||
"echo copying the local working copy to the ebs mount", "{cd} {varl}IMAGE_DIR{varr}",
|
||||
"tar -cSf - * | tar xf - -C {varl}EBS_MOUNT_POINT{varr}", "echo size of ebs",
|
||||
"du -sk {varl}EBS_MOUNT_POINT{varr}", "echo size of source",
|
||||
"du -sk {varl}IMAGE_DIR{varr}", "rm -rf {varl}IMAGE_DIR{varr}/*",
|
||||
"umount {varl}EBS_MOUNT_POINT{varr}", "echo ----COMPLETE----"))).render(OsFamily.UNIX),
|
||||
Resources.toString(Resources.getResource("test_ebs." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user