-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#10605] Added cleanup inactive applications batch job
- Loading branch information
Showing
15 changed files
with
564 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
batch/src/main/java/com/navercorp/pinpoint/batch/common/StartupJobLauncher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2024 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.pinpoint.batch.common; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.beans.factory.DisposableBean; | ||
import org.springframework.beans.factory.InitializingBean; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
/** | ||
* @author youngjin.kim2 | ||
*/ | ||
public class StartupJobLauncher implements InitializingBean, DisposableBean { | ||
|
||
private static final Logger logger = LogManager.getLogger(StartupJobLauncher.class); | ||
|
||
private final BatchJobLauncher launcher; | ||
private final List<String> jobs; | ||
|
||
private final ExecutorService executor = Executors.newSingleThreadExecutor(); | ||
|
||
public StartupJobLauncher(BatchJobLauncher launcher, List<String> jobs) { | ||
this.launcher = Objects.requireNonNull(launcher, "launcher"); | ||
this.jobs = Objects.requireNonNull(jobs, "jobs"); | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() { | ||
if (this.jobs.isEmpty()) { | ||
logger.info("No startup jobs to launch"); | ||
return; | ||
} | ||
|
||
logger.info("Startup job launcher started"); | ||
this.executor.execute(() -> { | ||
for (String job : jobs) { | ||
logger.info("Launching job {}", job); | ||
launcher.run(job, BatchJobLauncher.createTimeParameter()); | ||
} | ||
logger.info("Startup job launcher finished"); | ||
}); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
this.executor.shutdownNow(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...java/com/navercorp/pinpoint/batch/configuration/CleanupInactiveApplicationsJobConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2024 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.pinpoint.batch.configuration; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.ImportResource; | ||
|
||
/** | ||
* @author youngjin.kim2 | ||
*/ | ||
@ImportResource({ "classpath:job/applicationContext-cleanupInactiveApplicationsJob.xml" }) | ||
@Configuration(proxyBeanMethods = false) | ||
public class CleanupInactiveApplicationsJobConfig { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
batch/src/main/java/com/navercorp/pinpoint/batch/job/ApplicationEmptyFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2024 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.pinpoint.batch.job; | ||
|
||
import com.navercorp.pinpoint.batch.service.ApplicationService; | ||
import jakarta.annotation.Nonnull; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.springframework.batch.item.ItemProcessor; | ||
|
||
import java.time.Duration; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author youngjin.kim2 | ||
*/ | ||
public class ApplicationEmptyFilter implements ItemProcessor<String, String> { | ||
|
||
private static final Logger logger = LogManager.getLogger(ApplicationEmptyFilter.class); | ||
|
||
private final ApplicationService applicationService; | ||
private final Duration emptyDurationThreshold; | ||
|
||
public ApplicationEmptyFilter(ApplicationService applicationService, Duration emptyDurationThreshold) { | ||
this.applicationService = Objects.requireNonNull(applicationService, "applicationService"); | ||
this.emptyDurationThreshold = Objects.requireNonNull(emptyDurationThreshold, "emptyDurationThreshold"); | ||
} | ||
|
||
@Override | ||
public String process(@Nonnull String s) throws Exception { | ||
if (isApplicationEmpty(s)) { | ||
logger.info("Application is empty: {}", s); | ||
return s; | ||
} else { | ||
logger.info("Application is not empty: {}", s); | ||
return null; | ||
} | ||
} | ||
|
||
private boolean isApplicationEmpty(String applicationName) { | ||
return this.applicationService.isApplicationEmpty(applicationName, this.emptyDurationThreshold); | ||
} | ||
} |
Oops, something went wrong.