org.btrplace.model.constraint.migration.Deadline Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scheduler-api Show documentation
Show all versions of scheduler-api Show documentation
Core components for a scheduler
The newest version!
/*
* Copyright 2020 The BtrPlace Authors. All rights reserved.
* Use of this source code is governed by a LGPL-style
* license that can be found in the LICENSE.txt file.
*/
package org.btrplace.model.constraint.migration;
import org.btrplace.model.Node;
import org.btrplace.model.VM;
import org.btrplace.model.constraint.SatConstraint;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* A constraint to force the maximum end time of a migration by an absolute
* or relative deadline in the form of a timestamp.
*
* @author Vincent Kherbache
*/
public class Deadline implements SatConstraint {
private String timestamp;
private final VM vm;
/**
* Make a new constraint.
*
* @param vm the VM to constraint
* @param timestamp the desired deadline
*/
public Deadline(VM vm, String timestamp) {
this.vm = vm;
this.timestamp = timestamp;
}
/**
* Get the deadline timestamp.
*
* @return the timestamp
*/
public String getTimestamp() {
return timestamp;
}
/**
* Change the deadline timestamp.
*
* @param timestamp the new timestamp
*/
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
@Override
public boolean setContinuous(boolean b) {
return b;
}
@Override
public Collection getInvolvedNodes() {
return Collections.emptyList();
}
@Override
public Collection getInvolvedVMs() {
return Collections.singleton(vm);
}
@Override
public boolean isContinuous() {
return false;
}
@Override
public DeadlineChecker getChecker() {
return new DeadlineChecker(this);
}
@Override
public String toString() {
return "deadline(vm=" + vm + ", deadline='" + timestamp + "', continuous)";
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Deadline deadline = (Deadline) o;
return Objects.equals(timestamp, deadline.timestamp) &&
Objects.equals(vm, deadline.vm);
}
@Override
public int hashCode() {
return Objects.hash(timestamp, vm);
}
/**
* Instantiate discrete constraints for a collection of VMs.
*
* @param vms the VMs to integrate
* @param deadline the desired deadline
* @return the associated list of constraints
*/
public static List newDeadline(Collection vms, String deadline) {
return vms.stream().map(v -> new Deadline(v, deadline)).collect(Collectors.toList());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy