Skip to content

Commit e021864

Browse files
committed
changes
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 9848586 commit e021864

6 files changed

Lines changed: 383 additions & 42 deletions

File tree

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ public class EventTypes {
844844
public static final String EVENT_EXTENSION_CREATE = "EXTENSION.CREATE";
845845
public static final String EVENT_EXTENSION_UPDATE = "EXTENSION.UPDATE";
846846
public static final String EVENT_EXTENSION_DELETE = "EXTENSION.DELETE";
847+
public static final String EVENT_EXTENSION_SYNC = "EXTENSION.SYNC";
847848
public static final String EVENT_EXTENSION_RESOURCE_REGISTER = "EXTENSION.RESOURCE.REGISTER";
848849
public static final String EVENT_EXTENSION_RESOURCE_UNREGISTER = "EXTENSION.RESOURCE.UNREGISTER";
849850
public static final String EVENT_EXTENSION_CUSTOM_ACTION_ADD = "EXTENSION.CUSTOM.ACTION.ADD";

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/api/SyncExtensionCmd.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.cloudstack.api.ApiCommandResourceType;
2727
import org.apache.cloudstack.api.ApiConstants;
2828
import org.apache.cloudstack.api.ApiErrorCode;
29+
import org.apache.cloudstack.api.BaseAsyncCmd;
2930
import org.apache.cloudstack.api.BaseCmd;
3031
import org.apache.cloudstack.api.Parameter;
3132
import org.apache.cloudstack.api.ServerApiException;
@@ -35,6 +36,7 @@
3536
import org.apache.cloudstack.extension.Extension;
3637
import org.apache.cloudstack.framework.extensions.manager.ExtensionsManager;
3738

39+
import com.cloud.event.EventTypes;
3840
import com.cloud.exception.ConcurrentOperationException;
3941
import com.cloud.user.Account;
4042

@@ -45,7 +47,7 @@
4547
entityType = {Extension.class},
4648
authorized = {RoleType.Admin},
4749
since = "4.23.0")
48-
public class SyncExtensionCmd extends BaseCmd {
50+
public class SyncExtensionCmd extends BaseAsyncCmd {
4951

5052
@Inject
5153
ExtensionsManager extensionsManager;
@@ -124,4 +126,14 @@ public ApiCommandResourceType getApiResourceType() {
124126
public Long getApiResourceId() {
125127
return getId();
126128
}
129+
130+
@Override
131+
public String getEventType() {
132+
return EventTypes.EVENT_EXTENSION_SYNC;
133+
}
134+
135+
@Override
136+
public String getEventDescription() {
137+
return "Sync extension: " + getId();
138+
}
127139
}

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsManagerImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ protected void checkOrchestratorTemplates(Long extensionId) {
539539
}
540540
}
541541

542+
protected void checkExtensionPathState(Extension extension) {
543+
List<ManagementServerHostVO> msList = managementServerHostDao.listBy(ManagementServerHost.State.Up);
544+
msList.removeIf(ms -> ms.getMsid() == ManagementServerNode.getManagementServerId());
545+
checkExtensionPathState(extension, msList);
546+
}
547+
542548
protected void checkExtensionPathState(Extension extension, List<ManagementServerHostVO> msHosts) {
543549
String checksum = extensionsFilesystemManager.getChecksumForExtensionPath(extension.getName(),
544550
extension.getRelativePath());
@@ -1704,6 +1710,8 @@ public boolean syncExtension(SyncExtensionCmd cmd) {
17041710
throw new CloudRuntimeException(String.format("Failed to sync extension '%s' via '%s': %s",
17051711
extension.getName(), sourceManagementServer.getName(), result.second()));
17061712
}
1713+
1714+
checkExtensionPathState(extension);
17071715
return true;
17081716
}
17091717

framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsShareManagerImpl.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,31 @@ protected void applyExtensionSync(Extension extension, DownloadAndSyncExtensionF
375375
FileUtil.deleteRecursively(applyRoot);
376376
}
377377

378+
protected void cleanupExtensionsShareFiles(long cutoff) throws IOException {
379+
Path sharePath = getExtensionsSharePath();
380+
if (!Files.exists(sharePath) || !Files.isDirectory(sharePath)) {
381+
return;
382+
}
383+
try (Stream<Path> paths = Files.list(sharePath)) {
384+
paths.filter(p -> p.getFileName().toString().endsWith(".tgz"))
385+
.filter(p -> {
386+
try {
387+
return Files.getLastModifiedTime(p).toMillis() < cutoff;
388+
} catch (IOException e) {
389+
return false;
390+
}
391+
})
392+
.forEach(p -> {
393+
try {
394+
Files.delete(p);
395+
logger.debug("Deleted expired extension archive {}", p);
396+
} catch (IOException e) {
397+
logger.warn("Failed to delete expired extension archive {}", p, e);
398+
}
399+
});
400+
}
401+
}
402+
378403
@Override
379404
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
380405
try {
@@ -504,32 +529,9 @@ public ArchiveInfo(Path path, long size, String checksum,
504529
protected class ShareCleanupWorker extends ManagedContextRunnable {
505530
protected void reallyRun() {
506531
try {
507-
Path sharePath = getExtensionsSharePath();
508-
if (Files.exists(sharePath) && Files.isDirectory(sharePath)) {
509-
return;
510-
}
511532
long expiryMillis = shareLinkValidityInterval * 1100L;
512533
long cutoff = System.currentTimeMillis() - expiryMillis;
513-
try (Stream<Path> paths = Files.list(sharePath)) {
514-
paths.filter(p -> p.getFileName().toString().endsWith(".tgz"))
515-
.filter(p -> {
516-
try {
517-
return Files.getLastModifiedTime(p).toMillis() < cutoff;
518-
} catch (IOException e) {
519-
return false;
520-
}
521-
})
522-
.forEach(p -> {
523-
try {
524-
Files.delete(p);
525-
logger.debug("Deleted expired extension archive {}", p);
526-
} catch (IOException e) {
527-
logger.warn("Failed to delete expired extension archive {}", p, e);
528-
}
529-
});
530-
} catch (IOException e) {
531-
logger.warn("Failed to list extension share archives for cleanup", e);
532-
}
534+
cleanupExtensionsShareFiles(cutoff);
533535
} catch (Exception e) {
534536
logger.warn("Extensions share cleanup failed", e);
535537
}

0 commit comments

Comments
 (0)