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);
}
}
}
Aggregations