Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Sievers2014-04-07 10:49:00 -0400
committerJan Sievers2014-04-07 11:04:42 -0400
commit8e5e9f83e31b9e61a22b890bd688e38dd0c493f6 (patch)
tree50e752b20592ac66a1e086fe808aa3d8066549aa
parent7a0ae4bfecec7f05d00bfc5eaccb2a745191065d (diff)
downloadorg.eclipse.tycho.nexus-8e5e9f83e31b9e61a22b890bd688e38dd0c493f6.tar.gz
org.eclipse.tycho.nexus-8e5e9f83e31b9e61a22b890bd688e38dd0c493f6.tar.xz
org.eclipse.tycho.nexus-8e5e9f83e31b9e61a22b890bd688e38dd0c493f6.zip
423292 Fail to create unzip repository on Nexus 2.6.4 from GUI
the "500 - Internal server error" on creating new unzip repositories is a bug in the DefaultUnzipRepository's nexus state handling - invented method DefaultUnzipRepository.isNexusStarted() to respect both the nexus state - if accessible - and the nexus started event. - testCreateChangeStatusAndRemoveUnzipRepositoryAfterNexusStarted() reproduces the error. Bug: 423292 Signed-off-by: Stephan Weber <stephan.weber@sap.com> Change-Id: I5720b0a821f3dfb621c6ab7d4ebe9edffe9d60b5
-rw-r--r--unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java47
-rw-r--r--unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/JerseyUnzipVirtualRepository.java43
-rw-r--r--unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/JerseyUnzipVirtualRepositoryFactory.java52
-rw-r--r--unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/UnzipVirtualRepository.java16
-rw-r--r--unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepository.java61
5 files changed, 202 insertions, 17 deletions
diff --git a/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java
index c40cf2e..e4c831f 100644
--- a/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java
+++ b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/internal/plugin/UnzipRepositoryPluginITCase.java
@@ -12,7 +12,10 @@ package org.eclipse.tycho.nexus.internal.plugin;
import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.sonatype.nexus.client.core.subsystem.content.Location.repositoryLocation;
@@ -23,12 +26,15 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Properties;
+import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.apache.commons.io.IOUtils;
+import org.eclipse.tycho.nexus.unzip.internal.jersey.UnzipVirtualRepository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
@@ -36,6 +42,9 @@ import org.sonatype.nexus.client.core.exception.NexusClientNotFoundException;
import org.sonatype.nexus.client.core.subsystem.artifact.ResolveRequest;
import org.sonatype.nexus.client.core.subsystem.artifact.ResolveResponse;
import org.sonatype.nexus.client.core.subsystem.content.Location;
+import org.sonatype.nexus.client.core.subsystem.repository.Repositories;
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.core.subsystem.repository.maven.MavenHostedRepository;
import org.sonatype.nexus.testsuite.support.NexusStartAndStopStrategy;
import org.sonatype.nexus.testsuite.support.NexusStartAndStopStrategy.Strategy;
@@ -158,6 +167,44 @@ public class UnzipRepositoryPluginITCase extends AbstractUnzipRepositoryPluginIT
+ "-SNAPSHOT.jar"));
}
+ @Test
+ public void testCreateChangeStatusAndRemoveUnzipRepositoryAfterNexusStarted() throws Exception {
+ final String hostedRepositoryId = "hostedRepository";
+ final MavenHostedRepository hostedRepository = repositories().create(MavenHostedRepository.class,
+ hostedRepositoryId).save();
+
+ final String unzipRepositoryId = "hostedRepository.unzip";
+ final UnzipVirtualRepository unzipRepository = repositories()
+ .create(UnzipVirtualRepository.class, unzipRepositoryId).ofRepository(hostedRepositoryId).save();
+
+ assertTrue(unzipRepository.status().isInService());
+ assertFalse(unzipRepository.putOutOfService().status().isInService());
+ assertTrue(unzipRepository.putInService().status().isInService());
+
+ assertThat(getAllRepositoryIds(), hasItem(hostedRepositoryId));
+ assertThat(getAllRepositoryIds(), hasItem(unzipRepositoryId));
+
+ unzipRepository.remove();
+ hostedRepository.remove();
+
+ assertThat(getAllRepositoryIds(), not(hasItem(hostedRepositoryId)));
+ assertThat(getAllRepositoryIds(), not(hasItem(unzipRepositoryId)));
+ }
+
+ @SuppressWarnings("rawtypes")
+ private Set<String> getAllRepositoryIds() {
+ final Collection<Repository> allRepositories = repositories().get();
+ final Set<String> allRepositoryIds = new HashSet<String>();
+ for (final Repository repository : allRepositories) {
+ allRepositoryIds.add(repository.id());
+ }
+ return allRepositoryIds;
+ }
+
+ private Repositories repositories() {
+ return client().getSubsystem(Repositories.class);
+ }
+
private String getTestData(String localArtifactPath, String testDataPrefix) throws ZipException, IOException {
ZipFile zipFile = new ZipFile(testData().resolveFile(testDataPrefix + localArtifactPath));
String expectedContent;
diff --git a/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/JerseyUnzipVirtualRepository.java b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/JerseyUnzipVirtualRepository.java
new file mode 100644
index 0000000..d9fc2a3
--- /dev/null
+++ b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/JerseyUnzipVirtualRepository.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2014 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SAP AG - initial implementation
+ *******************************************************************************/
+package org.eclipse.tycho.nexus.unzip.internal.jersey;
+
+import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.JerseyVirtualRepository;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryShadowResource;
+
+public class JerseyUnzipVirtualRepository extends JerseyVirtualRepository<UnzipVirtualRepository> implements
+ UnzipVirtualRepository {
+ static final String PROVIDER = "org.eclipse.tycho.nexus.plugin.DefaultUnzipRepository";
+ private static final String PROVIDER_ROLE = "org.eclipse.tycho.nexus.internal.plugin.UnzipRepository";
+ private static final String REPO_TYPE = "virtual";
+
+ public JerseyUnzipVirtualRepository(final JerseyNexusClient nexusClient, final String id) {
+ super(nexusClient, id);
+ }
+
+ public JerseyUnzipVirtualRepository(final JerseyNexusClient nexusClient, final RepositoryShadowResource settings) {
+ super(nexusClient, settings);
+ }
+
+ @Override
+ protected RepositoryShadowResource createSettings() {
+ final RepositoryShadowResource settings = new RepositoryShadowResource();
+ settings.setName(settings.getId());
+ settings.setRepoType(REPO_TYPE);
+ settings.setProviderRole(PROVIDER_ROLE);
+ settings.setProvider(PROVIDER);
+ settings.setSyncAtStartup(false);
+ settings.setExposed(true);
+
+ return settings;
+ }
+}
diff --git a/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/JerseyUnzipVirtualRepositoryFactory.java b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/JerseyUnzipVirtualRepositoryFactory.java
new file mode 100644
index 0000000..0c1b24f
--- /dev/null
+++ b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/JerseyUnzipVirtualRepositoryFactory.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2014 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SAP AG - initial implementation
+ *******************************************************************************/
+package org.eclipse.tycho.nexus.unzip.internal.jersey;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.sonatype.nexus.client.core.subsystem.repository.Repository;
+import org.sonatype.nexus.client.internal.rest.jersey.subsystem.repository.JerseyVirtualRepositoryFactory;
+import org.sonatype.nexus.client.rest.jersey.JerseyNexusClient;
+import org.sonatype.nexus.rest.model.RepositoryBaseResource;
+import org.sonatype.nexus.rest.model.RepositoryShadowResource;
+
+@Named
+@Singleton
+public class JerseyUnzipVirtualRepositoryFactory extends JerseyVirtualRepositoryFactory {
+ @Override
+ public int canAdapt(final RepositoryBaseResource resource) {
+ int score = super.canAdapt(resource);
+ if (score > 0) {
+ final String provider = resource.getProvider();
+ if (JerseyUnzipVirtualRepository.PROVIDER.equals(provider)) {
+ score++;
+ }
+ }
+ return score;
+ }
+
+ @Override
+ public JerseyUnzipVirtualRepository adapt(final JerseyNexusClient nexusClient, final RepositoryBaseResource resource) {
+ return new JerseyUnzipVirtualRepository(nexusClient, (RepositoryShadowResource) resource);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public boolean canCreate(final Class<? extends Repository> type) {
+ return UnzipVirtualRepository.class.equals(type);
+ }
+
+ @Override
+ public JerseyUnzipVirtualRepository create(final JerseyNexusClient nexusClient, final String id) {
+ return new JerseyUnzipVirtualRepository(nexusClient, id);
+ }
+}
diff --git a/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/UnzipVirtualRepository.java b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/UnzipVirtualRepository.java
new file mode 100644
index 0000000..1d62ca3
--- /dev/null
+++ b/unzip-repository-plugin-its/src/test/java/org/eclipse/tycho/nexus/unzip/internal/jersey/UnzipVirtualRepository.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2014 SAP AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SAP AG - initial implementation
+ *******************************************************************************/
+package org.eclipse.tycho.nexus.unzip.internal.jersey;
+
+import org.sonatype.nexus.client.core.subsystem.repository.VirtualRepository;
+
+public interface UnzipVirtualRepository extends VirtualRepository<UnzipVirtualRepository> {
+}
diff --git a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepository.java b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepository.java
index 2ad2eb9..e7273d5 100644
--- a/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepository.java
+++ b/unzip-repository-plugin/src/main/java/org/eclipse/tycho/nexus/internal/plugin/DefaultUnzipRepository.java
@@ -22,6 +22,8 @@ import org.eclipse.tycho.nexus.internal.plugin.cache.UnzipCache;
import org.eclipse.tycho.nexus.internal.plugin.storage.Util;
import org.eclipse.tycho.nexus.internal.plugin.storage.ZipAwareStorageCollectionItem;
import org.eclipse.tycho.nexus.internal.plugin.storage.ZippedItem;
+import org.sonatype.nexus.ApplicationStatusSource;
+import org.sonatype.nexus.SystemState;
import org.sonatype.nexus.configuration.Configurator;
import org.sonatype.nexus.configuration.model.CRepository;
import org.sonatype.nexus.configuration.model.CRepositoryExternalConfigurationHolderFactory;
@@ -83,13 +85,36 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
@Requirement(hint = "maven2")
private ContentClass masterContentClass;
- private RepositoryKind repositoryKind;
-
- private boolean isNexusStarted = false;
+ @Requirement
+ private ApplicationStatusSource statusSource;
+ private RepositoryKind repositoryKind;
+ private UnzipCache cache;
+ private boolean processedNexusStartedEvent = false;
private boolean isMasterAvailable = false;
- private UnzipCache cache;
+ // If a class instance of DefaultUnzipRepository is created before Nexus startup finished the field statusSource gets
+ // and keeps an invalid proxy instance from plexus which always throws an IllegalStateException if being asked
+ // for the current Nexus state. All these instances get the NexusStartedEvent and with it set the MasterRepository
+ // from what is stored in the ExternalConfiguration.
+ // This is true for all unzip repositories being listed in the nexus.xml file on startup.
+ //
+ // If a class instance of DefaultUnzipRepository is created e.g. from the UI after Nexus startup finished it
+ // won't ever get a NexusStartedEvent so for these DefaultUnzipRepository instances the field
+ // processedNexusStartedEvent will always be false. But the field statusSource is now valid and we can ask for the
+ // correct state.
+ private boolean isNexusStarted() {
+ if (processedNexusStartedEvent) {
+ return true;
+ }
+
+ try {
+ final SystemState systemState = statusSource.getSystemStatus().getState();
+ return systemState.equals(SystemState.STARTED);
+ } catch (final IllegalStateException e) {
+ }
+ return false;
+ }
@Override
protected Configurator getConfigurator() {
@@ -145,7 +170,7 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
super.setMasterRepository(repository);
isMasterAvailable = true;
} catch (final NoSuchRepositoryException e) {
- if (isNexusStarted) {
+ if (isNexusStarted()) {
throw e;
} else {
// NoSuchRepositoryException yet. Just remember the id
@@ -164,7 +189,7 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
// see comment at setMasterRepositoryId(String id)
@Override
public Repository getMasterRepository() {
- if (isNexusStarted && isMasterAvailable) {
+ if (isNexusStarted() && isMasterAvailable) {
return super.getMasterRepository();
}
return null;
@@ -174,15 +199,18 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
// see comment at setMasterRepositoryId(String id)
@Override
public LocalStatus getLocalStatus() {
- if (isNexusStarted && isMasterAvailable) {
- return super.getLocalStatus();
+ LocalStatus localStatus = null;
+ if (isNexusStarted() && isMasterAvailable) {
+ localStatus = super.getLocalStatus();
} else {
- String localStatus = getCurrentConfiguration(false).getLocalStatus();
- if (localStatus == null) {
- return LocalStatus.OUT_OF_SERVICE;
+ final String localStatusString = getCurrentConfiguration(false).getLocalStatus();
+ if (localStatusString == null) {
+ localStatus = LocalStatus.OUT_OF_SERVICE;
+ } else {
+ localStatus = LocalStatus.valueOf(localStatusString);
}
- return LocalStatus.valueOf(localStatus);
}
+ return localStatus;
}
@Subscribe
@@ -190,8 +218,6 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
if (!isMasterAvailable) {
String repositoryId = getExternalConfiguration(false).getMasterRepositoryId();
try {
- getLogger().debug(
- "setting master repository '" + repositoryId + "' for unzip repository '" + getId() + "'");
setMasterRepositoryId(repositoryId);
} catch (NoSuchRepositoryException e) {
getLogger().error("[" + repositoryId + "] " + "cannot set master repository " + e.getMessage());
@@ -200,14 +226,15 @@ public class DefaultUnzipRepository extends AbstractShadowRepository implements
getLogger().error("[" + repositoryId + "] " + "cannot set master repository " + e.getMessage());
}
}
- isNexusStarted = true;
+ processedNexusStartedEvent = true;
}
@Subscribe
public void onRepositoryRegistryEventAdd(RepositoryRegistryEventAdd evt) {
- if (getMasterRepository() != null && evt.getRepository().getId().equals(getMasterRepository().getId())) {
+ final String eventRepositoryId = evt.getRepository().getId();
+ if (super.getMasterRepository() != null && eventRepositoryId.equals(super.getMasterRepository().getId())) {
try {
- setMasterRepositoryId(evt.getRepository().getId());
+ setMasterRepositoryId(eventRepositoryId);
} catch (final NoSuchRepositoryException e) {
getLogger().warn("Master Repository not available", e);
} catch (final IncompatibleMasterRepositoryException e) {

Back to the top