Search in sources :

Example 1 with AirflowDag

use of io.hops.hopsworks.common.dao.airflow.AirflowDag in project hopsworks by logicalclocks.

the class AirflowManager method cleanStaleSecurityMaterial.

private void cleanStaleSecurityMaterial() {
    Iterator<AirflowJWT> airflowJWTsIt = airflowJWTs.iterator();
    while (airflowJWTsIt.hasNext()) {
        AirflowJWT nextElement = airflowJWTsIt.next();
        try {
            MaterializedJWTID materialId = new MaterializedJWTID(nextElement.projectId, nextElement.uid, MaterializedJWTID.USAGE.AIRFLOW);
            MaterializedJWT airflowMaterial = materializedJWTFacade.findById(materialId);
            boolean shouldDelete = true;
            if (airflowMaterial != null) {
                List<AirflowDag> ownedDags = airflowDagFacade.filterByOwner(nextElement.username);
                for (AirflowDag dag : ownedDags) {
                    if (!dag.getPaused()) {
                        shouldDelete = false;
                        break;
                    }
                }
            }
            if (shouldDelete) {
                certificateMaterializer.removeCertificatesLocalCustomDir(nextElement.username, nextElement.projectName, getProjectSecretsDirectory(nextElement.username).toString());
                FileUtils.deleteQuietly(nextElement.tokenFile.toFile());
                airflowJWTsIt.remove();
                if (airflowMaterial != null) {
                    deleteAirflowMaterial(materialId);
                }
                deleteDirectoryIfEmpty(nextElement.tokenFile.getParent());
            }
        } catch (Exception ex) {
            // Catch everything here. We don't want the timer thread to get killed (expunging timer)
            // Be on the safe side and renew the token
            LOG.log(Level.WARNING, "Could not determine if token " + nextElement + " is stale. It will be renewed!", ex);
        }
    }
}
Also used : MaterializedJWTID(io.hops.hopsworks.persistence.entity.airflow.MaterializedJWTID) AirflowDag(io.hops.hopsworks.common.dao.airflow.AirflowDag) MaterializedJWT(io.hops.hopsworks.persistence.entity.airflow.MaterializedJWT) GeneralSecurityException(java.security.GeneralSecurityException) JWTDecodeException(com.auth0.jwt.exceptions.JWTDecodeException) SQLException(java.sql.SQLException) AirflowException(io.hops.hopsworks.exceptions.AirflowException) IOException(java.io.IOException) JWTException(io.hops.hopsworks.jwt.exception.JWTException) InvalidationException(io.hops.hopsworks.jwt.exception.InvalidationException)

Aggregations

JWTDecodeException (com.auth0.jwt.exceptions.JWTDecodeException)1 AirflowDag (io.hops.hopsworks.common.dao.airflow.AirflowDag)1 AirflowException (io.hops.hopsworks.exceptions.AirflowException)1 InvalidationException (io.hops.hopsworks.jwt.exception.InvalidationException)1 JWTException (io.hops.hopsworks.jwt.exception.JWTException)1 MaterializedJWT (io.hops.hopsworks.persistence.entity.airflow.MaterializedJWT)1 MaterializedJWTID (io.hops.hopsworks.persistence.entity.airflow.MaterializedJWTID)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 SQLException (java.sql.SQLException)1