com.cloudbees.sdk.commands.db.DatabaseSet Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2010-2013, CloudBees 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.
*/
package com.cloudbees.sdk.commands.db;
import com.cloudbees.sdk.cli.BeesCommand;
import com.cloudbees.sdk.cli.CLICommand;
import java.util.HashMap;
import java.util.Map;
/**
* @author Fabian Donze
*/
@BeesCommand(group = "Database", description = "Set a database password or plan")
@CLICommand("db:set")
public class DatabaseSet extends DatabaseBase {
private String password;
private String plan;
public DatabaseSet() {
}
public void setPassword(String password) {
this.password = password;
}
public void setPlan(String plan) {
this.plan = plan;
}
@Override
protected boolean preParseCommandLine() {
// add the Options
addOption("p", "password", true, "The database password");
addOption("pl", "plan", true, "The database plan");
return true;
}
@Override
protected boolean postParseCheck() {
if (super.postParseCheck()) {
setDatabaseName(getParameters().get(0));
return true;
}
return false;
}
@Override
protected boolean execute() throws Exception {
String dbId = getDatabaseName();
DBClient client = getBeesClient(DBClient.class, dbId);
Map parameters = new HashMap();
if (password != null) parameters.put("password", password);
if (plan != null) parameters.put("plan", plan);
if (parameters.size() > 0) {
com.cloudbees.api.DatabaseInfo res = client.databaseUpdate(dbId, parameters);
if (isTextOutput())
displayDatabaseInfo(res, false);
else
printOutput(res, com.cloudbees.api.DatabaseInfo.class);
}
return true;
}
}