Search in sources :

Example 16 with ValidationTaskResult

use of alluxio.cli.ValidationTaskResult in project alluxio by Alluxio.

the class CreateHmsClientValidationTask method getValidationWithResult.

/**
 * @return the result of the validation. {@link Pair#getFirst()} will be null if the connection
 * to the metastore was successful, otherwise if there is a failure {@link Pair#getSecond()}
 * will be null
 * @throws InterruptedException if the task is interrupted
 */
protected Pair<ValidationTaskResult, IMetaStoreClient> getValidationWithResult() throws InterruptedException {
    if (mInputTask == null) {
        return new Pair<>(new ValidationTaskResult(ValidationUtils.State.FAILED, getName(), "pre-requisite check on metastore URI failed.", ""), null);
    }
    Pair<ValidationTaskResult, String> inputResult = mInputTask.getValidationWithResult();
    if (inputResult.getFirst().getState() != ValidationUtils.State.OK) {
        return new Pair<>(inputResult.getFirst(), null);
    }
    String metastoreUri = inputResult.getSecond();
    try {
        ConnectHmsAction action;
        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            // Use the extension class loader
            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
            HiveConf conf = new HiveConf();
            conf.setVar(HiveConf.ConfVars.METASTOREURIS, metastoreUri);
            conf.setIntVar(HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT, mSocketTimeoutSeconds);
            action = new ConnectHmsAction(conf);
            UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
            ugi.doAs(action);
        } finally {
            Thread.currentThread().setContextClassLoader(currentClassLoader);
        }
        return new Pair<>(new ValidationTaskResult(ValidationUtils.State.OK, getName(), "Metastore connection successful", ""), action.getConnection());
    } catch (UndeclaredThrowableException e) {
        if (e.getUndeclaredThrowable() instanceof IMetaStoreClient.IncompatibleMetastoreException) {
            return new Pair<>(new ValidationTaskResult(ValidationUtils.State.FAILED, getName(), ValidationUtils.getErrorInfo(e), String.format("Hive metastore client (version: %s) is incompatible with " + "your Hive Metastore server version", IMetaStoreClient.class.getPackage().getImplementationVersion())), null);
        } else {
            return new Pair<>(new ValidationTaskResult(ValidationUtils.State.FAILED, getName(), ValidationUtils.getErrorInfo(e), "Failed to create hive metastore client. " + "Please check if the given hive metastore uris is valid and reachable"), null);
        }
    } catch (InterruptedException e) {
        return new Pair<>(new ValidationTaskResult(ValidationUtils.State.FAILED, getName(), ValidationUtils.getErrorInfo(e), "Hive metastore client creation is interrupted. Please rerun the test if needed"), null);
    } catch (Throwable t) {
        String errorInfo = ValidationUtils.getErrorInfo(t);
        ValidationTaskResult result = new ValidationTaskResult().setState(ValidationUtils.State.FAILED).setName(getName()).setOutput(errorInfo);
        if (errorInfo.contains("Could not connect to meta store using any of the URIs provided")) {
            // Happens when the hms port is reachable but not the actual hms port
            // Thrown as RuntimeException with this error message
            result.setAdvice("Failed to create hive metastore client. " + "Please check if the given hive metastore uri(s) is valid and reachable");
        } else {
            result.setAdvice("Failed to create hive metastore client");
        }
        return new Pair<>(result, null);
    }
}
Also used : IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) ValidationTaskResult(alluxio.cli.ValidationTaskResult) Pair(alluxio.collections.Pair) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 17 with ValidationTaskResult

use of alluxio.cli.ValidationTaskResult in project alluxio by Alluxio.

the class ManagerProcessContextTest method testConvertValidationResult.

