This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.distribution.api-0.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-api.git
commit bd3ed77de20042086a4d327f8d636ba307734959 Author: Tommaso Teofili <[email protected]> AuthorDate: Fri Nov 7 15:52:52 2014 +0000 SLING-4144 - split distribution api and core bundles git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/distribution/api@1637392 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 129 ++++++++ .../distribution/agent/DistributionAgent.java | 70 +++++ .../agent/DistributionAgentException.java | 34 +++ .../DistributionRequestAuthorizationException.java | 28 ++ .../DistributionRequestAuthorizationStrategy.java | 43 +++ .../sling/distribution/agent/package-info.java | 24 ++ .../communication/DistributionActionType.java | 83 ++++++ .../communication/DistributionParameter.java | 41 +++ .../communication/DistributionRequest.java | 80 +++++ .../communication/DistributionResponse.java | 47 +++ .../distribution/communication/package-info.java | 24 ++ .../component/DistributionComponent.java | 31 ++ .../component/DistributionComponentFactory.java | 331 +++++++++++++++++++++ .../component/DistributionComponentProvider.java | 48 +++ .../component/ManagedDistributionComponent.java | 40 +++ .../sling/distribution/component/package-info.java | 24 ++ .../distribution/event/DistributionEvent.java | 45 +++ .../distribution/event/DistributionEventType.java | 66 ++++ .../sling/distribution/event/package-info.java | 24 ++ .../packaging/DistributionPackage.java | 101 +++++++ .../DistributionPackageExportException.java | 34 +++ .../packaging/DistributionPackageExporter.java | 59 ++++ .../DistributionPackageImportException.java | 38 +++ .../packaging/DistributionPackageImporter.java | 57 ++++ .../packaging/DistributionPackageInfo.java | 56 ++++ .../packaging/SharedDistributionPackage.java | 43 +++ .../sling/distribution/packaging/package-info.java | 24 ++ .../distribution/queue/DistributionQueue.java | 92 ++++++ .../DistributionQueueDistributionStrategy.java | 55 ++++ .../queue/DistributionQueueException.java | 34 +++ .../distribution/queue/DistributionQueueItem.java | 69 +++++ .../queue/DistributionQueueItemSelector.java | 53 ++++ .../queue/DistributionQueueItemState.java | 77 +++++ .../queue/DistributionQueueProcessor.java | 39 +++ .../queue/DistributionQueueProvider.java | 55 ++++ .../sling/distribution/queue/package-info.java | 24 ++ .../TransportAuthenticationContext.java | 40 +++ .../TransportAuthenticationException.java | 35 +++ .../TransportAuthenticationProvider.java | 58 ++++ .../transport/authentication/package-info.java | 24 ++ .../trigger/DistributionRequestHandler.java | 40 +++ .../distribution/trigger/DistributionTrigger.java | 51 ++++ .../trigger/DistributionTriggerException.java | 33 ++ .../sling/distribution/trigger/package-info.java | 24 ++ 44 files changed, 2427 insertions(+) diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..0a5ef8f --- /dev/null +++ b/pom.xml @@ -0,0 +1,129 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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 or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <!-- ======================================================================= --> + <!-- P A R E N T P R O J E C T --> + <!-- ======================================================================= --> + <parent> + <groupId>org.apache.sling</groupId> + <artifactId>sling</artifactId> + <version>22</version> + </parent> + + <!-- ======================================================================= --> + <!-- P R O J E C T --> + <!-- ======================================================================= --> + <artifactId>org.apache.sling.distribution.api</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>bundle</packaging> + + <name>Apache Sling Distribution API</name> + <description> + The Apache Sling Distribution API bundle provides the APIs for the Sling Content Distribution module + </description> + + <scm> + <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/distribution/api</connection> + <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/distribution/api + </developerConnection> + <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/api</url> + </scm> + + <!-- ======================================================================= --> + <!-- B U I L D --> + <!-- ======================================================================= --> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.sling</groupId> + <artifactId>maven-sling-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>org.apache.sling.distribution.api</Bundle-SymbolicName> + <Export-Package> + org.apache.sling.distribution.component, + org.apache.sling.distribution.agent, + org.apache.sling.distribution.communication, + org.apache.sling.distribution.event, + org.apache.sling.distribution.queue, + org.apache.sling.distribution.trigger, + org.apache.sling.distribution.packaging, + org.apache.sling.distribution.transport.authentication + </Export-Package> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + </plugin> + </plugins> + </build> + + <!-- ======================================================================= --> + <!-- D E P E N D E N C I E S --> + <!-- ======================================================================= --> + <dependencies> + <!-- SLING --> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.api</artifactId> + <version>2.5.0</version> + </dependency> + + <!-- SPECs --> + <dependency> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + <dependency> + <groupId>com.google.code.findbugs</groupId> + <artifactId>jsr305</artifactId> + <version>2.0.0</version> + <scope>provided</scope> + </dependency> + + </dependencies> + +</project> diff --git a/src/main/java/org/apache/sling/distribution/agent/DistributionAgent.java b/src/main/java/org/apache/sling/distribution/agent/DistributionAgent.java new file mode 100644 index 0000000..1dbe7d4 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/agent/DistributionAgent.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.agent; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import aQute.bnd.annotation.ProviderType; +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.distribution.communication.DistributionRequest; +import org.apache.sling.distribution.communication.DistributionResponse; +import org.apache.sling.distribution.component.DistributionComponent; +import org.apache.sling.distribution.queue.DistributionQueue; + +/** + * A distribution agent is responsible for handling {@link org.apache.sling.distribution.communication.DistributionRequest}s. + * <p/> + * This means executing actions of e.g.: a specific {@link org.apache.sling.distribution.communication.DistributionActionType}s on + * specific path(s) which will resume pulling resources from a certain Sling instance and / or pushing resources to + * other instances. + */ +@ProviderType +public interface DistributionAgent extends DistributionComponent { + + + /** + * retrieves the names of the queues for this agent. + * @return the list of queue names + */ + Iterable<String> getQueueNames(); + + /** + * get the agent queue with the given name + * + * @param name a queue name + * @return a {@link org.apache.sling.distribution.queue.DistributionQueue} with the given name bound to this agent, if it exists, <code>null</code> otherwise + * @throws DistributionAgentException if an error occurs in retrieving the queue + */ + @CheckForNull + DistributionQueue getQueue(@Nullable String name) throws DistributionAgentException; + + /** + * executes a {@link org.apache.sling.distribution.communication.DistributionRequest} + * + * @param distributionRequest the distribution request + * @param resourceResolver the resource resolver used for authenticating the request, + * @return a {@link org.apache.sling.distribution.communication.DistributionResponse} + * @throws DistributionAgentException if any error happens during the execution of the request or if the authentication fails + */ + @Nonnull + DistributionResponse execute(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest) throws DistributionAgentException; + +} diff --git a/src/main/java/org/apache/sling/distribution/agent/DistributionAgentException.java b/src/main/java/org/apache/sling/distribution/agent/DistributionAgentException.java new file mode 100644 index 0000000..6b8bb28 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/agent/DistributionAgentException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.agent; + +/** + * Represents errors happened while {@link DistributionAgent}s do distributions. + */ +@SuppressWarnings("serial") +public class DistributionAgentException extends Exception { + + public DistributionAgentException(Exception e) { + super(e); + } + + public DistributionAgentException(String string) { + super(string); + } +} diff --git a/src/main/java/org/apache/sling/distribution/agent/DistributionRequestAuthorizationException.java b/src/main/java/org/apache/sling/distribution/agent/DistributionRequestAuthorizationException.java new file mode 100644 index 0000000..65dd507 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/agent/DistributionRequestAuthorizationException.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.agent; + +/** + * An {@link Exception} representing failed authorization in execution of a certain {@link org.apache.sling.distribution.communication.DistributionRequest} + */ +public class DistributionRequestAuthorizationException extends Exception { + public DistributionRequestAuthorizationException(String message) { + super(message); + } +} diff --git a/src/main/java/org/apache/sling/distribution/agent/DistributionRequestAuthorizationStrategy.java b/src/main/java/org/apache/sling/distribution/agent/DistributionRequestAuthorizationStrategy.java new file mode 100644 index 0000000..c74f164 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/agent/DistributionRequestAuthorizationStrategy.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.agent; + +import javax.annotation.Nonnull; + +import aQute.bnd.annotation.ConsumerType; +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.distribution.communication.DistributionRequest; +import org.apache.sling.distribution.component.DistributionComponent; + +/** + * Strategy for authorizing requests + */ +@ConsumerType +public interface DistributionRequestAuthorizationStrategy extends DistributionComponent { + + /** + * @param resourceResolver a {@link org.apache.sling.api.resource.ResourceResolver} representing the calling 'user' + * @param distributionRequest a request bringing metadata for getting {@link org.apache.sling.distribution.packaging.DistributionPackage}s + * to be exported + * @throws DistributionRequestAuthorizationException if the {@link org.apache.sling.api.resource.ResourceResolver} is + * not authorized to execute the given {@link org.apache.sling.distribution.communication.DistributionRequest} + */ + void checkPermission(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest) throws DistributionRequestAuthorizationException; + +} diff --git a/src/main/java/org/apache/sling/distribution/agent/package-info.java b/src/main/java/org/apache/sling/distribution/agent/package-info.java new file mode 100644 index 0000000..d3f2e4c --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/agent/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +@Version("0.1.0") +package org.apache.sling.distribution.agent; + +import aQute.bnd.annotation.Version; + diff --git a/src/main/java/org/apache/sling/distribution/communication/DistributionActionType.java b/src/main/java/org/apache/sling/distribution/communication/DistributionActionType.java new file mode 100644 index 0000000..98d1ea4 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/communication/DistributionActionType.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.communication; + +/** + * The type of a specific distribution action, used to decide what to do with specific distribution + * items / requests. + */ +public enum DistributionActionType { + + /** + * Content is added + */ + ADD("Add"), + + /** + * Content is deleted + */ + DELETE("Delete"), + + /** + * Content is polled + */ + POLL("Poll"); + + /** + * internal human readable name + */ + private final String name; + + /** + * Create a type + * + * @param name name + */ + private DistributionActionType(String name) { + this.name = name; + } + + /** + * Returns the human readable type name of this type. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Creates an action type for the given name. if the name cannot be mapped to a enum type or if + * it's <code>null</code>, <code>null</code> is returned. + * + * @param n the name + * @return the type or <code>null</code> + */ + public static DistributionActionType fromName(String n) { + if (n == null) { + return null; + } + try { + return DistributionActionType.valueOf(n.toUpperCase()); + } catch (IllegalArgumentException e) { + return null; + } + } + +} diff --git a/src/main/java/org/apache/sling/distribution/communication/DistributionParameter.java b/src/main/java/org/apache/sling/distribution/communication/DistributionParameter.java new file mode 100644 index 0000000..9ff292b --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/communication/DistributionParameter.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.communication; + +/** + * HTTP Parameters for distribution + */ +public enum DistributionParameter { + + QUEUE("queue"), + TYPE("type"), + ACTION("action"), + PATH("path"); + + private final String name; + + DistributionParameter(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } +} diff --git a/src/main/java/org/apache/sling/distribution/communication/DistributionRequest.java b/src/main/java/org/apache/sling/distribution/communication/DistributionRequest.java new file mode 100644 index 0000000..a50cbf7 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/communication/DistributionRequest.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.communication; + +import javax.annotation.Nonnull; +import java.util.Arrays; + +/** + * A distribution request + */ +public class DistributionRequest { + + private final long time; + + private final DistributionActionType action; + + private final String[] paths; + + public DistributionRequest(@Nonnull DistributionActionType action, @Nonnull String[] paths) { + this(System.currentTimeMillis(), action, paths); + } + + public DistributionRequest(long time, @Nonnull DistributionActionType action, @Nonnull String... paths) { + this.time = time; + this.action = action; + this.paths = paths; + } + + /** + * get the time this distribution request was created + * + * @return a <code>long</code> representing the distribution request creation time e.g. as returend by {@code System#currentTimeMillis} + */ + public long getTime() { + return time; + } + + /** + * get the {@link DistributionActionType} associated with this request + * + * @return the action as a <code>distributionActionType</code> + */ + public DistributionActionType getAction() { + return action; + } + + /** + * get the paths for this distribution request + * + * @return an array of <code>String</code>s representing the paths + */ + public String[] getPaths() { + return paths; + } + + @Override + public String toString() { + return "DistributionRequest{" + + "time=" + time + + ", action=" + action + + ", paths=" + Arrays.toString(paths) + + '}'; + } +} diff --git a/src/main/java/org/apache/sling/distribution/communication/DistributionResponse.java b/src/main/java/org/apache/sling/distribution/communication/DistributionResponse.java new file mode 100644 index 0000000..9027980 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/communication/DistributionResponse.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.communication; + +/** + * A distribution response + */ +public class DistributionResponse { + + private final String status; + private boolean successful; + + public DistributionResponse(String status, boolean successful) { + this.status = status; + this.successful = successful; + } + + public boolean isSuccessful() { + return successful; + } + + @Override + public String toString() { + return "{\"success\":" + isSuccessful() + ", \"status\":\"" + getStatus() + "\"}"; + } + + public String getStatus() { + return status != null ? status : "done nothing"; + } + +} diff --git a/src/main/java/org/apache/sling/distribution/communication/package-info.java b/src/main/java/org/apache/sling/distribution/communication/package-info.java new file mode 100644 index 0000000..3252696 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/communication/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +@Version("0.1.0") +package org.apache.sling.distribution.communication; + +import aQute.bnd.annotation.Version; + diff --git a/src/main/java/org/apache/sling/distribution/component/DistributionComponent.java b/src/main/java/org/apache/sling/distribution/component/DistributionComponent.java new file mode 100644 index 0000000..2e5145b --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/component/DistributionComponent.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.component; + +import aQute.bnd.annotation.ConsumerType; + +/** + * Marker interface for Sling Distribution components like: {@link org.apache.sling.distribution.agent.DistributionAgent}s, + * {@link org.apache.sling.distribution.trigger.DistributionTrigger}s, {@link org.apache.sling.distribution.packaging.DistributionPackageExporter}s + * and {@link org.apache.sling.distribution.packaging.DistributionPackageImporter}s. + */ +@ConsumerType +public interface DistributionComponent { + +} diff --git a/src/main/java/org/apache/sling/distribution/component/DistributionComponentFactory.java b/src/main/java/org/apache/sling/distribution/component/DistributionComponentFactory.java new file mode 100644 index 0000000..f065e58 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/component/DistributionComponentFactory.java @@ -0,0 +1,331 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.component; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.Map; + +import aQute.bnd.annotation.ProviderType; + +/** + * factory for {@link DistributionComponent}s + */ +@ProviderType +public interface DistributionComponentFactory { + + /** + * the type of the component + */ + String COMPONENT_TYPE = "type"; + + /** + * the name of the component + */ + String COMPONENT_NAME = "name"; + + /** + * type for components referencing OSGi services + */ + String COMPONENT_TYPE_SERVICE = "service"; + + /** + * component enabled + */ + String COMPONENT_ENABLED = "enabled"; + + + /** + * distribution agent component + */ + String COMPONENT_AGENT = "agent"; + + /** + * package exporter component + */ + String COMPONENT_PACKAGE_EXPORTER = "packageExporter"; + + /** + * package importer component + */ + String COMPONENT_PACKAGE_IMPORTER = "packageImporter"; + + /** + * request authorization strategy component + */ + String COMPONENT_REQUEST_AUTHORIZATION_STRATEGY = "requestAuthorizationStrategy"; + + /** + * queue distribution strategy component + */ + String COMPONENT_QUEUE_DISTRIBUTION_STRATEGY = "queueDistributionStrategy"; + + /** + * queue provider component + */ + String COMPONENT_QUEUE_PROVIDER = "queueProvider"; + + /** + * trigger component + */ + String COMPONENT_TRIGGER = "trigger"; + + /** + * package builder component + */ + String COMPONENT_PACKAGE_BUILDER = "packageBuilder"; + + /** + * transport authentication provider component + */ + String COMPONENT_TRANSPORT_AUTHENTICATION_PROVIDER = "transportAuthenticationProvider"; + + /** + * simple distribution agent type + */ + String AGENT_SIMPLE = "simple"; + + /** + * service user property + */ + String AGENT_SIMPLE_PROPERTY_SERVICE_NAME = "serviceName"; + + /** + * 'passive' property for agents (for defining "queueing agents") + */ + String AGENT_SIMPLE_PROPERTY_IS_PASSIVE = "isPassive"; + + /** + * local package exporter type + */ + String PACKAGE_EXPORTER_LOCAL = "local"; + + /** + * remote package exporter type + */ + String PACKAGE_EXPORTER_REMOTE = "remote"; + + /** + * endpoints property + */ + String PACKAGE_EXPORTER_REMOTE_PROPERTY_ENDPOINTS = "endpoints"; + + /** + * endpoint strategy property + */ + String PACKAGE_EXPORTER_REMOTE_PROPERTY_ENDPOINTS_STRATEGY = "endpoints.strategy"; + + /** + * no. of items to poll property + */ + String PACKAGE_EXPORTER_REMOTE_PROPERTY_POLL_ITEMS = "poll.items"; + + /** + * package exporter's agent property + */ + String PACKAGE_EXPORTER_AGENT = "agent"; + + /** + * local package importer type + */ + String PACKAGE_IMPORTER_LOCAL = "local"; + + /** + * remote package importer type + */ + String PACKAGE_IMPORTER_REMOTE = "remote"; + + /** + * endpoints property + */ + String PACKAGE_IMPORTER_REMOTE_PROPERTY_ENDPOINTS = "endpoints"; + + /** + * endpoint strategy property + */ + String PACKAGE_IMPORTER_REMOTE_PROPERTY_ENDPOINTS_STRATEGY = "endpoints.strategy"; + + /** + * user property + */ + String TRANSPORT_AUTHENTICATION_PROVIDER_USER = "user"; + + /** + * username property + */ + String TRANSPORT_AUTHENTICATION_PROVIDER_USER_PROPERTY_USERNAME = "username"; + + /** + * password property + */ + String TRANSPORT_AUTHENTICATION_PROVIDER_USER_PROPERTY_PASSWORD = "password"; + + /** + * remote event trigger type + */ + String TRIGGER_REMOTE_EVENT = "remoteEvent"; + + /** + * remote event endpoint property + */ + String TRIGGER_REMOTE_EVENT_PROPERTY_ENDPOINT = "endpoint"; + + /** + * resource event trigger type + */ + String TRIGGER_RESOURCE_EVENT = "resourceEvent"; + + /** + * resource event path property + */ + String TRIGGER_RESOURCE_EVENT_PROPERTY_PATH = "path"; + + /** + * scheduled trigger type + */ + String TRIGGER_SCHEDULED_EVENT = "scheduledEvent"; + + /** + * scheduled trigger action property + */ + String TRIGGER_SCHEDULED_EVENT_PROPERTY_ACTION = "action"; + + /** + * scheduled trigger path property + */ + String TRIGGER_SCHEDULED_EVENT_PROPERTY_PATH = "path"; + + /** + * scheduled trigger seconds property + */ + String TRIGGER_SCHEDULED_EVENT_PROPERTY_SECONDS = "seconds"; + + /** + * chain distribution trigger type + */ + String TRIGGER_DISTRIBUTION_EVENT = "distributionEvent"; + + /** + * chain distribution path property + */ + String TRIGGER_DISTRIBUTION_EVENT_PROPERTY_PATH = "path"; + + /** + * jcr event trigger type + */ + String TRIGGER_JCR_EVENT = "jcrEvent"; + + /** + * jcr event trigger path property + */ + String TRIGGER_JCR_EVENT_PROPERTY_PATH = "path"; + + /** + * jcr event trigger service user property + */ + String TRIGGER_JCR_EVENT_PROPERTY_SERVICE_NAME = "servicename"; + + /** + * jcr persisting event trigger type + */ + String TRIGGER_PERSISTED_JCR_EVENT = "persistedJcrEvent"; + + /** + * jcr persisting event trigger path property + */ + String TRIGGER_PERSISTED_JCR_EVENT_PROPERTY_PATH = "path"; + + /** + * jcr persisting event trigger service user property + */ + String TRIGGER_PERSISTED_JCR_EVENT_PROPERTY_SERVICE_NAME = "servicename"; + + /** + * jcr persisting event trigger nuggets path property + */ + String TRIGGER_PERSISTED_JCR_EVENT_PROPERTY_NUGGETS_PATH = "nuggetsPath"; + + /** + * privilege request authorization strategy type + */ + String REQUEST_AUTHORIZATION_STRATEGY_PRIVILEGE = "privilege"; + + /** + * privilege request authorization strategy jcr privilege property + */ + String REQUEST_AUTHORIZATION_STRATEGY_PRIVILEGE_PROPERTY_JCR_PRIVILEGE = "jcrPrivilege"; + + /** + * file vault package builder type + */ + String PACKAGE_BUILDER_FILEVLT = "vlt"; + + /** + * import mode property for file vault package builder + */ + String PACKAGE_BUILDER_FILEVLT_IMPORT_MODE = "importMode"; + + /** + * ACL handling property for file vault package builder + */ + String PACKAGE_BUILDER_FILEVLT_ACLHANDLING = "aclHandling"; + + /** + * queue provider job type + */ + String QUEUE_PROVIDER_JOB = "job"; + + /** + * queue provider simple type + */ + String QUEUE_PROVIDER_SIMPLE = "simple"; + + /** + * queue distribution strategy single type + */ + String QUEUE_DISTRIBUTION_STRATEGY_SINGLE = "single"; + + /** + * queue distribution strategy priority type + */ + String QUEUE_DISTRIBUTION_STRATEGY_PRIORITY = "priority"; + + /** + * queue distribution strategy priority paths property + */ + String QUEUE_DISTRIBUTION_STRATEGY_PRIORITY_PROPERTY_PATHS = "priority.paths"; + + /** + * create a {@link DistributionComponent} + * + * @param type the {@link java.lang.Class} of the component to be created + * @param properties the properties to be supplied for the initialization of the component + * @param componentProvider the {@link DistributionComponentProvider} used to eventually + * wire additional required {@link DistributionComponent}s + * @param <ComponentType> the actual type of the {@link DistributionComponent} + * to be created + * @return a {@link DistributionComponent} of the specified type initialized with given properties or <code>null</code> + * if that could not be created + */ + @CheckForNull + <ComponentType extends DistributionComponent> ComponentType createComponent(@Nonnull java.lang.Class<ComponentType> type, + @Nonnull Map<String, Object> properties, + @Nullable DistributionComponentProvider componentProvider); +} diff --git a/src/main/java/org/apache/sling/distribution/component/DistributionComponentProvider.java b/src/main/java/org/apache/sling/distribution/component/DistributionComponentProvider.java new file mode 100644 index 0000000..a8479a7 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/component/DistributionComponentProvider.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.component; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import aQute.bnd.annotation.ConsumerType; + +/** + * provider for already existing {@link DistributionComponent}s + */ +@ConsumerType +public interface DistributionComponentProvider { + + /** + * Retrieves an already existing component by name. + * If <code>null</code> is passed as componentName then a default component is returned. + * + * @param type the {@link java.lang.Class} of the component to be retrieved + * @param componentName the component name + * @param <ComponentType> the actual type of the {@link DistributionComponent} + * to be retrieved + * @return the {@link DistributionComponent} of the specified type, + * with the specified name, or <code>null</code> if such a {@link DistributionComponent} + * doesn't exist + */ + @CheckForNull + <ComponentType extends DistributionComponent> ComponentType getComponent(@Nonnull java.lang.Class<ComponentType> type, + @Nullable String componentName); +} diff --git a/src/main/java/org/apache/sling/distribution/component/ManagedDistributionComponent.java b/src/main/java/org/apache/sling/distribution/component/ManagedDistributionComponent.java new file mode 100644 index 0000000..23acf0f --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/component/ManagedDistributionComponent.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.component; + +import aQute.bnd.annotation.ConsumerType; + +/** + * A managed {@link DistributionComponent} is a component which requires explicit + * initialization and releasing of its underlying (and implementation specific) resources. + */ +@ConsumerType +public interface ManagedDistributionComponent { + + /** + * Enable the component + */ + void enable(); + + /** + * Disable the component + */ + void disable(); + +} diff --git a/src/main/java/org/apache/sling/distribution/component/package-info.java b/src/main/java/org/apache/sling/distribution/component/package-info.java new file mode 100644 index 0000000..d50ff91 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/component/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +@Version("0.1.0") +package org.apache.sling.distribution.component; + +import aQute.bnd.annotation.Version; + diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEvent.java b/src/main/java/org/apache/sling/distribution/event/DistributionEvent.java new file mode 100644 index 0000000..964fa86 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEvent.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.event; + +import java.util.Dictionary; + +import org.osgi.service.event.Event; + +/** + * A distribution related event + */ +public class DistributionEvent extends Event { + + public static final String EVENT_TOPIC = "org/apache/sling/distribution/event"; + + public DistributionEvent(DistributionEventType type, Dictionary<?, ?> properties) { + super(getTopic(type), properties); + } + + /** + * get the topic for a certain event type + * + * @param type the {@link DistributionEventType} to get the topic for + * @return the topic for the given event type + */ + public static String getTopic(DistributionEventType type) { + return EVENT_TOPIC + '/' + type.name(); + } +} diff --git a/src/main/java/org/apache/sling/distribution/event/DistributionEventType.java b/src/main/java/org/apache/sling/distribution/event/DistributionEventType.java new file mode 100644 index 0000000..b424f73 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/event/DistributionEventType.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.event; + +/** + * an enum of the possible types of events related to distribution + */ +public enum DistributionEventType { + + /** + * event for package created + */ + PACKAGE_CREATED, + + /** + * event for package queued + */ + PACKAGE_QUEUED, + + /** + * event for package replicated + */ + PACKAGE_DISTRIBUTED, + + /** + * event for package installed + */ + PACKAGE_INSTALLED, + + /** + * event for package imported + */ + PACKAGE_IMPORTED, + + /** + * event for agent created + */ + AGENT_CREATED, + + /** + * event for agent modified + */ + AGENT_MODIFIED, + + /** + * event for agent deleted + */ + AGENT_DELETED + +} diff --git a/src/main/java/org/apache/sling/distribution/event/package-info.java b/src/main/java/org/apache/sling/distribution/event/package-info.java new file mode 100644 index 0000000..5382163 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/event/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +@Version("0.1.0") +package org.apache.sling.distribution.event; + +import aQute.bnd.annotation.Version; + diff --git a/src/main/java/org/apache/sling/distribution/packaging/DistributionPackage.java b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackage.java new file mode 100644 index 0000000..ae32dc6 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackage.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.packaging; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.io.InputStream; +import java.io.Serializable; + +import aQute.bnd.annotation.ConsumerType; + +/** + * A distribution package + */ +@ConsumerType +public interface DistributionPackage extends Serializable { + + /** + * get package id. the id is a unique string that can be used to retrieve + * the package from an {@link DistributionPackageExporter} + * + * @return the package id + */ + @Nonnull + String getId(); + + /** + * get the paths covered by this package + * + * @return an array of paths + */ + @Nonnull + String[] getPaths(); + + /** + * get the action this package is used for + * + * @return the action + */ + @Nonnull + String getAction(); + + /** + * get the type of package + * + * @return the package type + */ + @Nonnull + String getType(); + + /** + * creates a package stream. + * a new stream is created for each call and it is the caller's obligation to close the stream. + * + * @return an {@link InputStream} + * @throws IOException + */ + @Nonnull + InputStream createInputStream() throws IOException; + + /** + * get package stream length + * + * @return the package length + */ + long getLength(); + + /** + * releases all resources associated with this package + */ + void delete(); + + + /** + * gets an additional info holder for this package. + * The additional info object contains control information rather than content information. + * For example info.origin can be used to skip distributing back to the originating endpoint. + * It should not be be serialized between instances as its main purpose is to allow + * inter component communication on the same instance. + * @return the associated metadata to this package + */ + @Nonnull + DistributionPackageInfo getInfo(); + +} diff --git a/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageExportException.java b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageExportException.java new file mode 100644 index 0000000..b225686 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageExportException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.packaging; + +/** + * This represents an error happening while exporting a {@link DistributionPackage} + */ +@SuppressWarnings("serial") +public class DistributionPackageExportException extends Exception { + + public DistributionPackageExportException(String message) { + super(message); + } + + public DistributionPackageExportException(Throwable t) { + super(t); + } +} diff --git a/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageExporter.java b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageExporter.java new file mode 100644 index 0000000..dc2bfd0 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageExporter.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.packaging; + + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import java.util.List; + +import aQute.bnd.annotation.ConsumerType; +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.distribution.communication.DistributionRequest; +import org.apache.sling.distribution.component.DistributionComponent; + +/** + * A {@link DistributionPackageExporter ) is responsible of exporting + * {@link DistributionPackage }s to be then imported by a {@link org.apache.sling.distribution.agent.DistributionAgent } + * (via a {@link DistributionPackageImporter }). + */ +@ConsumerType +public interface DistributionPackageExporter extends DistributionComponent { + + /** + * Exports the {@link DistributionPackage}s built from the + * passed {@link org.apache.sling.distribution.communication.DistributionRequest}. + * + * @param resourceResolver - the resource resolver used to export the packages + * @param distributionRequest - the request containing the information about which content is to be exported + * @return a <code>List</code> of {@link DistributionPackage}s + */ + @Nonnull + List<DistributionPackage> exportPackages(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest) throws DistributionPackageExportException; + + /** + * Retrieves a {@link DistributionPackage} given its 'id', if it already exists. + * + * @param resourceResolver - the resource resolver use to obtain the package. + * @param distributionPackageId - the id of the package to be retrieved + * @return a {@link DistributionPackage} if available, <code>null</code> otherwise + */ + @CheckForNull + DistributionPackage getPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull String distributionPackageId); +} diff --git a/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageImportException.java b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageImportException.java new file mode 100644 index 0000000..e22ec91 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageImportException.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.packaging; + +/** + * This represents an error happening while importing a {@link DistributionPackage} + */ +@SuppressWarnings("serial") +public class DistributionPackageImportException extends Exception { + + public DistributionPackageImportException(String message) { + super(message); + } + + public DistributionPackageImportException(Throwable t) { + super(t); + } + + public DistributionPackageImportException(String message, Exception e) { + super(message, e); + } +} diff --git a/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageImporter.java b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageImporter.java new file mode 100644 index 0000000..a175198 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageImporter.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.packaging; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import java.io.InputStream; + +import aQute.bnd.annotation.ConsumerType; +import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.distribution.component.DistributionComponent; + +/** + * A {@link DistributionPackageImporter} is responsible for importing + * {@link DistributionPackage}s into the resource tree. + */ +@ConsumerType +public interface DistributionPackageImporter extends DistributionComponent { + + /** + * Imports the given distribution package into the underlying system + * + * @param resourceResolver - the resource resolver used to import the resources + * @param distributionPackage - the package to be imported + * @return <code>true</code> if the import succeeded, <code>false</code> otherwise + * @throws DistributionPackageImportException if any error occurs during import + */ + boolean importPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionPackage distributionPackage) throws DistributionPackageImportException; + + /** + * Tries to convert an {@link java.io.InputStream} to a {@link DistributionPackage} and then imports it into the underlying system + * + * @param resourceResolver - the resource resolver used to read the package + * @param stream the {@link InputStream} of the package to be converted and installed + * @return a {@link DistributionPackage} if the stream has been successfully converted and installed + * @throws DistributionPackageImportException when the stream cannot be read as a {@link DistributionPackage} and installed + */ + @CheckForNull + DistributionPackage importStream(@Nonnull ResourceResolver resourceResolver, @Nonnull InputStream stream) throws DistributionPackageImportException; + +} diff --git a/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageInfo.java b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageInfo.java new file mode 100644 index 0000000..326ed8e --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageInfo.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sling.distribution.packaging; + + +/** + * Additional information about a package. + * Additional information is optional and components should expect every piece of it to be null. + */ +public class DistributionPackageInfo { + + private String origin; + + /** + * retrieves the origin of the package. + * @return the package origin + */ + public String getOrigin() { + return origin; + } + + /** + * sets the origin of the package. + * @param origin the originating instance of this package + */ + public void setOrigin(String origin) { + this.origin = origin; + } + + /** + * fills the current info object from the provided one. + * @param packageInfo package metadata + */ + public void fillInfo(DistributionPackageInfo packageInfo) { + if (packageInfo != null) { + this.setOrigin(packageInfo.getOrigin()); + } + } +} diff --git a/src/main/java/org/apache/sling/distribution/packaging/SharedDistributionPackage.java b/src/main/java/org/apache/sling/distribution/packaging/SharedDistributionPackage.java new file mode 100644 index 0000000..8bc2130 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/packaging/SharedDistributionPackage.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.packaging; + +import javax.annotation.Nonnull; + +import aQute.bnd.annotation.ConsumerType; + +/** + * A {@link DistributionPackage} that offers basic reference counting + */ +@ConsumerType +public interface SharedDistributionPackage extends DistributionPackage { + + + /** + * acquire a reference to this package and increase the reference count. + */ + void acquire(@Nonnull String holderName); + + /** + * release a reference to this package and decrease the reference count. + * when no more references are hold the package <code>delete</code> method is called. + */ + void release(@Nonnull String holderName); + +} diff --git a/src/main/java/org/apache/sling/distribution/packaging/package-info.java b/src/main/java/org/apache/sling/distribution/packaging/package-info.java new file mode 100644 index 0000000..e0a3160 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/packaging/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +@Version("0.1.0") +package org.apache.sling.distribution.packaging; + +import aQute.bnd.annotation.Version; + diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java new file mode 100644 index 0000000..8999408 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.queue; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import aQute.bnd.annotation.ConsumerType; + +/** + * a queue for handling {@link org.apache.sling.distribution.agent.DistributionAgent}s' requests + */ +@ConsumerType +public interface DistributionQueue { + + /** + * get this queue name + * + * @return queue name as a <code>String</code> + */ + @Nonnull + String getName(); + + /** + * add a distribution item to this queue + * + * @param item a distribution item representing the package to distribute + * @return <code>true</code> if the distribution item was added correctly to the queue, + * <code>false</code otherwise + */ + boolean add(@Nonnull DistributionQueueItem item); + + /** + * get the status of a certain item in the queue + * + * @param item the distribution item to get the status for + * @return the item status in the queue + * @throws DistributionQueueException if any error occurs while getting the status + */ + @Nonnull + DistributionQueueItemState getStatus(@Nonnull DistributionQueueItem item) + throws DistributionQueueException; + + /** + * get the first item (FIFO wise, the next to be processed) into the queue + * + * @return the first item into the queue or <code>null</code> if the queue is empty + */ + @CheckForNull + DistributionQueueItem getHead(); + + /** + * check if the queue is empty + * + * @return <code>true</code> if the queue is empty, <code>false</code> otherwise + */ + boolean isEmpty(); + + /** + * get the items in the queue + * + * @param queueItemSelector represents the criteria to filter queue items. + * if null is passed then all items are returned. + * @return a <code>Iterable</code> of {@link DistributionQueueItem}s + */ + @Nonnull + Iterable<DistributionQueueItem> getItems(@Nullable DistributionQueueItemSelector queueItemSelector); + + /** + * remove an item from the queue by specifying its id + * + * @param id <code>String</code> representing an item's identifier + */ + void remove(@Nonnull String id); +} diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueDistributionStrategy.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueDistributionStrategy.java new file mode 100644 index 0000000..f0fbf32 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueDistributionStrategy.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.queue; + +import javax.annotation.Nonnull; +import java.util.List; + +import aQute.bnd.annotation.ConsumerType; +import org.apache.sling.distribution.component.DistributionComponent; +import org.apache.sling.distribution.packaging.DistributionPackage; + +/** + * a {@link DistributionQueueDistributionStrategy} implements an algorithm for the distribution of + * {@link org.apache.sling.distribution.packaging.DistributionPackage}s among the available queues + */ +@ConsumerType +public interface DistributionQueueDistributionStrategy extends DistributionComponent { + String DEFAULT_QUEUE_NAME = "default"; + + /** + * synchronously distribute a {@link org.apache.sling.distribution.packaging.DistributionPackage} + * to one or more {@link DistributionQueue}s provided by the given {@link DistributionQueueProvider} + * + * @param distributionPackage a {@link org.apache.sling.distribution.packaging.DistributionPackage} to distribute + * @param queueProvider the {@link DistributionQueueProvider} used to provide the queues to be used for the given package + * @return <code>true</code> if addition was successful, <code>false</code> otherwise + * @throws DistributionQueueException if any internal error happens during distribution + */ + boolean add(@Nonnull DistributionPackage distributionPackage, @Nonnull DistributionQueueProvider queueProvider) throws DistributionQueueException; + + + /** + * Returns the queue names available for this strategy. + * @return a list of queue names + */ + @Nonnull + List<String> getQueueNames(); + +} diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueException.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueException.java new file mode 100644 index 0000000..c5d7520 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.queue; + +/** + * Represents errors happening during queue operations + */ +@SuppressWarnings("serial") +public class DistributionQueueException extends Exception { + + public DistributionQueueException(String message, Exception e) { + super(message, e); + } + + public DistributionQueueException(String string) { + super(string); + } +} diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java new file mode 100644 index 0000000..42f570f --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.queue; + +import org.apache.sling.distribution.packaging.DistributionPackageInfo; + +/** + * An item in a {@link DistributionQueue} + * <p/> + * This is basically a proxy to {@link org.apache.sling.distribution.packaging.DistributionPackage} designed to avoid having + * to keep the package {@link org.apache.sling.distribution.packaging.DistributionPackage#createInputStream() stream} into + * the queues. + */ +public class DistributionQueueItem { + + private final String id; + + private final String[] paths; + + private final String action; + + private final String type; + + private final DistributionPackageInfo packageInfo; + + public DistributionQueueItem(String id, String[] paths, String action, String type, DistributionPackageInfo packageInfo) { + this.id = id; + this.paths = paths; + this.action = action; + this.type = type; + this.packageInfo = packageInfo; + } + + public String getId() { + return id; + } + + public String[] getPaths() { + return paths; + } + + public String getAction() { + return action; + } + + public String getType() { + return type; + } + + public DistributionPackageInfo getPackageInfo() { + return packageInfo; + } +} diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemSelector.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemSelector.java new file mode 100644 index 0000000..e52c863 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemSelector.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sling.distribution.queue; + +/** + * Class representing criteria for queue items selection. + */ +public class DistributionQueueItemSelector { + private final int skip; + private final int limit; + + /** + * + * @param skip the number of items to skip + * @param limit the maximum number of items to return. use -1 to return all items. + */ + public DistributionQueueItemSelector(int skip, int limit) { + this.skip = skip; + this.limit = limit; + } + + /** + * @return the number of items to skip from the queue. + */ + public int getSkip() { + return skip; + } + + /** + * + * @return return the maximum number of items to be selected. + */ + public int getLimit() { + return limit; + } +} diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemState.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemState.java new file mode 100644 index 0000000..afdb0ac --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemState.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.queue; + +import java.util.Calendar; + +/** + * the current status of a certain item in a {@link DistributionQueue} + */ + +public class DistributionQueueItemState { + + private final int attempts; + + private final ItemState state; + + private final Calendar entered; + + public DistributionQueueItemState(Calendar entered, ItemState state, int attempts) { + + this.entered = entered; + this.state = state; + this.attempts = attempts; + } + + public DistributionQueueItemState(ItemState state) { + this(Calendar.getInstance(), state, 0); + } + + public boolean isSuccessful() { + return ItemState.SUCCEEDED.equals(state); + } + + public int getAttempts() { + return attempts; + } + + public ItemState getItemState() { + return state; + } + + @Override + public String toString() { + return "{\"attempts\":\"" + attempts + "\",\"" + "successful\":\"" + isSuccessful() + "\",\"" + "state\":\"" + state + "\"}"; + } + + public Calendar getEntered() { + return entered; + } + + public enum ItemState { + QUEUED, // waiting in queue after adding or for restart after failing + ACTIVE, // job is currently in processing + SUCCEEDED, // processing finished successfully + STOPPED, // processing was stopped by a user + GIVEN_UP, // number of retries reached + ERROR, // processing signaled CANCELLED or throw an exception + DROPPED // dropped jobs + } + +} diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueProcessor.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueProcessor.java new file mode 100644 index 0000000..dff45c8 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueProcessor.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.queue; + +import javax.annotation.Nonnull; + +import aQute.bnd.annotation.ConsumerType; + +/** + * Processor of {@link DistributionQueueItem}s + */ +@ConsumerType +public interface DistributionQueueProcessor { + + /** + * Process an item from a certain <code>distributionQueue</code> + * + * @param queueName the name of the <code>distributionQueue</code> to be processed + * @param distributionQueueItem the <code>distributionQueueItem</code> to be processed + * @return <code>true</code> if the item was successfully processed, <code>false</code> otherwise + */ + public boolean process(@Nonnull String queueName, @Nonnull DistributionQueueItem distributionQueueItem); +} diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueProvider.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueProvider.java new file mode 100644 index 0000000..80ec410 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueProvider.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.queue; + +import javax.annotation.Nonnull; + +import aQute.bnd.annotation.ConsumerType; +import org.apache.sling.distribution.component.DistributionComponent; + +/** + * A provider for {@link DistributionQueue}s + */ +@ConsumerType +public interface DistributionQueueProvider extends DistributionComponent { + + /** + * provide a named queue for the given agent + * + * @param queueName the name of the queue to retrieve + * @return a {@link DistributionQueue} + * @throws DistributionQueueException if any error happens + */ + @Nonnull + DistributionQueue getQueue(@Nonnull String queueName) throws DistributionQueueException; + + /** + * enables queue driven processing for an agent + * + * @param queueProcessor the queue processor to be used + */ + void enableQueueProcessing(@Nonnull DistributionQueueProcessor queueProcessor) throws DistributionQueueException; + + + /** + * disables queue driven processing for an agent + * + */ + void disableQueueProcessing() throws DistributionQueueException; +} diff --git a/src/main/java/org/apache/sling/distribution/queue/package-info.java b/src/main/java/org/apache/sling/distribution/queue/package-info.java new file mode 100644 index 0000000..70795e9 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/queue/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +@Version("0.1.0") +package org.apache.sling.distribution.queue; + +import aQute.bnd.annotation.Version; + diff --git a/src/main/java/org/apache/sling/distribution/transport/authentication/TransportAuthenticationContext.java b/src/main/java/org/apache/sling/distribution/transport/authentication/TransportAuthenticationContext.java new file mode 100644 index 0000000..b1e3c18 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/transport/authentication/TransportAuthenticationContext.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.transport.authentication; + +import java.util.HashMap; +import java.util.Map; + +public class TransportAuthenticationContext { + private final Map<String, Object> attributes = new HashMap<String, Object>(); + + @SuppressWarnings("unchecked") + public <T> T getAttribute(String name, Class<? extends T> klass) { + T result = null; + Object object = attributes.get(name); + if (klass.isInstance(object)) { + result = (T) object; + } + return result; + } + + public <T> void addAttribute(String name, T object) { + attributes.put(name, object); + } +} diff --git a/src/main/java/org/apache/sling/distribution/transport/authentication/TransportAuthenticationException.java b/src/main/java/org/apache/sling/distribution/transport/authentication/TransportAuthenticationException.java new file mode 100644 index 0000000..b4f7765 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/transport/authentication/TransportAuthenticationException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.transport.authentication; + +/** + * Represents an error in transport authentication + */ +@SuppressWarnings("serial") +public class TransportAuthenticationException extends Exception { + + public TransportAuthenticationException(String string) { + super(string); + } + + public TransportAuthenticationException(Exception e) { + super(e); + } + +} diff --git a/src/main/java/org/apache/sling/distribution/transport/authentication/TransportAuthenticationProvider.java b/src/main/java/org/apache/sling/distribution/transport/authentication/TransportAuthenticationProvider.java new file mode 100644 index 0000000..6df2d29 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/transport/authentication/TransportAuthenticationProvider.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.transport.authentication; + +import aQute.bnd.annotation.ConsumerType; +import org.apache.sling.distribution.component.DistributionComponent; + +/** + * A {@link org.apache.sling.distribution.transport.authentication.TransportAuthenticationProvider} is responsible for + * authentication of instances sending and receiving distribution items via transport algorithms + * A {@link org.apache.sling.distribution.transport.authentication.TransportAuthenticationProvider} will authenticate + * 'authenticables' objects of type {@link A}, producing 'authenticated' objects of type {@link T}. + * + */ +@ConsumerType +public interface TransportAuthenticationProvider<A, T> extends DistributionComponent { + + /** + * Check if this provider is able to authenticate objects belonging to given 'authenticable' class. + * + * @param authenticable class of objects to be authenticated + * @return <code>true</code> if this provider can check authentication on instances of this class, <code>false</code> + * otherwise + */ + boolean canAuthenticate(Class<A> authenticable); + + /** + * Authenticate an 'authenticable' object by performing some implementation specific operation on it, and producing + * an 'authenticated' object to be passed back to a transport algorithm. + * The returned 'authenticated' object may be of the same class of the 'authenticable' object (e.g. passing an 'authenticable' + * http client and returning an 'authenticated' http client) or of a different class (e.g. passing an 'authenticable' + * jcr repository and returning an 'authenticated' jcr session). + * + * @param authenticable class of objects to be authenticated + * @param context authentication context holding authentication information + * @return an 'authenticated' object to be used by the transport + * @throws TransportAuthenticationException + */ + T authenticate(A authenticable, TransportAuthenticationContext context) + throws TransportAuthenticationException; + +} diff --git a/src/main/java/org/apache/sling/distribution/transport/authentication/package-info.java b/src/main/java/org/apache/sling/distribution/transport/authentication/package-info.java new file mode 100644 index 0000000..de83a67 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/transport/authentication/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +@Version("0.1.0") +package org.apache.sling.distribution.transport.authentication; + +import aQute.bnd.annotation.Version; + diff --git a/src/main/java/org/apache/sling/distribution/trigger/DistributionRequestHandler.java b/src/main/java/org/apache/sling/distribution/trigger/DistributionRequestHandler.java new file mode 100644 index 0000000..0d77435 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/trigger/DistributionRequestHandler.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.trigger; + +import javax.annotation.Nonnull; + +import aQute.bnd.annotation.ConsumerType; +import org.apache.sling.distribution.communication.DistributionRequest; + +/** + * An handler for {@link org.apache.sling.distribution.communication.DistributionRequest}s passed to a + * {@link DistributionTrigger} + */ +@ConsumerType +public interface DistributionRequestHandler { + + /** + * handle the request according to the trigger implementation. + * + * @param request a distribution request + */ + void handle(@Nonnull DistributionRequest request); + +} diff --git a/src/main/java/org/apache/sling/distribution/trigger/DistributionTrigger.java b/src/main/java/org/apache/sling/distribution/trigger/DistributionTrigger.java new file mode 100644 index 0000000..53b9fc3 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/trigger/DistributionTrigger.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.trigger; + +import javax.annotation.Nonnull; + +import aQute.bnd.annotation.ConsumerType; +import org.apache.sling.distribution.component.DistributionComponent; + +/** + * A {@link DistributionTrigger} is responsible to trigger + * {@link org.apache.sling.distribution.communication.DistributionRequest}s upon certain 'events' (e.g. Sling / Jcr events, + * periodic polling, etc.). + * A {@link DistributionTrigger} is meant to be stateless so that more than one + * {@link DistributionRequestHandler} can be registered into the same trigger. + */ +@ConsumerType +public interface DistributionTrigger extends DistributionComponent { + + /** + * register a request handler to be triggered and returns a corresponding registration id + * + * @param requestHandler handler + * @throws DistributionTriggerException if registration fails + */ + void register(@Nonnull DistributionRequestHandler requestHandler) throws DistributionTriggerException; + + /** + * unregister the given handler, if existing + * + * @param requestHandler handler to unregister + * @throws DistributionTriggerException if unregistration fails + */ + void unregister(@Nonnull DistributionRequestHandler requestHandler) throws DistributionTriggerException; +} diff --git a/src/main/java/org/apache/sling/distribution/trigger/DistributionTriggerException.java b/src/main/java/org/apache/sling/distribution/trigger/DistributionTriggerException.java new file mode 100644 index 0000000..36c91cd --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/trigger/DistributionTriggerException.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.distribution.trigger; + +/** + * Exception representing errors during (un)registration of {@link DistributionTrigger}s + */ +public class DistributionTriggerException extends Exception { + + public DistributionTriggerException(String message, Throwable throwable) { + super(message, throwable); + } + + public DistributionTriggerException(String message) { + super(message); + } +} diff --git a/src/main/java/org/apache/sling/distribution/trigger/package-info.java b/src/main/java/org/apache/sling/distribution/trigger/package-info.java new file mode 100644 index 0000000..5fd7c36 --- /dev/null +++ b/src/main/java/org/apache/sling/distribution/trigger/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +@Version("0.1.0") +package org.apache.sling.distribution.trigger; + +import aQute.bnd.annotation.Version; + -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
