Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change CloudSimTag from static int to enum like cloudsim 7G #38

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,86 +1,83 @@
package org.lgdcloudsim.core;

import org.lgdcloudsim.loadbalancer.LoadBalancer;
import org.lgdcloudsim.interscheduler.InterSchedulerResult;
import org.lgdcloudsim.request.InstanceGroup;
import org.lgdcloudsim.util.FailedOutdatedResult;

import java.util.Set;

import org.lgdcloudsim.interscheduler.InterSchedulerResult;
import org.lgdcloudsim.loadbalancer.LoadBalancer;

/**
* Tags indicating a type of action that
* needs to be undertaken by CloudSim entities when they receive or send events.
* The lower the value of Tag, the higher the execution priority.
*
* Contains various static tags that indicate a type of action that needs to be undertaken
* by CloudSim entities when they receive or send events.
* Note that in the same situation, the order in which tags are processed is consistent with the order in which they are declared in the class.
*
* @author Jiawen Liu
* @author Manzur Murshed
* @author Rajkumar Buyya
* @author Anthony Sulistio
* @author Manoel Campos da Silva Filho
* @author Anonymous
* @since CloudSim Toolkit 1.0
* @author Remo Andreoli
* @since LGDCloudsim 1.1
*/
public class CloudSimTag {
public static final int NONE = -99;

/**
* Starting constant value for cloud-related tags.
*/
private static final int BASE = 0;

public enum CloudActionTags implements CloudSimTags {
/**
* Denotes that some user request has failed.
* This event will be sent to {@link CloudInformationService} for processing.
* The {@link org.lgdcloudsim.core.events.SimEvent#getData()} must be a set of {@link org.lgdcloudsim.request.UserRequest} object.
* Denotes the base tag value for CloudSim entities.
* It doesn't represent any specific action.
*/
public static final int USER_REQUEST_FAIL = BASE - 1;
NONE,

/**
* Synchronize host states to inter-scheduler between data centers.
* It will be executed periodically.
* Denotes a request from a Datacenter to register itself. This tag is normally used
* between {@link CloudInformationService} and Datacenter entities.
* When such a {@link org.lgdcloudsim.core.events.SimEvent} is sent, the {@link org.lgdcloudsim.core.events.SimEvent#getData()}
* must be a {@link org.lgdcloudsim.datacenter.Datacenter} object.
*/
public static final int SYN_STATE_BETWEEN_DC = USER_REQUEST_FAIL - 1;
DC_REGISTRATION_REQUEST,

/**
* Synchronize host states to intra-scheduler in the data center.
* It will be executed periodically.
* Periodically modify the scope of each collaboration zone.
* This tag is used to notify the {@link CloudInformationService} to change the collaboration zone.
*/
public static final int SYN_STATE_BETWEEN_CENTER_AND_INTRA_SCHEDULER_IN_DC = SYN_STATE_BETWEEN_DC - 1;
CHANGE_COLLABORATION_SYN,

/**
* Denotes the end of the execution of instances.
* This tag is used by the {@link org.lgdcloudsim.datacenter.Datacenter}.
* the {@link org.lgdcloudsim.core.events.SimEvent#getData()} must be a list of {@link org.lgdcloudsim.request.Instance} objects
* which are finishing at the same time.
*/
public static final int SYN_STATE_BY_HEARTBEAT_IN_DC = SYN_STATE_BETWEEN_CENTER_AND_INTRA_SCHEDULER_IN_DC - 1;
END_INSTANCE_RUN,

/**
* Denotes the end of the execution of instances.
* This tag is used by the {@link org.lgdcloudsim.datacenter.Datacenter}.
* the {@link org.lgdcloudsim.core.events.SimEvent#getData()} must be a list of {@link org.lgdcloudsim.request.Instance} objects
* which are finishing at the same time.
*/
public static final int END_INSTANCE_RUN = SYN_STATE_BY_HEARTBEAT_IN_DC - 1;
SYN_STATE_BY_HEARTBEAT_IN_DC,

/**
* Periodically modify the scope of each collaboration zone.
* This tag is used to notify the {@link CloudInformationService} to change the collaboration zone.
* Synchronize host states to intra-scheduler in the data center.
* It will be executed periodically.
*/
public static final int CHANGE_COLLABORATION_SYN = END_INSTANCE_RUN - 1;
SYN_STATE_BETWEEN_CENTER_AND_INTRA_SCHEDULER_IN_DC,

/**
* Denotes a request from a Datacenter to register itself. This tag is normally used
* between {@link CloudInformationService} and Datacenter entities.
* When such a {@link org.lgdcloudsim.core.events.SimEvent} is sent, the {@link org.lgdcloudsim.core.events.SimEvent#getData()}
* must be a {@link org.lgdcloudsim.datacenter.Datacenter} object.
* Synchronize host states to inter-scheduler between data centers.
* It will be executed periodically.
*/
SYN_STATE_BETWEEN_DC,

/**
* Denotes that some user request has failed.
* This event will be sent to {@link CloudInformationService} for processing.
* The {@link org.lgdcloudsim.core.events.SimEvent#getData()} must be a set of {@link org.lgdcloudsim.request.UserRequest} object.
*/
public static final int DC_REGISTRATION_REQUEST = CHANGE_COLLABORATION_SYN - 1;
USER_REQUEST_FAIL,

/**
* Denotes a request from the {@link org.lgdcloudsim.user.UserSimple} to a {@link CloudInformationService} to get
* the list of all Datacenters which are registered with the CloudInformationService.
*/
public static final int DC_LIST_REQUEST = BASE + 1;
DC_LIST_REQUEST,

/**
* Denotes a request from the {@link org.lgdcloudsim.user.UserSimple} to send.
Expand All @@ -89,28 +86,28 @@ public class CloudSimTag {
* It also can be the {@link org.lgdcloudsim.interscheduler.InterScheduler} scheduling result.
* In this case, the instanceGroups can be forwarded to other data centers.
*/
public static final int USER_REQUEST_SEND = DC_LIST_REQUEST + 1;
USER_REQUEST_SEND,

/**
* Denotes that there are still user requests that need to be sent by the {@link org.lgdcloudsim.user.UserSimple}.
*/
public static final int NEED_SEND_USER_REQUEST = USER_REQUEST_SEND + 1;
NEED_SEND_USER_REQUEST,

/**
* Denotes the start of inter-scheduler scheduling.
* Note that it must be bigger than {@link #USER_REQUEST_SEND}.
* Therefore, when two events arrive at the same time,
* the user request can be placed in the queue first, and then inter-scheduler scheduling can be started.
*/
public static final int INTER_SCHEDULE_BEGIN = NEED_SEND_USER_REQUEST + 1;
INTER_SCHEDULE_BEGIN,

/**
* Denotes the end of inter-scheduler scheduling.
* The event will be sent after the execution of the {@link #INTER_SCHEDULE_BEGIN}.
* The time interval between two events is the time spent on inter-scheduling.
* The {@link org.lgdcloudsim.core.events.SimEvent#getData()} must be a list of {@link InterSchedulerResult} object.
*/
public static final int INTER_SCHEDULE_END = INTER_SCHEDULE_BEGIN + 1;
INTER_SCHEDULE_END,

/**
* Send the scheduling results of the {@link org.lgdcloudsim.interscheduler.InterScheduler} to the data center.
Expand All @@ -121,71 +118,71 @@ public class CloudSimTag {
* So the datacenter will call intra-scheduler to schedule the instance group.
* The {@link org.lgdcloudsim.core.events.SimEvent#getData()} must be a list of {@link org.lgdcloudsim.request.InstanceGroup} object.
*/
public static final int SCHEDULE_TO_DC_NO_FORWARD = INTER_SCHEDULE_END + 1;
SCHEDULE_TO_DC_NO_FORWARD,

/**
* Send the scheduling results of the {@link org.lgdcloudsim.interscheduler.InterScheduler} to the data center.
* This type of scheduling not only clarifies which data center the instance group is scheduled to,
* but also schedules the instances in the instance group at the host level.
* The {@link org.lgdcloudsim.core.events.SimEvent#getData()} must be a list of {@link org.lgdcloudsim.request.InstanceGroup} object.
*/
public static final int SCHEDULE_TO_DC_HOST = SCHEDULE_TO_DC_NO_FORWARD + 1;
SCHEDULE_TO_DC_HOST,

/**
* This event is used to respond to the {@link #SCHEDULE_TO_DC_HOST} event.
* It indicates that all instances included in the event were successfully scheduled to the host without conflicts and failures.
*/
public static final int SCHEDULE_TO_DC_HOST_OK = SCHEDULE_TO_DC_HOST + 1;
SCHEDULE_TO_DC_HOST_OK,

/**
* This event is used to respond to the {@link #SCHEDULE_TO_DC_HOST} event.
* It indicates that there are conflicts or failures in scheduling the instances to the host.
* The {@link org.lgdcloudsim.core.events.SimEvent#getData()} must be a {@link FailedOutdatedResult<InstanceGroup>} object.
*/
public static final int SCHEDULE_TO_DC_HOST_CONFLICTED = SCHEDULE_TO_DC_HOST_OK + 1;
SCHEDULE_TO_DC_HOST_CONFLICTED,

/**
* Denotes the start of the load balancing process.
* It is used by the {@link org.lgdcloudsim.datacenter.Datacenter}.
* It will call the {@link LoadBalancer} to distribute the instances to the intra-schedulers.
*/
public static final int LOAD_BALANCE_SEND = SCHEDULE_TO_DC_HOST_CONFLICTED + 1;
LOAD_BALANCE_SEND,

/**
* Denotes the end of the {@link org.lgdcloudsim.intrascheduler.IntraScheduler} scheduling.
* The event will be sent after the execution of the {@link #INTRA_SCHEDULE_BEGIN}.
*/
public static final int INTRA_SCHEDULE_END = LOAD_BALANCE_SEND + 1;
INTRA_SCHEDULE_END,

/**
* Conflict checking before placing any instance on the host.
*/
public static final int PRE_ALLOCATE_RESOURCE = INTRA_SCHEDULE_END + 1;
PRE_ALLOCATE_RESOURCE,

/**
* Denotes the start of the {@link org.lgdcloudsim.intrascheduler.IntraScheduler} scheduling.
*/
public static final int INTRA_SCHEDULE_BEGIN = PRE_ALLOCATE_RESOURCE + 1;
INTRA_SCHEDULE_BEGIN;

/**
* If there are multiple identical events at the same time, they only need to be executed once.
*/
public static final Set<Integer> UNIQUE_TAG = Set.of(LOAD_BALANCE_SEND, PRE_ALLOCATE_RESOURCE, SYN_STATE_BY_HEARTBEAT_IN_DC);
public static final Set<CloudActionTags> UNIQUE_TAG = Set.of(LOAD_BALANCE_SEND, PRE_ALLOCATE_RESOURCE, SYN_STATE_BY_HEARTBEAT_IN_DC);

/**
* Tags that exist in cycles.
* If only these tags are left in all events,
* it means that there are no new events that need to be executed, and the simulation can be ended.
*/
public static final Set<Integer> LOOP_TAG = Set.of(SYN_STATE_BETWEEN_DC, SYN_STATE_BETWEEN_CENTER_AND_INTRA_SCHEDULER_IN_DC, CHANGE_COLLABORATION_SYN);
public static final Set<CloudActionTags> LOOP_TAG = Set.of(SYN_STATE_BETWEEN_DC, SYN_STATE_BETWEEN_CENTER_AND_INTRA_SCHEDULER_IN_DC, CHANGE_COLLABORATION_SYN);

/**
* Convert the tag to a string.
*
* @param tag the tag to convert
* @return the string representation of the tag
*/
public static String tagToString(int tag) {
public static String tagToString(CloudActionTags tag) {
return switch (tag) {
case CHANGE_COLLABORATION_SYN -> "CHANGE_COLLABORATION_SYN";
case SYN_STATE_BY_HEARTBEAT_IN_DC -> "SYN_STATE_BY_HEARTBEAT_IN_DC";
Expand All @@ -209,8 +206,8 @@ public static String tagToString(int tag) {
case PRE_ALLOCATE_RESOURCE -> "PRE_ALLOCATE_RESOURCE";
case END_INSTANCE_RUN -> "END_INSTANCE_RUN";
case NONE -> "NONE";
case BASE -> "Base";
default -> "UNKNOWN";
};
}
}

Loading
Loading