@Test
public void testConvertValidationResult() {
    Map<ValidationUtils.State, List<ValidationTaskResult>> res = new HashMap<>();
    List<ValidationTaskResult> results = new ArrayList<>();
    results.add(new ValidationTaskResult().setName("test1").setState(ValidationUtils.State.FAILED).setDesc("aaaa").setOutput("bbbb").setAdvice("adv1"));
    List<ValidationTaskResult> results2 = new ArrayList<>();
    results2.add(new ValidationTaskResult().setName("test2").setState(ValidationUtils.State.SKIPPED).setDesc("cccc").setOutput("dddd").setOutput("out2").setAdvice("adv2"));
    res.put(ValidationUtils.State.FAILED, results);
    res.put(ValidationUtils.State.SKIPPED, results2);
    List<ValidationResult> conv = HubUtil.convertValidationResult(res);
    assertEquals(2, conv.size());
    assertEquals(1, conv.stream().filter(f -> f.getName().equals("test1")).count());
    assertEquals(1, conv.stream().filter(f -> f.getName().equals("test2")).count());
    ValidationResult t1 = conv.stream().filter(f -> f.getName().equals("test1")).findAny().orElseThrow(() -> new RuntimeException("Didn't have test1 object"));
    assertEquals(ValidationStatus.FAILED, t1.getTestResult());
    assertEquals("adv1", t1.getAdvice());
    assertEquals("aaaa", t1.getDescription());
    assertEquals("bbbb", t1.getOutput());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ValidationResult(alluxio.hub.proto.ValidationResult) ValidationTaskResult(alluxio.cli.ValidationTaskResult) BaseHubTest(alluxio.hub.test.BaseHubTest) Test(org.junit.Test)

Example 18 with ValidationTaskResult

use of alluxio.cli.ValidationTaskResult in project alluxio by Alluxio.

the class HdfsVersionValidationTask method validateImpl.

@Override
public ValidationTaskResult validateImpl(Map<String, String> optionMap) throws InterruptedException {
    String hadoopVersion;
    try {
        hadoopVersion = getHadoopVersion();
    } catch (IOException e) {
        return new ValidationTaskResult(ValidationUtils.State.FAILED, getName(), String.format("Failed to get hadoop version:%n%s.", ValidationUtils.getErrorInfo(e)), "Please check if hadoop is on your PATH.");
    }
    String version = mConf.getString(PropertyKey.UNDERFS_VERSION);
    for (String prefix : new String[] { CDH_PREFIX, HADOOP_PREFIX }) {
        if (version.startsWith(prefix)) {
            version = version.substring(prefix.length());
            break;
        }
    }
    if (hadoopVersion.contains(version)) {
        return new ValidationTaskResult(ValidationUtils.State.OK, getName(), String.format("Hadoop version %s contains UFS version defined in alluxio %s=%s.", hadoopVersion, PropertyKey.UNDERFS_VERSION, version), "");
    }
    return new ValidationTaskResult(ValidationUtils.State.FAILED, getName(), String.format("Hadoop version %s does not match %s=%s.", hadoopVersion, PropertyKey.UNDERFS_VERSION, version), String.format("Please configure %s to match the HDFS version.", PropertyKey.UNDERFS_VERSION));
}
Also used : IOException(java.io.IOException) ValidationTaskResult(alluxio.cli.ValidationTaskResult)

Example 19 with ValidationTaskResult

use of alluxio.cli.ValidationTaskResult in project alluxio by Alluxio.

the class SecureHdfsValidationTask method validateImpl.

@Override
public ValidationTaskResult validateImpl(Map<String, String> optionsMap) {
    if (!ValidationUtils.isHdfsScheme(mPath)) {
        mMsg.append("Skip this check as the UFS is not HDFS.\n");
        return new ValidationTaskResult(ValidationUtils.State.SKIPPED, getName(), mMsg.toString(), mAdvice.toString());
    }
    // superclass which uses its own msg and advice objects
    ValidationTaskResult loadConfig = loadHdfsConfig();
    if (loadConfig.getState() != ValidationUtils.State.OK) {
        String extraAdvice = "Validating a secure HDFS connection requires specifying additional " + "HDFS configuration files. ";
        return loadConfig.setAdvice(extraAdvice + loadConfig.getAdvice());
    }
    // The state is OK when the HDFS is secured
    ValidationTaskResult hdfsSecured = validateSecureHdfs();
    if (hdfsSecured.getState() != ValidationUtils.State.OK) {
        return hdfsSecured;
    }
    return validatePrincipalLogin();
}
Also used : ValidationTaskResult(alluxio.cli.ValidationTaskResult)

Example 20 with ValidationTaskResult

use of alluxio.cli.ValidationTaskResult in project alluxio by Alluxio.

the class SecureHdfsValidationTask method validatePrincipalLogin.

private ValidationTaskResult validatePrincipalLogin() {
    String principal = (String) mConf.getOrDefault(mPrincipalProperty, "");
    String keytab = (String) mConf.getOrDefault(mKeytabProperty, "");
    if (principal.isEmpty() || keytab.isEmpty()) {
        mMsg.append(String.format("Failed to find Kerberos principal and keytab. " + "Found %s=%s and %s=%s.%n", mPrincipalProperty.toString(), principal, mKeytabProperty, keytab));
        mAdvice.append(String.format("Please configure Alluxio to connect with secure HDFS " + "following %s%n", DOC_LINK));
        return new ValidationTaskResult(ValidationUtils.State.FAILED, getName(), mMsg.toString(), mAdvice.toString());
    }
    // Check whether can login with specified principal and keytab
    Matcher matchPrincipal = PRINCIPAL_PATTERN.matcher(principal);
    if (!matchPrincipal.matches()) {
        mMsg.append(String.format("Principal %s is not in the right format.%n", principal));
        mAdvice.append(String.format("Please fix principal %s=%s.%n", mPrincipalProperty.toString(), principal));
        return new ValidationTaskResult(ValidationUtils.State.FAILED, getName(), mMsg.toString(), mAdvice.toString());
    }
    String primary = matchPrincipal.group("primary");
    String instance = matchPrincipal.group("instance");
    String realm = matchPrincipal.group("realm");
    // Login with principal and keytab
    String[] command = new String[] { "kinit", "-kt", keytab, principal };
    try {
        String output = ShellUtils.execCommand(command);
        mMsg.append(String.format("Command %s finished with output: %s%n", Arrays.toString(command), output));
        return new ValidationTaskResult(ValidationUtils.State.OK, getName(), mMsg.toString(), mAdvice.toString());
    } catch (IOException e) {
        mMsg.append(String.format("Kerberos login failed for %s with keytab %s.%n", principal, keytab));
        mMsg.append(ValidationUtils.getErrorInfo(e));
        mMsg.append(String.format("Primary is %s, instance is %s and realm is %s.%n", primary, instance, realm));
        ValidationTaskResult result = new ValidationTaskResult(ValidationUtils.State.FAILED, getName(), mMsg.toString(), mAdvice.toString());
        return result;
    }
}
Also used : Matcher(java.util.regex.Matcher) IOException(java.io.IOException) ValidationTaskResult(alluxio.cli.ValidationTaskResult)

Aggregations

ValidationTaskResult (alluxio.cli.ValidationTaskResult)28 Test (org.junit.Test)19 StringContains.containsString (org.hamcrest.core.StringContains.containsString)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Pair (alluxio.collections.Pair)4 IOException (java.io.IOException)3 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)3 List (java.util.List)2 AbstractValidationTask (alluxio.cli.AbstractValidationTask)1 ApplicableUfsType (alluxio.cli.ApplicableUfsType)1 ValidationUtils (alluxio.cli.ValidationUtils)1 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)1 PropertyKey (alluxio.conf.PropertyKey)1 InvalidPathException (alluxio.exception.InvalidPathException)1 ValidationResult (alluxio.hub.proto.ValidationResult)1 BaseHubTest (alluxio.hub.test.BaseHubTest)1 PathUtils (alluxio.util.io.PathUtils)1 RandomAccessFile (java.io.RandomAccessFile)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 URI (java.net.URI)1