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

com.elastisys.scale.cloudpool.splitter.requests.http.TerminateMachineRequest Maven / Gradle / Ivy

Go to download

A cloud pool that uses a configured list of child cloud pools to carry out operations.

The newest version!
package com.elastisys.scale.cloudpool.splitter.requests.http;

import static java.lang.String.format;
import static org.apache.http.entity.ContentType.APPLICATION_JSON;

import java.util.concurrent.Callable;

import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;

import com.elastisys.scale.cloudpool.splitter.config.PrioritizedCloudPool;
import com.elastisys.scale.commons.net.http.client.AuthenticatedHttpClient;

/**
 * A {@link Callable} request that will execute
 * {@code POST /pool//terminate} against a cloud pool.
 */
public class TerminateMachineRequest extends CloudPoolRequest {

	/** Machine to request cloud pool to terminate. */
	private final String machineId;
	/** {@code true} if cloud pool should decrement its desired pool size. */
	private final boolean decrementDesiredSize;

	public TerminateMachineRequest(PrioritizedCloudPool cloudPool,
			String machineId, boolean decrementDesiredSize) {
		super(cloudPool);
		this.machineId = machineId;
		this.decrementDesiredSize = decrementDesiredSize;
	}

	@Override
	public Void execute(AuthenticatedHttpClient client) throws Exception {
		String path = String.format("/pool/%s/terminate", this.machineId);
		HttpPost request = new HttpPost(url(path));
		String message = format("{ \"decrementDesiredSize\": %s }",
				this.decrementDesiredSize);
		request.setEntity(new StringEntity(message, APPLICATION_JSON));
		client.execute(request);

		return null;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy