cloudsim-plus-master/cloudsim-plus-master/cloudsim-plus/src/main/java/org/cloudsimplus/faultinjection/HostFaultInjection.java
private void createVmCloneIfAllVmsDestroyed(DatacenterBroker broker, Vm lastVmFailedFromBroker) {
        if(!isAllVmsFailed(broker)){
            return;
        }

        if(!isVmClonerSet(broker) || getVmCloner(broker).isMaxClonesNumberReached()) {
            vmRecoveryTimeSecsMap.put(lastVmFailedFromBroker, -getSimulation().clock());
        }

        if(!isVmClonerSet(broker)) {
            Log.printFormattedLine("\t# A Vm Cloner was not set for broker %d. So that VM failure will not be recovered.", broker.getId());
            return;
        }

        final VmCloner cloner = getVmCloner(broker);
        if(cloner.isMaxClonesNumberReached()){
            Log.printFormattedLine("\t# The maximum allowed number of %d VMs to create has been reached.", cloner.getMaxClonesNumber());
            return;
        }

        registerFaultOfAllVms(broker);
        final double recoveryTimeSecs = getRandomRecoveryTimeForVmInSecs();
        Log.printFormattedLine("\t# Time to recovery from fault by cloning the failed VM: %.2f minutes", recoveryTimeSecs/60.0);

        final Map.Entry<Vm, List<Cloudlet>> entry = cloner.clone(lastVmFailedFromBroker);

        final Vm clonedVm = entry.getKey();
        final List<Cloudlet> clonedCloudlets = entry.getValue();
        clonedVm.setSubmissionDelay(recoveryTimeSecs);
        clonedVm.addOnHostAllocationListener(evt -> vmRecoveryTimeSecsMap.put(evt.getVm(), recoveryTimeSecs));
        broker.submitVm(clonedVm);
        broker.submitCloudletList(clonedCloudlets, recoveryTimeSecs);
    }
/**
     * Creates a VM for the last failed VM if all VMs belonging to the broker have failed
     * and the maximum number of clones to create was not reached.
     *
     * <p>
     * If all VMs have failed and a {@link VmCloner} is not set or the max number of
     * clones already was created, from the time of the failure
     * until the end of the simulation, this interval the customer
     * service is completely unavailable.
     *
     * Since the map below stores recovery times and not unavailability times,
     * it's being store the failure time as a negative value.
     * This way, when computing the availability for the customer,
     * these negative values are changed to: lastSimulationTime - |negativeRecoveryTime|.
     * Using this logic, is like the VM was recovered only in the end of the simulation.
     * It in fact is not recovered, but this logic has to be applied to
     * allow computing the availability.
     *
     * </p>
     * @param broker
     * @param lastVmFailedFromBroker
     */
Creates a VM for the last failed VM if all VMs belonging to the broker have failed
and the maximum number of clones to create was not reached.


If all VMs have failed and a  VmCloner is not set or the max number of
clones already was created, from the time of the failure
until the end of the simulation, this interval the customer
service is completely unavailable.

Since the map below stores recovery times and not unavailability times,
it's being store the failure time as a negative value.
This way, when computing the availability for the customer,
these negative values are changed to: lastSimulationTime - |negativeRecoveryTime|.
Using this logic, is like the VM was recovered only in the end of the simulation.
It in fact is not recovered, but this logic has to be applied to
allow computing the availability.


