You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2015/09/17 20:57:29 UTC
svn commit: r1703667 - in /aries/trunk/subsystem:
subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BasicSubsystem.java
subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1084Test.java
Author: jwross
Date: Thu Sep 17 18:57:29 2015
New Revision: 1703667
URL: http://svn.apache.org/viewvc?rev=1703667&view=rev
Log:
ARIES-1084 Subsystem : Failure on restart after framework crash
When instantiating a persisted subsystem, do the following state conversions, if necessary.
STARTING, ACTIVE, STOPPING -> RESOLVED
RESOLVING -> INSTALLED
Added:
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1084Test.java
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BasicSubsystem.java
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BasicSubsystem.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BasicSubsystem.java?rev=1703667&r1=1703666&r2=1703667&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BasicSubsystem.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BasicSubsystem.java Thu Sep 17 18:57:29 2015
@@ -122,9 +122,20 @@ public class BasicSubsystem implements R
this(FileSystem.getFSRoot(file));
}
- public BasicSubsystem(IDirectory directory) throws IOException, URISyntaxException, ResolutionException {
+ public BasicSubsystem(IDirectory directory) throws IOException,
+ URISyntaxException, ResolutionException {
this.directory = directory;
- setDeploymentManifest(new DeploymentManifest.Builder().manifest(getDeploymentManifest()).build());
+ State state = State
+ .valueOf(getDeploymentManifestHeaderValue(DeploymentManifest.ARIESSUBSYSTEM_STATE));
+ if (EnumSet.of(State.STARTING, State.ACTIVE, State.STOPPING).contains(
+ state)) {
+ state = State.RESOLVED;
+ }
+ else if (State.RESOLVING.equals(state)) {
+ state = State.INSTALLED;
+ }
+ setDeploymentManifest(new DeploymentManifest.Builder()
+ .manifest(getDeploymentManifest()).state(state).build());
}
/* BEGIN Resource interface methods. */
Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1084Test.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1084Test.java?rev=1703667&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1084Test.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1084Test.java Thu Sep 17 18:57:29 2015
@@ -0,0 +1,163 @@
+/*
+ * 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.aries.subsystem.itests.defect;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.apache.aries.subsystem.core.archive.DeploymentManifest;
+import org.apache.aries.subsystem.itests.SubsystemTest;
+import org.apache.aries.subsystem.itests.util.TestCapability;
+import org.apache.aries.subsystem.itests.util.TestRepository;
+import org.apache.aries.subsystem.itests.util.TestRepositoryContent;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.resource.Resource;
+import org.osgi.service.repository.Repository;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
+
+/*
+ * https://issues.apache.org/jira/browse/ARIES-1084
+ *
+ * Subsystem : Failure on restart after framework crash
+ */
+public class Aries1084Test extends SubsystemTest {
+ /*
+ * Subsystem-SymbolicName: feature.a.esa
+ * Subsystem-Content: bundle.a.jar
+ *
+ * Included in archive:
+ * bundle.a.jar
+ */
+ private static final String FEATURE_A = "feature.a.esa";
+ /*
+ * Bundle-SymbolicName: bundle.a.jar
+ */
+ private static final String BUNDLE_A = "bundle.a.jar";
+
+ private static boolean createdTestFiles;
+
+ @Before
+ public void createTestFiles() throws Exception {
+ if (createdTestFiles)
+ return;
+ createBundleA();
+ createFeatureA();
+ createdTestFiles = true;
+ }
+
+ private void createBundleA() throws IOException {
+ createBundle(name(BUNDLE_A));
+ }
+
+ private void createFeatureA() throws IOException {
+ createFeatureAManifest();
+ createSubsystem(FEATURE_A, BUNDLE_A);
+ }
+
+ private void createFeatureAManifest() throws IOException {
+ Map<String, String> attributes = new HashMap<String, String>();
+ attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, FEATURE_A);
+ attributes.put(SubsystemConstants.SUBSYSTEM_CONTENT, BUNDLE_A);
+ createManifest(FEATURE_A + ".mf", attributes);
+ }
+
+ @Test
+ public void testBundleStartsWhenSubsystemLeftInInvalidState() throws Exception {
+ Subsystem featureA = installSubsystemFromFile(FEATURE_A);
+ try {
+ startSubsystem(featureA);
+ assertBundleState(Bundle.ACTIVE, BUNDLE_A, featureA);
+ Bundle core = getSubsystemCoreBundle();
+ File file = core.getBundleContext().getDataFile(
+ featureA.getSubsystemId() + "/OSGI-INF/DEPLOYMENT.MF");
+ core.stop();
+ DeploymentManifest manifest = new DeploymentManifest(file);
+ FileOutputStream fos = new FileOutputStream(file);
+ try {
+ new DeploymentManifest.Builder()
+ .manifest(manifest)
+ .state(Subsystem.State.ACTIVE)
+ .build()
+ .write(fos);
+ }
+ finally {
+ fos.close();
+ }
+ core.start();
+ featureA = getChild(getRootSubsystem(), FEATURE_A);
+ assertBundleState(Bundle.ACTIVE, BUNDLE_A, featureA);
+ }
+ finally {
+ stopAndUninstallSubsystemSilently(featureA);
+ }
+ }
+
+ private Repository createTestRepository() throws IOException {
+ return new TestRepository.Builder()
+ .resource(createBundleAResource())
+ .build();
+ }
+
+ private byte[] createBundleAContent() throws IOException {
+ Manifest manifest = new Manifest();
+ manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
+ manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, BUNDLE_A);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ JarOutputStream jos = new JarOutputStream(baos, manifest);
+ jos.close();
+ return baos.toByteArray();
+ }
+
+ private Resource createBundleAResource() throws IOException {
+ return new TestRepositoryContent.Builder()
+ .capability(
+ new TestCapability.Builder()
+ .namespace(IdentityNamespace.IDENTITY_NAMESPACE)
+ .attribute(IdentityNamespace.IDENTITY_NAMESPACE, BUNDLE_A))
+ .content(createBundleAContent())
+ .build();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ try {
+ serviceRegistrations.add(
+ bundleContext.registerService(
+ Repository.class,
+ createTestRepository(),
+ null));
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}