All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.narcissujsk.openstackjsk.openstack.manila.internal.ShareSnapshotServiceImpl Maven / Gradle / Ivy

The newest version!
package com.github.narcissujsk.openstackjsk.openstack.manila.internal;

import com.github.narcissujsk.openstackjsk.api.manila.ShareSnapshotService;
import com.github.narcissujsk.openstackjsk.model.common.ActionResponse;
import com.github.narcissujsk.openstackjsk.model.manila.ShareSnapshot;
import com.github.narcissujsk.openstackjsk.model.manila.ShareSnapshotCreate;
import com.github.narcissujsk.openstackjsk.model.manila.ShareSnapshotUpdateOptions;
import com.github.narcissujsk.openstackjsk.openstack.compute.functions.ToActionResponseFunction;
import com.github.narcissujsk.openstackjsk.openstack.manila.domain.ManilaShareSnapshot;
import com.github.narcissujsk.openstackjsk.openstack.manila.domain.ManilaShareSnapshotUpdate;
import com.github.narcissujsk.openstackjsk.openstack.manila.domain.actions.ShareSnapshotAction;
import com.github.narcissujsk.openstackjsk.openstack.manila.domain.actions.ShareSnapshotActions;

import java.util.List;

import static com.google.common.base.Preconditions.checkNotNull;

public class ShareSnapshotServiceImpl extends BaseShareServices implements ShareSnapshotService {
    @Override
    public ShareSnapshot create(ShareSnapshotCreate snapshotCreate) {
        checkNotNull(snapshotCreate);
        return post(ManilaShareSnapshot.class, uri("/snapshots"))
                .entity(snapshotCreate)
                .execute();
    }

    @Override
    public List list() {
        return list(false);
    }

    @Override
    public List listDetails() {
        return list(true);
    }

    private List list(boolean detail) {
        return get(ManilaShareSnapshot.ShareSnapshots.class, uri("/snapshots" +  (detail ? "/detail" : "")))
                .execute()
                .getList();
    }

    @Override
    public ShareSnapshot get(String snapshotId) {
        checkNotNull(snapshotId);
        return get(ManilaShareSnapshot.class, uri("/snapshots/%s", snapshotId)).execute();
    }

    @Override
    public ShareSnapshot update(String snapshotId, ShareSnapshotUpdateOptions snapshotUpdateOptions) {
        checkNotNull(snapshotId);
        checkNotNull(snapshotUpdateOptions);

        return put(ManilaShareSnapshot.class, uri("/snapshots/%s", snapshotId))
                .entity(ManilaShareSnapshotUpdate.fromOptions(snapshotUpdateOptions))
                .execute();
    }

    @Override
    public ActionResponse delete(String snapshotId) {
        checkNotNull(snapshotId);
        return ToActionResponseFunction.INSTANCE.apply(
                delete(Void.class, uri("/snapshots/%s", snapshotId)).executeWithResponse());
    }

    @Override
    public ActionResponse resetState(String snapshotId, ShareSnapshot.Status status) {
        checkNotNull(snapshotId);
        checkNotNull(status);

        return invokeAction(snapshotId, ShareSnapshotActions.resetState(status));
    }

    @Override
    public ActionResponse forceDelete(String snapshotId) {
        checkNotNull(snapshotId);
        return invokeAction(snapshotId, ShareSnapshotActions.forceDelete());
    }

    /**
     * Invoke the action on the given snapshot.
     *
     * @param snapshotId the snapshot ID
     * @param action the action to invoke
     * @return the action response of the server
     */
    private ActionResponse invokeAction(String snapshotId, ShareSnapshotAction action) {
        return ToActionResponseFunction.INSTANCE.apply(
                post(Void.class, uri("/snapshots/%s/action", snapshotId))
                        .entity(action)
                        .executeWithResponse());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy