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

com.emc.mongoose.load.step.weighted.WeightedLoadStepClient Maven / Gradle / Ivy

The newest version!
package com.emc.mongoose.load.step.weighted;

import com.emc.mongoose.base.env.Extension;
import com.emc.mongoose.base.item.op.OpType;
import com.emc.mongoose.base.load.step.client.LoadStepClient;
import com.emc.mongoose.base.load.step.client.LoadStepClientBase;
import com.emc.mongoose.base.logging.LogUtil;
import com.emc.mongoose.base.metrics.MetricsManager;
import com.github.akurilov.commons.reflection.TypeUtil;
import com.github.akurilov.commons.system.SizeInBytes;
import com.github.akurilov.confuse.Config;
import com.github.akurilov.confuse.exceptions.InvalidValuePathException;
import com.github.akurilov.confuse.exceptions.InvalidValueTypeException;
import com.github.akurilov.confuse.impl.BasicConfig;
import org.apache.logging.log4j.Level;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static com.github.akurilov.commons.collection.TreeUtil.reduceForest;
import static com.github.akurilov.commons.lang.Exceptions.throwUnchecked;
import static com.github.akurilov.confuse.Config.deepToMap;

public class WeightedLoadStepClient extends LoadStepClientBase {
	public WeightedLoadStepClient(
					final Config config, final List extensions, final List ctxConfigs,
					final MetricsManager metricsManager) {
		super(config, extensions, ctxConfigs, metricsManager);
	}

	@Override
	public String getTypeName() {
		return WeightedLoadStepExtension.TYPE;
	}

	@Override
	@SuppressWarnings("unchecked")
	protected  T copyInstance(final Config config, final List ctxConfigs) {
		return (T) new WeightedLoadStepClient(config, extensions, ctxConfigs, metricsMgr);
	}

	@Override
	protected void init() throws IllegalStateException {
		final String autoStepId = "weighted_" + LogUtil.getDateTimeStamp();
		final Config stepConfig = config.configVal("load-step");
		if (stepConfig.boolVal("idAutoGenerated")) {
			stepConfig.val("id", autoStepId);
		}
		final int subStepCount = ctxConfigs.size();

		// 2nd pass: initialize the sub steps
		for (int originIndex = 0; originIndex < subStepCount; originIndex++) {
			final Map mergedConfigTree = reduceForest(
							Arrays.asList(deepToMap(config), deepToMap(ctxConfigs.get(originIndex))));
			Config subConfig = null;
			try {
				subConfig = new BasicConfig(config.pathSep(), config.schema(), mergedConfigTree);
			} catch (final InvalidValueTypeException | InvalidValuePathException e) {
				LogUtil.exception(Level.FATAL, e, "Scenario syntax error");
				throwUnchecked(e);
			}
			final OpType opType = OpType.valueOf(subConfig.stringVal("load-op-type").toUpperCase());
			final int concurrencyLimit = config.intVal("storage-driver-limit-concurrency");
			final Config outputConfig = subConfig.configVal("output");
			final Config metricsConfig = outputConfig.configVal("metrics");
			final SizeInBytes itemDataSize;
			final Object itemDataSizeRaw = subConfig.val("item-data-size");
			if (itemDataSizeRaw instanceof String) {
				itemDataSize = new SizeInBytes((String) itemDataSizeRaw);
			} else {
				itemDataSize = new SizeInBytes(TypeUtil.typeConvert(itemDataSizeRaw, long.class));
			}
			final boolean colorFlag = outputConfig.boolVal("color");
			stepConfig.val("id", subConfig.stringVal("load-step-id")); // Overwrite step id with sub config step id
			initMetrics(originIndex, opType, concurrencyLimit, metricsConfig, itemDataSize, colorFlag);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy