<commit_before>package com.sequenceiq.cloudbreak.service.stack.connector.azure;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.sequenceiq.cloudbreak.service.StackBasedStatusCheckerTask;

@Component
public class AzureMetadataSetupCheckerTask extends StackBasedStatusCheckerTask<AzureMetadataSetupCheckerTaskContext> {

    private static final Logger LOGGER = LoggerFactory.getLogger(AzureMetadataSetupCheckerTask.class);

    @Override
    public boolean checkStatus(AzureMetadataSetupCheckerTaskContext azureMetadataSetupCheckerTaskContext) {
        try {
            azureMetadataSetupCheckerTaskContext.getAzureClient().getVirtualMachine(azureMetadataSetupCheckerTaskContext.getProps());
            return true;
        } catch (Exception ex) {
            return false;
        }
    }

    @Override
    public void handleTimeout(AzureMetadataSetupCheckerTaskContext azureMetadataSetupCheckerTaskContext) {
        String message = String.format("Azure Virtualmachine with name: %s is not available; operation timed out.",
                azureMetadataSetupCheckerTaskContext.getProps().get(AzureStackUtil.NAME));
        LOGGER.error(message);
        throw new AzureResourceException(message);
    }<commit_msg>log warning if virtual machine on azure is not available for metadata setup<commit_after>package com.sequenceiq.cloudbreak.service.stack.connector.azure;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.sequenceiq.cloudbreak.service.StackBasedStatusCheckerTask;

import groovyx.net.http.HttpResponseException;

@Component
public class AzureMetadataSetupCheckerTask extends StackBasedStatusCheckerTask<AzureMetadataSetupCheckerTaskContext> {

    private static final Logger LOGGER = LoggerFactory.getLogger(AzureMetadataSetupCheckerTask.class);

    @Override
    public boolean checkStatus(AzureMetadataSetupCheckerTaskContext azureMetadataSetupCheckerTaskContext) {
        try {
            azureMetadataSetupCheckerTaskContext.getAzureClient().getVirtualMachine(azureMetadataSetupCheckerTaskContext.getProps());
            return true;
        } catch (Exception ex) {
            if (ex instanceof HttpResponseException) {
                HttpResponseException e = (HttpResponseException) ex;
                String message = "";
                if (e.getResponse() != null && e.getResponse().getData() != null) {
                    message = e.getResponse().getData().toString();
                }
                LOGGER.warn("Virtual machine is not yet available: {}, status code: {}, message: {}", e.getMessage(), e.getStatusCode(), message);
            } else {
                LOGGER.warn("Virtual machine is not yet available: {}", ex.getMessage());
            }
            return false;
        }
    }

    @Override
    public void handleTimeout(AzureMetadataSetupCheckerTaskContext azureMetadataSetupCheckerTaskContext) {
        String message = String.format("Azure Virtualmachine with name: %s is not available; operation timed out.",
                azureMetadataSetupCheckerTaskContext.getProps().get(AzureStackUtil.NAME));
        LOGGER.error(message);
        throw new AzureResourceException(message);
    }
{'fraction_non_alphanumeric': 0.08035172832019406, 'fraction_numerical': 0.001212856276531231, 'mean_word_length': 3.726361031518625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6102443', 'n_tokens_mistral': 791, 'n_tokens_neox': 804, 'n_words': 169}