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

com.elastisys.scale.cloudpool.splitter.requests.http.SetServiceStateRequest 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.api.types.ServiceState;
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//serviceState} against a cloud pool.
 */
public class SetServiceStateRequest extends CloudPoolRequest {

	/** Machine whose service state is to be set. */
	private final String machineId;
	/** Service state to set. */
	private final ServiceState serviceState;

	public SetServiceStateRequest(PrioritizedCloudPool cloudPool,
			String machineId, ServiceState serviceState) {
		super(cloudPool);
		this.machineId = machineId;
		this.serviceState = serviceState;
	}

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

		return null;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy