Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Can you help me work cache activation?

Avatar

Level 4

Hello Everyone,

I have implemented executeCurlCommand using curl command to delete / activate cache.

Now cache deletion works well.

But cache activation doesn't work.

I have no idea why.

If you are availabe, can you help me work cache activation?

Here are my source code to delete / activate cache using curl command.

-------------------------------------------------------------------

public static final String DISPATCHER_HEADER_CQ_ACTION = "CQ-Action";

public static final String DISPATCHER_HEADER_CQ_HANDLE = "CQ-Handle";
public static final String DISPATCHER_HEADER_CQ_PATH = "CQ-Path";
public static final String DISPATCHER_HEADER_CONTENT_LENGTH = "Content-Length";
public static final String DISPATCHER_HEADER_CONTENT_TYPE = "Content-Type";
public static final String DISPATCHER_HEADER_CONTENT_TYPE_VALUE = "application/octet-stream";

public static void execute(BundleContext bundleContext, Event event) {

        if (bundleContext != null && event != null) {

            final ServiceReference rrServiceReference = bundleContext.getServiceReference(ResourceResolverFactory.class.getName());

            final ResourceResolverFactory resolverFactory = (ResourceResolverFactory) bundleContext.getService(rrServiceReference);

            final ResourceResolver resolver = AdminService.getResourceResolver(resolverFactory);

            final ReplicationAction replicationAction = ReplicationEvent.fromEvent(event).getReplicationAction();

            final ReplicationActionType replicationActionType = replicationAction.getType();

            if (replicationActionType.equals(ReplicationActionType.ACTIVATE)) {

                executeCurlCommand(getDispatcherUris(resolver), replicationAction.getPaths(), ReplicationActionType.DELETE);

                executeCurlCommand(getDispatcherUris(resolver), replicationAction.getPaths(), ReplicationActionType.ACTIVATE);

            } else if (replicationActionType.equals(ReplicationActionType.DEACTIVATE) ||

                    replicationActionType.equals(ReplicationActionType.DELETE)) {

                executeCurlCommand(getDispatcherUris(resolver), replicationAction.getPaths(), ReplicationActionType.DELETE);

            }

        }

}

private static void executeCurlCommand(List<String> dispatchers, String[] paths, ReplicationActionType methodType) {

        for (String path : paths) {

            for (String dispatcher : dispatchers) {

                String[] command = {

                        "curl",

                        "-H", Constants.DISPATCHER_HEADER_CQ_ACTION + ": " + methodType.getName(),

                        "-H", Constants.DISPATCHER_HEADER_CQ_HANDLE + ": " + path,

                        "-H", Constants.DISPATCHER_HEADER_CQ_PATH   + ": " + path,

                        "-H", Constants.DISPATCHER_HEADER_CONTENT_LENGTH + ": " + "0",

                        "-H", Constants.DISPATCHER_HEADER_CONTENT_TYPE + ": " + Constants.DISPATCHER_HEADER_CONTENT_TYPE_VALUE ,

                        dispatcher

                };

                try

                {

                    ProcessBuilder process = new ProcessBuilder(command);

                    process.start();

                }

                catch (IOException e) {

                    log.error(e.getMessage(), e);

                }

            }

        }

}

13 Replies