Class Microservice

java.lang.Object
desmoj.core.simulator.NamedObject
desmoj.core.simulator.ModelComponent
desmoj.core.simulator.Schedulable
desmoj.core.simulator.Entity
cambio.simulator.entities.NamedEntity
cambio.simulator.entities.microservice.Microservice

public class Microservice extends NamedEntity
A Microservice is one of the core Entities of the simulation. It represents the meta layer of a microservice that is usually present in its managing platform, e.g. CloudFoundry.

Specifically, it can take care of starting, killing and shutting down MicroserviceInstances (in the following just called instances) and provides metadata to each instance. For example, a Microservice object knows which resilience patterns should be implemented by each instance and how many resources each instances is assigned. Naturally it also knows the status of all existing (including killed ones) instances of this service.

Further it has the ability to apply resilience patterns such as autoscaling and different types of load balancing to itself.

The interface of a Microservice is defined via its operations.

Author:
Lion Wagner
See Also:
  • Field Details

    • instancesSet

      protected final transient Set<MicroserviceInstance> instancesSet
    • reporter

      protected final transient MultiDataPointReporter reporter
    • snapshortReporter

      protected final transient SnapshotDataPointReporter snapshortReporter
    • accReporter

      protected final transient ListCollectingReporter accReporter
    • started

      protected transient boolean started
    • instanceSpawnCounter

      protected transient int instanceSpawnCounter
    • instanceOwnedPatternConfigurations

      @Expose @SerializedName(value="i_patterns", alternate={"instance_patterns","patterns","i_pattern","instance_pattern"}) protected InstanceOwnedPatternConfiguration[] instanceOwnedPatternConfigurations
  • Constructor Details

    • Microservice

      public Microservice(desmoj.core.simulator.Model model, String name, boolean showInTrace)
      Creates a new instance of a Microservice.
  • Method Details

    • start

      public void start()
      Starts this Microservice. This procedure includes the starting of the defined amount of instances and the initiation of the ServiceOwnedPatterns.
    • toString

      public String toString()
      Overrides:
      toString in class desmoj.core.simulator.NamedObject
    • getQuotedName

      public String getQuotedName()
      Description copied from class: NamedEntity
      Gets a quoted version of the name of this object. The name will include the object number assigned by DESMO-J.
      Overrides:
      getQuotedName in class NamedEntity
      Returns:
      the name of this entity surrounded with ' quotes.
    • getCapacity

      public int getCapacity()
    • setCapacity

      public void setCapacity(int capacity)
    • getInstancesCount

      public int getInstancesCount()
    • setInstancesCount

      public void setInstancesCount(int numberOfInstances)
      Similar to scaleToInstancesCount(int) but also overwrites the general target instance count of this service.
      Parameters:
      numberOfInstances - amount of instance that this service should target.
    • scaleToInstancesCount

      public void scaleToInstancesCount(int targetInstanceCount)
      Schedules the immediate start or shutdown of MicroserviceInstances until the amount of active instances reaches the target instance count.

      TODO: restart instances that were shut down.

      Parameters:
      targetInstanceCount - amount of instance to which this service should scale.
    • killInstances

      public void killInstances(int numberOfInstances)
      Kills the given number of services many random instances. Accept numbers larger than the current amount of instances.
      Parameters:
      numberOfInstances - number of instances that should be instantly killed
    • killInstance

      public void killInstance()
      Kills a random instance. Can be called on a service that has 0 running instances.
    • getOperations

      public Operation[] getOperations()
    • setOperations

      public void setOperations(Operation[] operations)
    • getOperationByName

      public Operation getOperationByName(String name)
      Searches an Operation that has the name that is given as an argument. The real name of the operation may differ. It may starts with the name of this microservice instance or ands with a '#' and a number.
      Parameters:
      name - name of the operation that should be found
      Returns:
      an operation that has exactly that name, null if not found
    • getNextAvailableInstance

      public MicroserviceInstance getNextAvailableInstance() throws NoInstanceAvailableException
      Uses the loadbalancer of this microservice to find the next suitable target instance.
      Returns:
      a MicroserviceInstance that should receive the next request
      Throws:
      NoInstanceAvailableException - if no instance is available
    • applyDelay

      public void applyDelay(desmoj.core.dist.NumericalDist<Double> dist, Operation operationSrc, Operation operationTrg)
      Applies the given delay distribution to the given operations.
      Parameters:
      dist - NumericalDist of the delay.
      operationSrc - Operation of this Microservice that should be affected, can be set to null to affect all Operations
      operationTrg - target Operation of the operationSrc that should be affected, can be set to null to affect all outgoing InternalRequests
    • finalizeStatistics

      public void finalizeStatistics()
    • getRelativeUtilizationOfInstances

      public List<Double> getRelativeUtilizationOfInstances()
    • getAverageRelativeUtilization

      public double getAverageRelativeUtilization()
    • getUtilizationOfInstances

      public List<Double> getUtilizationOfInstances()
    • getAverageUtilization

      public double getAverageUtilization()
    • getStartingInstanceCount

      public int getStartingInstanceCount()
    • getLoadBalancer

      public LoadBalancer getLoadBalancer()
    • getInstancesSet

      public Set<MicroserviceInstance> getInstancesSet()