1818package org .apache .cloudstack .diagnostics ;
1919
2020import java .io .File ;
21+ import java .nio .file .Path ;
22+ import java .nio .file .Paths ;
2123import java .util .ArrayList ;
2224import java .util .List ;
2325import java .util .Map ;
2628import javax .inject .Inject ;
2729import javax .naming .ConfigurationException ;
2830
29- import org .apache .cloudstack .api .command .admin .diagnostics .GetDiagnosticsDataCmd ;
30- import org .apache .cloudstack .api .command .admin .diagnostics .RunDiagnosticsCmd ;
31- import org .apache .cloudstack .diagnostics .fileprocessor .DiagnosticsFilesList ;
32- import org .apache .cloudstack .diagnostics .fileprocessor .DiagnosticsFilesListFactory ;
33- import org .apache .cloudstack .diagnostics .to .DiagnosticsDataObject ;
34- import org .apache .cloudstack .diagnostics .to .DiagnosticsDataTO ;
35- import org .apache .cloudstack .engine .orchestration .service .NetworkOrchestrationService ;
36- import org .apache .cloudstack .engine .subsystem .api .storage .DataObject ;
37- import org .apache .cloudstack .engine .subsystem .api .storage .DataStore ;
38- import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreManager ;
39- import org .apache .cloudstack .engine .subsystem .api .storage .ZoneScope ;
40- import org .apache .cloudstack .framework .config .ConfigKey ;
41- import org .apache .cloudstack .framework .config .Configurable ;
42- import org .apache .cloudstack .managed .context .ManagedContextRunnable ;
43- import org .apache .cloudstack .poll .BackgroundPollManager ;
44- import org .apache .cloudstack .poll .BackgroundPollTask ;
45- import org .apache .cloudstack .storage .NfsMountManager ;
46- import org .apache .cloudstack .storage .image .datastore .ImageStoreEntity ;
47- import org .apache .commons .collections .CollectionUtils ;
48- import org .apache .commons .lang3 .StringUtils ;
49- import org .apache .log4j .Logger ;
50-
5131import com .cloud .agent .AgentManager ;
5232import com .cloud .agent .api .Answer ;
5333import com .cloud .agent .api .routing .NetworkElementCommand ;
5434import com .cloud .agent .api .to .DataTO ;
35+ import com .cloud .dc .DataCenterVO ;
36+ import com .cloud .dc .dao .DataCenterDao ;
5537import com .cloud .event .ActionEvent ;
5638import com .cloud .event .EventTypes ;
5739import com .cloud .exception .InvalidParameterValueException ;
6951import com .cloud .vm .VirtualMachineManager ;
7052import com .cloud .vm .dao .VMInstanceDao ;
7153import com .google .common .base .Strings ;
54+ import org .apache .cloudstack .api .command .admin .diagnostics .GetDiagnosticsDataCmd ;
55+ import org .apache .cloudstack .api .command .admin .diagnostics .RunDiagnosticsCmd ;
56+ import org .apache .cloudstack .diagnostics .fileprocessor .DiagnosticsFilesList ;
57+ import org .apache .cloudstack .diagnostics .fileprocessor .DiagnosticsFilesListFactory ;
58+ import org .apache .cloudstack .diagnostics .to .DiagnosticsDataObject ;
59+ import org .apache .cloudstack .diagnostics .to .DiagnosticsDataTO ;
60+ import org .apache .cloudstack .engine .orchestration .service .NetworkOrchestrationService ;
61+ import org .apache .cloudstack .engine .subsystem .api .storage .DataObject ;
62+ import org .apache .cloudstack .engine .subsystem .api .storage .DataStore ;
63+ import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreManager ;
64+ import org .apache .cloudstack .engine .subsystem .api .storage .ZoneScope ;
65+ import org .apache .cloudstack .framework .config .ConfigKey ;
66+ import org .apache .cloudstack .framework .config .Configurable ;
67+ import org .apache .cloudstack .managed .context .ManagedContextRunnable ;
68+ import org .apache .cloudstack .poll .BackgroundPollManager ;
69+ import org .apache .cloudstack .poll .BackgroundPollTask ;
70+ import org .apache .cloudstack .storage .NfsMountManager ;
71+ import org .apache .cloudstack .storage .image .datastore .ImageStoreEntity ;
72+ import org .apache .commons .collections .CollectionUtils ;
73+ import org .apache .commons .lang3 .StringUtils ;
74+ import org .apache .log4j .Logger ;
7275
7376import static org .apache .cloudstack .diagnostics .DiagnosticsHelper .getTimeDifference ;
77+ import static org .apache .cloudstack .diagnostics .DiagnosticsHelper .setDirFilePermissions ;
7478import static org .apache .cloudstack .diagnostics .DiagnosticsHelper .umountSecondaryStorage ;
7579import static org .apache .cloudstack .diagnostics .fileprocessor .DiagnosticsFilesList .CpvmDefaultSupportedFiles ;
7680import static org .apache .cloudstack .diagnostics .fileprocessor .DiagnosticsFilesList .SsvmDefaultSupportedFiles ;
@@ -97,12 +101,14 @@ public class DiagnosticsServiceImpl extends ManagerBase implements PluggableServ
97101 private ImageStoreDetailsUtil imageStoreDetailsUtil ;
98102 @ Inject
99103 private NfsMountManager mountManager ;
104+ @ Inject
105+ private DataCenterDao dataCenterDao ;
100106
101107 // This 2 settings should require a restart of the management server?
102108 private static final ConfigKey <Boolean > EnableGarbageCollector = new ConfigKey <>("Advanced" , Boolean .class ,
103- "diagnostics.data.gc.enable" , "true" , "enable the diagnostics data files garbage collector" , false );
109+ "diagnostics.data.gc.enable" , "true" , "enable the diagnostics data files garbage collector" , true );
104110 private static final ConfigKey <Integer > GarbageCollectionInterval = new ConfigKey <>("Advanced" , Integer .class ,
105- "diagnostics.data.gc.interval" , "86400" , "garbage collection interval in seconds" , false );
111+ "diagnostics.data.gc.interval" , "86400" , "garbage collection interval in seconds" , true );
106112
107113 // These are easily computed properties and need not need a restart of the management server
108114 private static final ConfigKey <Long > DataRetrievalTimeout = new ConfigKey <>("Advanced" , Long .class ,
@@ -329,6 +335,11 @@ private Pair<Boolean, String> orchestrateCopyToSecondaryStorageVMware(final Data
329335 try {
330336 File dataDirectory = new File (dataDirectoryInSecondaryStore );
331337 boolean existsInSecondaryStore = dataDirectory .exists () || dataDirectory .mkdir ();
338+
339+ // Modify directory file permissions
340+ Path path = Paths .get (dataDirectory .getAbsolutePath ());
341+ setDirFilePermissions (path );
342+
332343 if (existsInSecondaryStore ) {
333344 // scp from system VM to mounted sec storage directory
334345 int port = 3922 ;
@@ -449,7 +460,8 @@ private static void deleteOldDiagnosticsFiles(File directory, String storeName)
449460 for (File file : fileList ) {
450461 if (file .isFile ()) {
451462 if (MaximumFileAgeforGarbageCollection .value () <= getTimeDifference (file )) {
452- file .delete ();
463+ boolean success = file .delete ();
464+ LOGGER .info (file .getName () + " delete status: " + success );
453465 }
454466 }
455467 }
@@ -458,23 +470,26 @@ private static void deleteOldDiagnosticsFiles(File directory, String storeName)
458470
459471 @ Override
460472 protected void runInContext () {
461- // Get All Image Stores in current running Zone
462- List <DataStore > storeList = serviceImpl .storeMgr .listImageStores ();
463-
464- for (DataStore store : storeList ) {
465- String mountPoint = null ;
466- try {
467- mountPoint = serviceImpl .mountManager .getMountPoint (store .getUri (), null );
468- if (StringUtils .isNotBlank (mountPoint )) {
469- File directory = new File (mountPoint + "/" + DIAGNOSTICS_DATA_DIRECTORY );
470- if (directory .isDirectory ()) {
471- deleteOldDiagnosticsFiles (directory , store .getName ());
473+ List <DataCenterVO > dcList = serviceImpl .dataCenterDao .listEnabledZones ();
474+ for (DataCenterVO vo : dcList ) {
475+ // Get All Image Stores in current running Zone
476+ List <DataStore > storeList = serviceImpl .storeMgr .getImageStoresByScope (new ZoneScope (vo .getId ()));
477+ for (DataStore store : storeList ) {
478+ String mountPoint = null ;
479+ try {
480+ mountPoint = serviceImpl .mountManager .getMountPoint (store .getUri (), null );
481+ if (StringUtils .isNotBlank (mountPoint )) {
482+ File directory = new File (mountPoint + "/" + DIAGNOSTICS_DATA_DIRECTORY );
483+ if (directory .isDirectory ()) {
484+ deleteOldDiagnosticsFiles (directory , store .getName ());
485+ }
472486 }
487+ } finally {
488+ // umount secondary storage
489+ umountSecondaryStorage (mountPoint );
473490 }
474- } finally {
475- // umount secondary storage
476- umountSecondaryStorage (mountPoint );
477491 }
492+
478493 }
479494 }
480495
0 commit comments