com.huawei.openstack4j.openstack.storage.block.internal.BlockVolumeServiceImpl 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
/*******************************************************************************
* Copyright 2016 ContainX and OpenStack4j
*
* 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.
*******************************************************************************/
/*******************************************************************************
* Huawei has modified this source file.
* Copyright 2019 Huawei Technologies Co.,Ltd.
*
* 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.storage.block.internal;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.huawei.openstack4j.api.Apis;
import com.huawei.openstack4j.api.Builders;
import com.huawei.openstack4j.api.storage.BlockVolumeService;
import com.huawei.openstack4j.api.storage.BlockVolumeTransferService;
import com.huawei.openstack4j.model.common.ActionResponse;
import com.huawei.openstack4j.model.storage.block.Volume;
import com.huawei.openstack4j.model.storage.block.VolumeType;
import com.huawei.openstack4j.model.storage.block.VolumeUploadImage;
import com.huawei.openstack4j.model.storage.block.options.UploadImageData;
import com.huawei.openstack4j.openstack.storage.block.domain.AttachAction;
import com.huawei.openstack4j.openstack.storage.block.domain.CinderUploadImageData;
import com.huawei.openstack4j.openstack.storage.block.domain.CinderVolume;
import com.huawei.openstack4j.openstack.storage.block.domain.CinderVolume.Volumes;
import com.huawei.openstack4j.openstack.storage.block.domain.CinderVolumeMigration;
import com.huawei.openstack4j.openstack.storage.block.domain.CinderVolumeType;
import com.huawei.openstack4j.openstack.storage.block.domain.CinderVolumeType.VolumeTypes;
import com.huawei.openstack4j.openstack.storage.block.domain.CinderVolumeUpdate;
import com.huawei.openstack4j.openstack.storage.block.domain.CinderVolumeUploadImage;
import com.huawei.openstack4j.openstack.storage.block.domain.CinderVolumesResponse;
import com.huawei.openstack4j.openstack.storage.block.domain.ExtendAction;
import com.huawei.openstack4j.openstack.storage.block.domain.Extension;
import com.huawei.openstack4j.openstack.storage.block.domain.ForceDeleteAction;
import com.huawei.openstack4j.openstack.storage.block.domain.ForceDetachAction;
import com.huawei.openstack4j.openstack.storage.block.domain.ForceDetachConnector;
import com.huawei.openstack4j.openstack.storage.block.domain.ResetStatusAction;
import com.huawei.openstack4j.openstack.storage.block.domain.UpdateReadOnlyFlagAction;
import com.huawei.openstack4j.openstack.storage.block.domain.Version;
import com.huawei.openstack4j.openstack.storage.block.domain.VolumeMeta;
import com.huawei.openstack4j.openstack.storage.block.domain.VolumeMetadata;
/**
* Manages Volumes and Volume Type based operations against Block Storage (Cinder)
*
* @author Jeremy Unruh
*/
public class BlockVolumeServiceImpl extends BaseBlockStorageServices implements BlockVolumeService {
/**
* {@inheritDoc}
*/
@Override
public List extends VolumeType> listVolumeTypes() {
return get(VolumeTypes.class, uri("/types")).execute().getList();
}
/**
* {@inheritDoc}
*/
@Override
public List extends Volume> list() {
return get(Volumes.class, uri("/volumes/detail")).execute().getList();
}
/**
* {@inheritDoc}
*/
@Override
public List extends Volume> list(Map filteringParams) {
Invocation volumeInvocation = buildInvocation(filteringParams);
return volumeInvocation.execute().getList();
}
/**
* {@inheritDoc}
*/
@Override
public Volume get(String volumeId) {
checkNotNull(volumeId);
return get(CinderVolume.class, uri("/volumes/%s", volumeId)).execute();
}
/**
* {@inheritDoc}
*/
@Override
public ActionResponse delete(String volumeId) {
checkNotNull(volumeId);
return deleteWithResponse(uri("/volumes/%s", volumeId)).execute();
}
/**
* {@inheritDoc}
*/
@Override
public ActionResponse forceDelete(String volumeId, Boolean cascade) {
checkNotNull(volumeId);
Map params = new HashMap<>();
params.put("cascade",cascade);
return deleteWithResponse(uri("/volumes/%s", volumeId)).params(params).execute();
}
/**
* {@inheritDoc}
*/
@Override
public ActionResponse forceDelete(String volumeId) {
checkNotNull(volumeId);
return post(ActionResponse.class, uri("/volumes/%s/action", volumeId)).entity(new ForceDeleteAction())
.execute();
}
/**
* {@inheritDoc}
*/
@Override
public ActionResponse resetState(String volumeId, Volume.Status status) {
checkNotNull(volumeId);
checkNotNull(status);
return post(ActionResponse.class, uri("/volumes/%s/action", volumeId)).entity(new ResetStatusAction(status))
.execute();
}
/**
* {@inheritDoc}
*/
@Override
public ActionResponse extend(String volumeId, Integer newSize) {
checkNotNull(volumeId);
checkNotNull(newSize);
return post(ActionResponse.class, uri("/volumes/%s/action", volumeId)).entity(new ExtendAction(newSize))
.execute();
}
/**
* {@inheritDoc}
*/
@Override
public Volume create(Volume volume) {
checkNotNull(volume);
return post(CinderVolume.class, uri("/volumes")).entity(volume).execute();
}
/**
* {@inheritDoc}
*/
@Override
public Volume create(Volume volume, Map schedulerHints) {
checkNotNull(volume);
if (schedulerHints == null || schedulerHints.isEmpty()) {
return create(volume);
} else {
HashMap