Example usage for org.joda.time DateTime now

List of usage examples for org.joda.time DateTime now

Introduction

In this page you can find the example usage for org.joda.time DateTime now.

Prototype

public static DateTime now() 

Source Link

Document

Obtains a DateTime set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:com.cloudera.director.azure.compute.provider.CleanUpTask.java

License:Apache License

/**
 * Creates a CleanUpTask./*from w  w  w .j  a  va2  s .  c o m*/
 *
 * NOTE: VM object may or may not be created properly, use info in the resource context to delete
 * any left over resources.
 * @param resourceGroup Azure Resource Group name
 * @param context       ResourceContext info
 * @param computeProviderHelper
 * @param isPublicIPConfigured
 */
public CleanUpTask(String resourceGroup, ResourceContext context,
        AzureComputeProviderHelper computeProviderHelper, boolean isPublicIPConfigured,
        int azureOperationPollingTimeout) {
    this.resourceGroup = resourceGroup;
    this.context = context;
    this.computeProviderHelper = computeProviderHelper;
    this.isPublicIPConfigured = isPublicIPConfigured;
    this.startTime = DateTime.now();
    this.vm = null;
    this.azureOperationPollingTimeout = azureOperationPollingTimeout;
}

From source file:com.cloudera.director.azure.compute.provider.CleanUpTask.java

License:Apache License

/**
 * Deletes a VM first and then its supporting resources using VirtualMachine info.
 *
 * @return result of CleanUpTask/*from www  .j  a va2  s  . c om*/
 */
private TaskResult deleteUsingVmInfo() {
    if (vm == null) {
        LOG.error("VM identifier is null, can not delete VM and associated resources.");
        return new TaskResult(false, null);
    }

    // Create ResourceContext to hold VM information, verify the required resource info is present.
    ResourceContext ctx = computeProviderHelper.getResourceContextFromVm(resourceGroup, vm);
    try {
        ctx.setNetworkInterfaceName(computeProviderHelper.getNicNameFromVm(vm));
        ctx.setStorageAccountName(computeProviderHelper.getStorageAccountFromVM(vm));
        ctx.setAvailabilitySetName(computeProviderHelper.getAvailabilitySetNameFromVm(vm));
    } catch (Exception e) {
        LOG.error("VirtualMachine info for VM{} is malformed.", vm.getName(), e);
        return new TaskResult(false, ctx);
    }

    String vmName = vm.getName();
    try {
        // Azure SDK throws ServiceException if VM does not exist in the RG
        computeProviderHelper.getVirtualMachineStatus(resourceGroup, vmName);
    } catch (ServiceException | IOException | URISyntaxException e) {
        LOG.debug("Failed to find VM: {} in resource group: {} due to error, can't delete it.", vmName,
                resourceGroup, e);
        // local context delete will/should take care of the rest
        return new TaskResult(false, ctx);
    }

    LOG.info("Begin deleting VM: {} in resource group: {}.", vm.getName(), resourceGroup);
    int successCount = 0;
    try {
        ComputeOperationResponse response = computeProviderHelper.beginDeleteVirtualMachine(resourceGroup, vm);
        successCount = pollPendingOperation(response, azureOperationPollingTimeout, defaultSleepIntervalInSec,
                LOG, vm.getName());
    } catch (IOException | ServiceException e) {
        LOG.error("Failed to delete VM {}. Please check Azure portal for any not deleted resources.",
                vm.getName(), e);
    } catch (InterruptedException e) {
        LOG.error("Deletion of VM {} is interrupted. Please check Azure portal for any remaining resources.",
                vm.getName(), e);
    }

    if (successCount != 1) {
        return new TaskResult(false, ctx);
    }

    // Delete the rest of the resources in any order should be fine
    OperationResponse result;
    String nicName = computeProviderHelper.getNicNameFromVm(vm);
    try {
        result = computeProviderHelper.beginDeleteNetworkResourcesOnVM(resourceGroup, vm, isPublicIPConfigured);
        LOG.debug("VM: {}. Delete NetworkInterface {} status code: {}.", vmName, nicName,
                result.getStatusCode());
    } catch (IOException | ServiceException | ExecutionException | InterruptedException e) {
        LOG.error("VM: {}. Delete NetworkInterface {} encountered error:", vmName, nicName, e);
    }

    String saName = computeProviderHelper.getStorageAccountFromVM(vm);
    try {
        result = computeProviderHelper.beginDeleteStorageAccountOnVM(resourceGroup, vm);
        LOG.debug("VM: {}. Delete StorageAccount {} status code: {}.", vmName, saName, result.getStatusCode());
    } catch (IOException | ServiceException e) {
        LOG.error("VM: {}. Delete StorageAccount {} encountered error:", vmName, saName, e);
    }

    long timeSeconds = (DateTime.now().getMillis() - startTime.getMillis()) / 1000;
    LOG.info("Delete VM {} and its resources took {} seconds.", vm.getName(), timeSeconds);

    return new TaskResult(true, ctx);
}

