com.huawei.openstack4j.openstack.database.internal.DatabaseInstanceService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openstack4j Show documentation
Show all versions of openstack4j Show documentation
Huawei Cloud Open API SDK for Java
/*******************************************************************************
* 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.huawei.openstack4j.openstack.database.internal;
import java.util.HashMap;
import java.util.List;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.huawei.openstack4j.openstack.common.IdResourceEntity;
import com.huawei.openstack4j.openstack.database.domain.DatabaseInstance;
import com.huawei.openstack4j.openstack.database.domain.DatabaseInstanceCreate;
import com.huawei.openstack4j.openstack.database.domain.Volume;
import com.huawei.openstack4j.openstack.database.domain.DatabaseInstance.DatabaseInstances;
import com.huawei.openstack4j.openstack.trove.domain.ExtendParam;
/**
* The implementation of manipulation of {@link DatabaseInstance}
*
* @author QianBiao.NG
* @date 2017-07-31 11:13:41
*/
public class DatabaseInstanceService extends BaseDatabaseServices {
/**
* list all database instances
*
* @return a list of {@link DatabaseInstance} instances
*/
public List list() {
return get(DatabaseInstances.class, uri("/instances")).execute().getList();
}
/**
* get the detail of database instance
*
* @param instanceId database instance identifier
* @return {@link DatabaseInstance} instance
*/
public DatabaseInstance get(String instanceId) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(instanceId), "parameter `instanceId` should not be empty");
DatabaseInstance instance = get(DatabaseInstance.class, uri("/instances/%s", instanceId)).execute();
return instance;
}
/**
* create a new database instance (new instance or read only(replica) instance)
*
* @param creation a model represent the attributes of database instance creation
* @return {@link DatabaseInstance} instance
*/
public DatabaseInstance create(DatabaseInstanceCreate creation) {
Preconditions.checkNotNull(creation, "parameter `creation` should not be null");
Preconditions.checkArgument(!Strings.isNullOrEmpty(creation.getName()),
"parameter `creation.name` should not be empty");
Preconditions.checkNotNull(creation.getDatastore(), "parameter `creation.datastore` should not be empty");
Preconditions.checkArgument(!Strings.isNullOrEmpty(creation.getDatastore().getVersion()),
"parameter `creation.datastore.version` should not be empty");
Preconditions.checkNotNull(creation.getDatastore().getType(),
"parameter `creation.datastore.type` should not be empty");
Preconditions.checkArgument(!Strings.isNullOrEmpty(creation.getFlavorRef()),
"parameter `creation.flavorRef` should not be empty");
// fields below is not required by create replica instance
/**
Preconditions.checkArgument(!Strings.isNullOrEmpty(creation.getRegion()),
"parameter `creation.region` should not be empty");
Preconditions.checkArgument(!Strings.isNullOrEmpty(creation.getAvailabilityZone()),
"parameter `creation.availabilityZone` should not be empty");
Preconditions.checkArgument(!Strings.isNullOrEmpty(creation.getVpcId()),
"parameter `creation.vpcId` should not be empty");
Preconditions.checkArgument(!Strings.isNullOrEmpty(creation.getRootPassword()),
"parameter `creation.rootPassword` should not be empty");
Preconditions.checkArgument(
creation.getSecurityGroup() != null && !Strings.isNullOrEmpty(creation.getSecurityGroup().getId()),
"parameter `creation.securityGroup.id` should not be empty");
Preconditions.checkArgument(
creation.getNic() != null && !Strings.isNullOrEmpty(creation.getNic().getSubnetId()),
"parameter `creation.nic.subnetId` should not be empty");
Preconditions.checkArgument(creation.getVolume() != null, "parameter `creation.volume` should not be null");
Preconditions.checkArgument(creation.getVolume().getSize() != null,
"parameter `creation.volume.size` should not be null");
*/
return post(DatabaseInstance.class, uri("/instances")).entity(creation).execute();
}
/**
* delete a database instance
* @param instanceId database instance identifier
* @return asynchronous job id of the database deletion job
*/
public String delete(String instanceId) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(instanceId), "parameter `instanceId` should not be empty");
HashMap