@param broker
@param lastVmFailedFromBroker
Creates a VM for the last failed VM if all VMs belonging to the broker have failed and the maximum number of clones to create was not reached . If all VMs have failed and a VmCloner is not set or the max number of clones already was created from the time of the failure until the end of the simulation this interval the customer service is completely unavailable . Since the map below stores recovery times and not unavailability times it ' s being store the failure time as a negative value . This way when computing the availability for the customer these negative values are changed to : lastSimulationTime - |negativeRecoveryTime| . Using this logic is like the VM was recovered only in the end of the simulation . It in fact is not recovered but this logic has to be applied to allow computing the availability . @param broker @param lastVmFailedFromBroker
private void createVmCloneIfAllVmsDestroyed(DatacenterBroker broker, Vm lastVmFailedFromBroker) {
        if(!isAllVmsFailed(broker)){
            return;
        }
        if(!isVmClonerSet(broker) || getVmCloner(broker).isMaxClonesNumberReached()) {
            vmRecoveryTimeSecsMap.put(lastVmFailedFromBroker, -getSimulation().clock());
        }
        if(!isVmClonerSet(broker)) {
            Log.printFormattedLine("\t# A Vm Cloner was not set for broker %d. So that VM failure will not be recovered.", broker.getId());
            return;
        }
        final VmCloner cloner = getVmCloner(broker);
        if(cloner.isMaxClonesNumberReached()){
            Log.printFormattedLine("\t# The maximum allowed number of %d VMs to create has been reached.", cloner.getMaxClonesNumber());
            return;
        }
        registerFaultOfAllVms(broker);
        final double recoveryTimeSecs = getRandomRecoveryTimeForVmInSecs();
        Log.printFormattedLine("\t# Time to recovery from fault by cloning the failed VM: %.2f minutes", recoveryTimeSecs/60.0);
        final Map.Entry<Vm, List<Cloudlet>> entry = cloner.clone(lastVmFailedFromBroker);
        final Vm clonedVm = entry.getKey();
        final List<Cloudlet> clonedCloudlets = entry.getValue();
        clonedVm.setSubmissionDelay(recoveryTimeSecs);
        clonedVm.addOnHostAllocationListener(evt -> vmRecoveryTimeSecsMap.put(evt.getVm(), recoveryTimeSecs));
        broker.submitVm(clonedVm);
        broker.submitCloudletList(clonedCloudlets, recoveryTimeSecs);
    }
private void createVmCloneIfAllVmsDestroyed ( DatacenterBroker broker , Vm lastVmFailedFromBroker ) { if ( ! isAllVmsFailed ( broker ) ) { return ; } if ( ! isVmClonerSet ( broker ) || getVmCloner ( broker ) . isMaxClonesNumberReached ( ) ) { vmRecoveryTimeSecsMap . put ( lastVmFailedFromBroker , - getSimulation ( ) . clock ( ) ) ; } if ( ! isVmClonerSet ( broker ) ) { Log . printFormattedLine ( "\t# A Vm Cloner was not set for broker %d. So that VM failure will not be recovered." , broker . getId ( ) ) ; return ; } final VmCloner cloner = getVmCloner ( broker ) ; if ( cloner . isMaxClonesNumberReached ( ) ) { Log . printFormattedLine ( "\t# The maximum allowed number of %d VMs to create has been reached." , cloner . getMaxClonesNumber ( ) ) ; return ; } registerFaultOfAllVms ( broker ) ; final double recoveryTimeSecs = getRandomRecoveryTimeForVmInSecs ( ) ; Log . printFormattedLine ( "\t# Time to recovery from fault by cloning the failed VM: %.2f minutes" , recoveryTimeSecs / 60.0 ) ; final Map . Entry < Vm , List < Cloudlet > > entry = cloner . clone ( lastVmFailedFromBroker ) ; final Vm clonedVm = entry . getKey ( ) ; final List < Cloudlet > clonedCloudlets = entry . getValue ( ) ; clonedVm . setSubmissionDelay ( recoveryTimeSecs ) ; clonedVm . addOnHostAllocationListener ( evt -> vmRecoveryTimeSecsMap . put ( evt . getVm ( ) , recoveryTimeSecs ) ) ; broker . submitVm ( clonedVm ) ; broker . submitCloudletList ( clonedCloudlets , recoveryTimeSecs ) ; }
Creates a VM for the last failed VM if all VMs belonging to the broker have failed
 and the maximum number of clones to create was not reached.
Creates a VM for the last failed VM if all VMs belonging to the broker have failed and the maximum number of clones to create was not reached .