forked from thaingo/java-membase-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mike Wiederhold
committed
Mar 28, 2011
0 parents
commit 040030e
Showing
13 changed files
with
651 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"/> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains 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,6 @@ | ||
*~ | ||
/bin | ||
/build | ||
/doc | ||
/target | ||
.DS_Store |
This file contains 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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>java-membase-installer</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.maven.ide.eclipse.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.maven.ide.eclipse.maven2Nature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains 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,13 @@ | ||
#Wed Mar 23 17:09:55 PDT 2011 | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.6 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.6 |
This file contains 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,8 @@ | ||
#Wed Mar 23 17:09:55 PDT 2011 | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
fullBuildGoals=process-test-resources | ||
resolveWorkspaceProjects=true | ||
resourceFilterGoals=process-resources resources\:testResources | ||
skipCompilerPlugin=true | ||
version=1 |
Binary file not shown.
This file contains 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,61 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<!-- | ||
Copyright 2011 Membase, Inc. | ||
Licensed 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. | ||
--> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.membase</groupId> | ||
<artifactId>java-membase-installer</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>java-membase-installer</name> | ||
<url>http://maven.apache.org</url> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.0.2</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.jcraft</groupId> | ||
<artifactId>jsch</artifactId> | ||
<version>0.1.42</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.6.1</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>1.6.1</version> | ||
<type>jar</type> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains 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,189 @@ | ||
package com.couchbase.install; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.couchbase.install.exception.InstallFailedException; | ||
import com.couchbase.install.exception.SSHException; | ||
import com.couchbase.install.exception.UninstallFailedException; | ||
import com.couchbase.install.internal.CouchbaseSCP; | ||
import com.couchbase.install.internal.CouchbaseSSH; | ||
|
||
public class Installer { | ||
private static final Logger LOG = LoggerFactory.getLogger(Installer.class); | ||
private static final String WLOC = "http://builds.hq.northscale.net/releases/1.6.5/"; | ||
private static final String LLOC = "http://builds.hq.northscale.net/latestbuilds/"; | ||
private String user; | ||
private String pass; | ||
private String host; | ||
private String sVersion; | ||
private String mVersion; | ||
|
||
|
||
public Installer(String user, String pass, String host, String sVersion, String mVersion) { | ||
this.user = user; | ||
this.pass = pass; | ||
this.host = host; | ||
this.sVersion = sVersion; | ||
this.mVersion = mVersion; | ||
} | ||
|
||
public void installMoxi() throws InstallFailedException { | ||
try { | ||
CouchbaseSSH ssh = new CouchbaseSSH(user, pass, host); | ||
ssh.docommand("rm -rf " + sVersion + "*"); | ||
if (!ssh.docommand("wget " + LLOC + mVersion).contains("`" + mVersion + "' saved")) { | ||
ssh.docommand("rm -rf " + mVersion + "*"); | ||
ssh.closeSession(); | ||
throw new InstallFailedException("Unable to download Moxi: Bad version"); | ||
} | ||
if (sVersion.endsWith(".deb")) { | ||
if (!ssh.docommand("dpkg -i " + mVersion).contains("Setting up moxi-server")) { | ||
ssh.docommand("rm -rf " + mVersion + "*"); | ||
ssh.closeSession(); | ||
throw new InstallFailedException("Debian install failed on host: " + host); | ||
} | ||
} else if (sVersion.endsWith(".rpm")) { | ||
if (!ssh.docommand("rpm -i " + mVersion).contains("You have successfully installed Moxi Server.")) { | ||
ssh.docommand("rm -rf " + mVersion + "*"); | ||
ssh.closeSession(); | ||
throw new InstallFailedException("RedHat install failed on host: " + host); | ||
} | ||
} else if (mVersion.endsWith(".exe")) { | ||
ssh.closeSession(); | ||
throw new InstallFailedException("Windows installation not currently supported"); | ||
} else { | ||
ssh.closeSession(); | ||
throw new InstallFailedException("Error installing" + sVersion + " on " + host + ". Doesn't appear to be linux package"); | ||
} | ||
ssh.docommand("rm -rf " + mVersion + "*"); | ||
ssh.closeSession(); | ||
} catch (SSHException e) { | ||
throw new InstallFailedException(); | ||
} | ||
} | ||
|
||
public void installClient() throws InstallFailedException { | ||
CouchbaseSSH ssh = null; | ||
CouchbaseSCP scp = null; | ||
try { | ||
ssh = new CouchbaseSSH(user, pass, host); | ||
scp = new CouchbaseSCP(user, pass, host); | ||
scp.doSCP("distributed_loadgen.tar.gz", "distributed_loadgen.tar.gz"); | ||
ssh.docommand("tar xf distributed_loadgen.tar.gz"); | ||
ssh.docommand("rm -f distributed_loadgen.tar.gz"); | ||
if (!ssh.docommand("cd distributed_loadgen; ant;").contains("BUILD SUCCESSFUL")) { | ||
ssh.closeSession(); | ||
throw new InstallFailedException("Load Generator didn't compile correctly on " + host); | ||
} | ||
ssh.docommand("cd distributed_loadgen; ant run > /dev/null &"); | ||
} catch (SSHException e) { | ||
throw new InstallFailedException("Couldn't create ssh session with " + host); | ||
} finally { | ||
if (scp != null) { | ||
scp.closeSession(); | ||
} | ||
if (ssh != null) { | ||
ssh.closeSession(); | ||
} | ||
} | ||
} | ||
|
||
public void installServer() throws InstallFailedException { | ||
CouchbaseSSH ssh = null; | ||
try { | ||
ssh = new CouchbaseSSH(user, pass, host); | ||
ssh.docommand("rm -rf " + sVersion + "*"); | ||
if (!ssh.docommand("wget " + WLOC + sVersion).contains("`" + sVersion + "' saved")) { | ||
ssh.docommand("rm -rf " + sVersion + "*"); | ||
ssh.closeSession(); | ||
throw new InstallFailedException("Unable to download Membase: Bad version"); | ||
} | ||
|
||
if (sVersion.endsWith(".deb")) { | ||
if (!ssh.docommand("dpkg -i " + sVersion).contains("* Started Membase server")) { | ||
ssh.docommand("rm -rf " + sVersion + "*"); | ||
ssh.closeSession(); | ||
throw new InstallFailedException("Debian install failed on host: " + host); | ||
} | ||
} else if (sVersion.endsWith(".rpm")) { | ||
if (!ssh.docommand("rpm -i " + sVersion).contains("You have successfully installed Membase Server.")) { | ||
ssh.docommand("rm -rf " + sVersion + "*"); | ||
ssh.closeSession(); | ||
throw new InstallFailedException("RedHat install failed on host: " + host); | ||
} | ||
} else if (sVersion.endsWith(".exe")) { | ||
ssh.closeSession(); | ||
throw new InstallFailedException("Windows installation not currently supported"); | ||
} else { | ||
ssh.closeSession(); | ||
throw new InstallFailedException("Error installing" + sVersion + " on " + host + ". Doesn't appear to be linux package"); | ||
} | ||
ssh.docommand("rm -rf " + sVersion + "*"); | ||
ssh.closeSession(); | ||
} catch (SSHException e) { | ||
throw new InstallFailedException(); | ||
} finally { | ||
if (ssh != null) { | ||
ssh.closeSession(); | ||
} | ||
} | ||
} | ||
|
||
public void uninstallLinux() throws UninstallFailedException{ | ||
CouchbaseSSH ssh; | ||
try { | ||
ssh = new CouchbaseSSH(user, pass, host); | ||
} catch (SSHException e) { | ||
throw new UninstallFailedException(); | ||
} | ||
if (sVersion.endsWith(".deb")) { | ||
ssh.docommand("dpkg -r membase-server"); | ||
} else if (sVersion.endsWith(".rpm")) { | ||
ssh.docommand("rpm -e membase-server"); | ||
} else if (sVersion.endsWith(".exe")) { | ||
LOG.info("No Windows uninstall support"); | ||
} | ||
ssh.docommand("rm -rf /var/opt/membase"); | ||
ssh.docommand("rm -rf /etc/opt/membase"); | ||
ssh.docommand("rm -rf /opt/membase*"); | ||
ssh.closeSession(); | ||
} | ||
|
||
public void uninstallClient() throws UninstallFailedException{ | ||
CouchbaseSSH ssh; | ||
try { | ||
ssh = new CouchbaseSSH(user, pass, host); | ||
} catch (SSHException e) { | ||
throw new UninstallFailedException(); | ||
} ssh.docommand("pkill java"); | ||
ssh.docommand("rm -rf distributed_loadgen"); | ||
ssh.closeSession(); | ||
} | ||
|
||
public void uninstallMoxi() throws UninstallFailedException{ | ||
CouchbaseSSH ssh; | ||
try { | ||
ssh = new CouchbaseSSH(user, pass, host); | ||
} catch (SSHException e) { | ||
throw new UninstallFailedException(); | ||
} if (sVersion.endsWith(".deb")) { | ||
ssh.docommand("dpkg -r moxi-server"); | ||
} else if (sVersion.endsWith(".rpm")) { | ||
ssh.docommand("rpm -e moxi-server"); | ||
} else if (sVersion.endsWith(".exe")) { | ||
LOG.info("No Windows uninstall support"); | ||
} | ||
ssh.closeSession(); | ||
} | ||
|
||
public static void main(String args[]) { | ||
Installer installer = new Installer("root", "northscale!23", "10.2.1.54", "membase-server-enterprise_x86_64_1.6.5.deb", "moxi-server_x86_64.deb"); | ||
try { | ||
installer.installMoxi(); | ||
} catch (InstallFailedException e) { | ||
System.out.println("Install failed: " + e.getMessage()); | ||
} | ||
//installer.uninstallMoxi(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/couchbase/install/exception/InstallFailedException.java
This file contains 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,13 @@ | ||
package com.couchbase.install.exception; | ||
|
||
public class InstallFailedException extends Exception { | ||
private static final long serialVersionUID = 1612092419020233049L; | ||
|
||
public InstallFailedException() { | ||
super(); | ||
} | ||
|
||
public InstallFailedException(String message) { | ||
super(message); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/couchbase/install/exception/SSHException.java
This file contains 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,13 @@ | ||
package com.couchbase.install.exception; | ||
|
||
public class SSHException extends Exception { | ||
private static final long serialVersionUID = 1255733856909878467L; | ||
|
||
public SSHException() { | ||
super(); | ||
} | ||
|
||
public SSHException(String message) { | ||
super(message); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/couchbase/install/exception/UninstallFailedException.java
This file contains 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,13 @@ | ||
package com.couchbase.install.exception; | ||
|
||
public class UninstallFailedException extends Exception{ | ||
private static final long serialVersionUID = 545587689544294224L; | ||
|
||
public UninstallFailedException() { | ||
super(); | ||
} | ||
|
||
public UninstallFailedException(String message) { | ||
super(message); | ||
} | ||
} |
Oops, something went wrong.