From source file:com.cloudera.director.azure.compute.provider.CleanUpTask.java

License:Apache License

/**
 * Delete VM first and then its supporting resources using ResourceContext info.
 *
 * VM may not have been allocated successfully in this case.
 *
 * @return result of CleanUpTask//from   w w w.j a va  2s . c o  m
 */
private TaskResult deleteUsingContextInfo() {
    boolean hasError = false;
    String vmName = "UNKNOWN_VM";

    LOG.debug("Begin clean up with ResourceContext used in VM creation");
    if (context.getVMInput() != null) {
        // Context contains VirtualMachine info, try using it to delete first.
        this.vm = context.getVMInput();
        vmName = vm.getName();
        TaskResult deleteVmResult = deleteUsingVmInfo();

        // VM and its supporting resources deleted, all done.
        if (deleteVmResult.isSuccessful()) {
            LOG.info("VM {} and its resources have been cleaned up.", vmName);
            return deleteVmResult;
        }

        // Fall through and cleanup VM resources (NIC, Public IP, Storage Acct etc.)
    }

    OperationResponse result;
    // clean up individual resources if the above steps failed
    if (context.getStorageAccountName() != null) {
        String saName = context.getStorageAccountName();
        try {
            result = computeProviderHelper.beginDeleteStorageAccountByName(resourceGroup, saName);
            LOG.debug("VM: {}. Delete StorageAccount {} status code: {}.", vmName, saName,
                    result.getStatusCode());
        } catch (IOException | ServiceException e) {
            hasError = true;
            LOG.error("VM: {}. Delete StorageAccount {} failed:", vmName, saName, e);
        }
    }

    if (context.getNetworkInterface() != null) {
        String nicName = context.getNetworkInterfaceName();
        try {
            result = computeProviderHelper.beginDeleteNetworkInterfaceByName(resourceGroup, nicName);
            LOG.debug("VM: {}. Delete NetworkInterface {} status code: {}.", vmName, nicName,
                    result.getStatusCode());
        } catch (IOException | ExecutionException | InterruptedException e) {
            hasError = true;
            LOG.error("VM: {}. Delete NetworkInterface {} encountered error:", vmName, nicName, e);
        }
    }

    if (isPublicIPConfigured && context.getPublicIpAddress() != null) {
        String pip = context.getPublicIpName();
        try {
            result = computeProviderHelper.beginDeletePublicIpAddressByName(resourceGroup, pip);
            LOG.debug("VM: {}. Delete PublicIP {} status code: {}.", vmName, pip, result.getStatusCode());
        } catch (InterruptedException | ExecutionException | IOException e) {
            hasError = true;
            LOG.error("VM: {}. Delete PublicIP {} encountered error:", vmName, pip, e);
        }
    } else {
        LOG.debug(
                "Skipping delete of public IP address: isPublicIPConfigured {}; "
                        + "context.getPublicIpAddress(): {}",
                isPublicIPConfigured, context.getPublicIpAddress());
    }

    long timeSeconds = (DateTime.now().getMillis() - startTime.getMillis()) / 1000;
    LOG.info("Delete VM {} context resources took {} seconds.", vm.getName(), timeSeconds);

    return new TaskResult(!hasError, this.context);
}

From source file:com.cloudera.director.azure.compute.provider.CreateVMTask.java

License:Apache License

public CreateVMTask(ResourceContext context, VmCreationParameters parameters, int azureOperationPollingTimeout,
        AzureComputeProviderHelper computeProviderHelper) {
    this.context = context;
    this.vnet = parameters.getVnet();
    this.nsg = parameters.getNsg();
    this.as = parameters.getAvailabilitySet();
    this.vmSize = parameters.getVmSize();
    this.vmNamePrefix = parameters.getVmNamePrefix();
    this.instanceId = parameters.getInstanceId();
    this.vmName = vmNamePrefix + "-" + instanceId;
    this.fqdnSuffix = parameters.getFqdnSuffix();
    this.adminName = parameters.getAdminName();
    this.sshPublicKey = parameters.getSshPublicKey();
    this.storageAccountType = parameters.getStorageAccountType();
    this.dataDiskCount = parameters.getDataDiskCount();
    this.dataDiskSizeGiB = parameters.getDataDiskSizeGiB();
    this.imageInfo = parameters.getImageInfo();
    this.computeProviderHelper = computeProviderHelper;
    this.startTime = DateTime.now();
    this.subnet = parameters.getSubnet();
    this.azureOperationPollingTimeout = azureOperationPollingTimeout;
}

