<commit_before>package org.dasein.cloud.google.util.model;

import com.google.api.client.util.DateTime;
import com.google.api.services.compute.model.AttachedDisk;
import com.google.api.services.compute.model.Disk;
import com.google.common.base.Function;
import org.dasein.cloud.ProviderContext;
import org.dasein.cloud.compute.*;
import org.dasein.cloud.google.compute.server.GoogleServerSupport;
import org.dasein.cloud.google.util.GoogleEndpoint;
import org.dasein.cloud.google.util.GoogleLogger;
import org.dasein.util.uom.storage.Gigabyte;
import org.dasein.util.uom.storage.Storage;
import org.slf4j.Logger;

import javax.annotation.Nullable;

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

/**
 * This class contains a static factory methods that allows volumes to be converted to Dasein objects (and vice-a-versa). This class also
 * contains various methods for manipulating google volumes which are not provided by default via GCE java API.
 *
 * @author igoonich
 * @since 13.12.2013
 */
public final class GoogleDisks {

	private static final Logger logger = GoogleLogger.getLogger(GoogleDisks.class);

	/**
	 * Data center extension to be used by default
	 */
	private static final String DEFAULT_DISK_ZONE_TYPE = "a";

	/**
	 * Persistent disk type. Currently the only type of disks which accepted by google
	 */
	public static final String PERSISTENT_DISK_TYPE = "PERSISTENT";

	/**
	 * Google disks read mode
	 */
	public enum DiskMode {

		/**
		 * Read-only mode. Persistent disk can be attached to multiple instances in this mode.
		 */
		READ_ONLY,

		/**
		 * read-write mode. Persistent disk can be attached to a single instance in read-write mode.
		 */
		READ_WRITE

	}

	/**
	 * Wrapper version of google attachment
	 */
	public static class RichAttachedDisk {
		private AttachedDisk attachedDisk;
		private AttachedDiskType attachedDiskType;

		public RichAttachedDisk(AttachedDiskType attachedDiskType, AttachedDisk attachedDisk) {
			this.attachedDiskType = checkNotNull(attachedDiskType);
			this.attachedDisk = checkNotNull(attachedDisk);
		}

		public AttachedDiskType getAttachedDiskType() {
			return attachedDiskType;
		}

		public AttachedDisk getAttachedDisk() {
			return attachedDisk;
		}
	}

	/**
	 * Dasein attached volume creation type
	 */
	public enum AttachedDiskType {

		/**
		 * Create boot volume operation
		 */
		BOOT,

		/**
		 * Do not create volume, use existing one
		 */
		EXISTING,

		/**
		 * Create standard volume
		 */
		STANDARD

	}

