blob: 2f27082415f3bfb702bbfaf101e33a9bcfe0684b [file] [log] [blame]
package net.juniper.contrail.model;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.TreeSet;
import com.cloud.exception.InternalErrorException;
/**
* ModelObject
*
* A model object represents the desired state of the system.
*
* The object constructor should set the uuid and the internal id of the cloudstack objects.
*
* The build method reads the master database (typically cloudstack mysql) and derives the state that
* we wish to reflect in the contrail API. This method should not modify the Contrail API state.
*
* The verify method reads the API server state and compares with cached properties.
*
* The update method pushes updates to the contrail API server.
*/
public interface ModelObject {
public static class ModelReference implements Comparable<ModelReference> {
WeakReference<ModelObject> reference;
ModelReference(ModelObject obj) {
reference = new WeakReference<ModelObject>(obj);
}
@Override
public int compareTo(ModelReference other) {
ModelObject lhs = reference.get();
ModelObject rhs = other.reference.get();
if (lhs == null) {
if (rhs == null) {
return 0;
}
return -1;
}
return lhs.compareTo(rhs);
}
@Override
public boolean equals(Object other) {
try {
ModelReference rhs = (ModelReference) other;
return compareTo(rhs) == 0;
} catch (ClassCastException ex) {
}
return false;
}
public ModelObject get() {
return reference.get();
}
};
public void addSuccessor(ModelObject child);
public TreeSet<ModelReference> ancestors();
public void clearSuccessors();
public int compareTo(ModelObject o);
/**
* Delete the object from the API server.
* @param controller
* @throws IOException
*/
public void delete(ModelController controller) throws IOException;
/**
* Deletes the object from the data model graph.
*
* @param controller
* @throws IOException
*/
public void destroy(ModelController controller) throws IOException;
public void removeSuccessor(ModelObject child);
public TreeSet<ModelObject> successors();
/**
* Push updates to Contrail API server. This API is only valid for objects in the database.
* @param controller
* @throws IOException
* @throws InternalErrorException
*/
public void update(ModelController controller) throws InternalErrorException, IOException;
/**
* Check that the state of the current object matches the state of the API server.
* @param controller
* @return
*/
public boolean verify(ModelController controller);
/*
* Compare the state of existing model object with latest model object
*/
public boolean compare(ModelController controller, ModelObject current);
}