From source file:com.cloudera.director.azure.compute.provider.CreateVMTask.java

License:Apache License

public TaskResult call() {
    boolean success = false;
    ComputeOperationResponse op;// w  ww . ja  v a2 s . c o  m
    int successCount = 0;

    try {
        requestResources();
        op = computeProviderHelper.submitVmCreationOp(context);
    } catch (Exception e) {
        // AZURE_SDK Catch all exception from Azure SDK calls so that we can always cleanup.
        LOG.error("Failed to create VM {} due to:", vmName, e);
        return new TaskResult(false, this.context);
    }

    try {
        String vmName = context.getVMInput().getName();
        successCount = pollPendingOperation(op, azureOperationPollingTimeout, defaultSleepIntervalInSec, LOG,
                vmName);
    } catch (InterruptedException e) {
        LOG.info("VM {} creation is interrupted.", vmName, e);
        return new TaskResult(false, this.context);
    }

    long timeSeconds = (DateTime.now().getMillis() - startTime.getMillis()) / 1000;

    if (successCount == 1) {
        /* FIXME temporarily disable VM script runner to speed up VM deployment.
        int scriptSuccessCount = pollPendingOperation(computeProviderHelper.createCustomizedScript(context),
            defaultTimeoutInSec, defaultSleepIntervalInSec, LOG);
        if (scriptSuccessCount == 1) {
          LOG.info("Script execution succeeded");
          exitCode = 0;
        }
        */

        success = true;
        LOG.info("Creation of VM {} succeeded after {} seconds.", vmName, timeSeconds);
    } else {
        LOG.error("Creation of VM {} failed after {} seconds.", vmName, timeSeconds);
    }

    return new TaskResult(success, this.context);
}

From source file:com.codio.client.CodioSign.java

License:Apache License

public CodioSign(final String data, final String provider, final String key) {
    this.provider = provider;
    timestamp = Long.toString(DateTime.now().getMillis());
    this.signature = HmacSHA1.calculateHMAC(timestamp + data + provider, key);
}

From source file:com.codio.collab.core.DocumentFactory.java

License:Apache License

public CollabDocument getDocument(final String collection, final String document) {
    final String docId = docId(collection, document);
    accessTime.put(docId, DateTime.now().plusMinutes(10));
    if (documents.containsKey(docId)) {
        return documents.get(docId);
    }/*  w ww  .  j a v  a 2s.c o  m*/
    CollabDocument doc = getRedisDriver().getDocument(collection, document);
    documents.put(docId, doc);
    return doc;
}

From source file:com.cognitivabrasil.repositorio.services.DocumentServiceImpl.java

License:Open Source License

@Override
public void deleteEmpty() {
    DateTime d = DateTime.now();
    List<Document> docs = docRep.findByCreatedLessThanAndActiveIsFalse(d.minusHours(3));
    for (Document doc : docs) {
        deleteFromDatabase(doc);/*from w  w w. ja  v a  2 s. c  om*/
    }
}

From source file:com.cronutils.model.time.generator.EveryFieldValueGenerator.java

License:Apache License

public EveryFieldValueGenerator(CronField cronField) {
    super(cronField);
    log.trace(String.format("processing \"%s\" at %s", cronField.getExpression().asString(), DateTime.now()));
}

From source file:com.cryart.sabbathschool.viewmodel.SSLessonsViewModel.java

License:Open Source License

public void onReadClick() {
    if (ssQuarterlyInfo != null && ssQuarterlyInfo.lessons.size() > 0) {
        DateTime today = DateTime.now().withTimeAtStartOfDay();
        String ssLessonIndex = ssQuarterlyInfo.lessons.get(0).index;

        for (SSLesson ssLesson : ssQuarterlyInfo.lessons) {
            DateTime startDate = DateTimeFormat.forPattern(SSConstants.SS_DATE_FORMAT)
                    .parseDateTime(ssLesson.start_date).withTimeAtStartOfDay();

            DateTime endDate = DateTimeFormat.forPattern(SSConstants.SS_DATE_FORMAT)
                    .parseDateTime(ssLesson.end_date).plusDays(1).withTimeAtStartOfDay();

            if (new Interval(startDate, endDate).contains(today)) {
                ssLessonIndex = ssLesson.index;
                break;
            }//from  w  ww  .ja v a 2 s .c  o m
        }

        Intent ssReadingIntent = new Intent(context, SSReadingActivity.class);
        ssReadingIntent.putExtra(SSConstants.SS_LESSON_INDEX_EXTRA, ssLessonIndex);
        context.startActivity(ssReadingIntent);
    }
}