	/**
	 * Create {@link Disk} object based on provided dasein {@link VolumeCreateOptions}
	 *
	 * @param createOptions dasein volume create options
	 * @param context       provider context
	 * @return google disk object to be created
	 */
	public static Disk from(VolumeCreateOptions createOptions, ProviderContext context) {
		checkNotNull(createOptions);
		checkNotNull(context);
		checkNotNull(createOptions.getName(), "Name is missing for volume");

		Disk googleDisk = new Disk();

		googleDisk.setName(createOptions.getName());
		googleDisk.setDescription(createOptions.getDescription());

		if (createOptions.getSnapshotId() != null) {
			googleDisk.setSourceSnapshot(GoogleEndpoint.SNAPSHOT.getEndpointUrl(createOptions.getSnapshotId(), context.getAccountNumber()));
		} else {
			googleDisk.setSizeGb(createOptions.getVolumeSize().getQuantity().longValue());
		}

		if (createOptions.getDataCenterId() != null) {
			googleDisk.setZone(createOptions.getDataCenterId());
		} else {
			googleDisk.setZone(context.getRegionId() + "-" + DEFAULT_DISK_ZONE_TYPE);
		}<commit_msg>allow to create volumes from snapshots with different size<commit_after>package org.dasein.cloud.google.util.model;

import com.google.api.client.util.DateTime;
import com.google.api.services.compute.model.AttachedDisk;
import com.google.api.services.compute.model.Disk;
import com.google.common.base.Function;
import org.dasein.cloud.ProviderContext;
import org.dasein.cloud.compute.*;
import org.dasein.cloud.google.compute.server.GoogleServerSupport;
import org.dasein.cloud.google.util.GoogleEndpoint;
import org.dasein.cloud.google.util.GoogleLogger;
import org.dasein.util.uom.storage.Gigabyte;
import org.dasein.util.uom.storage.Storage;
import org.slf4j.Logger;

import javax.annotation.Nullable;

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

/**
 * This class contains a static factory methods that allows volumes to be converted to Dasein objects (and vice-a-versa). This class also
 * contains various methods for manipulating google volumes which are not provided by default via GCE java API.
 *
 * @author igoonich
 * @since 13.12.2013
 */
public final class GoogleDisks {

	private static final Logger logger = GoogleLogger.getLogger(GoogleDisks.class);

	/**
	 * Data center extension to be used by default
	 */
	private static final String DEFAULT_DISK_ZONE_TYPE = "a";

	/**
	 * Persistent disk type. Currently the only type of disks which accepted by google
	 */
	public static final String PERSISTENT_DISK_TYPE = "PERSISTENT";

	/**
	 * Google disks read mode
	 */
	public enum DiskMode {

		/**
		 * Read-only mode. Persistent disk can be attached to multiple instances in this mode.
		 */
		READ_ONLY,

		/**
		 * read-write mode. Persistent disk can be attached to a single instance in read-write mode.
		 */
		READ_WRITE

	}

	/**
	 * Wrapper version of google attachment
	 */
	public static class RichAttachedDisk {
		private AttachedDisk attachedDisk;
		private AttachedDiskType attachedDiskType;

		public RichAttachedDisk(AttachedDiskType attachedDiskType, AttachedDisk attachedDisk) {
			this.attachedDiskType = checkNotNull(attachedDiskType);
			this.attachedDisk = checkNotNull(attachedDisk);
		}

		public AttachedDiskType getAttachedDiskType() {
			return attachedDiskType;
		}

		public AttachedDisk getAttachedDisk() {
			return attachedDisk;
		}
	}

	/**
	 * Dasein attached volume creation type
	 */
	public enum AttachedDiskType {

		/**
		 * Create boot volume operation
		 */
		BOOT,

		/**
		 * Do not create volume, use existing one
		 */
		EXISTING,

		/**
		 * Create standard volume
		 */
		STANDARD

	}

	/**
	 * Create {@link Disk} object based on provided dasein {@link VolumeCreateOptions}
	 *
	 * @param createOptions dasein volume create options
	 * @param context       provider context
	 * @return google disk object to be created
	 */
	public static Disk from(VolumeCreateOptions createOptions, ProviderContext context) {
		checkNotNull(createOptions);
		checkNotNull(context);
		checkNotNull(createOptions.getName(), "Name is missing for volume");

		Disk googleDisk = new Disk();

		googleDisk.setName(createOptions.getName());
		googleDisk.setDescription(createOptions.getDescription());

		if (createOptions.getSnapshotId() != null) {
			googleDisk.setSourceSnapshot(GoogleEndpoint.SNAPSHOT.getEndpointUrl(createOptions.getSnapshotId(), context.getAccountNumber()));
		}

		googleDisk.setSizeGb(createOptions.getVolumeSize().getQuantity().longValue());

		if (createOptions.getDataCenterId() != null) {
			googleDisk.setZone(createOptions.getDataCenterId());
		} else {
			googleDisk.setZone(context.getRegionId() + "-" + DEFAULT_DISK_ZONE_TYPE);
		}
{'fraction_non_alphanumeric': 0.09720299086125726, 'fraction_numerical': 0.0024923843810578787, 'mean_word_length': 4.303230543318649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '937688', 'n_tokens_mistral': 2282, 'n_tokens_neox': 2049, 'n_words': 553}