Skip to content

Commit

Permalink
upstream: b=master,r=d2a592382fa343d6cd13c45b69a9edffe39c68c1,t=2017-…
Browse files Browse the repository at this point in the history
…04-07-1629-26139
  • Loading branch information
sonatype-zion committed Apr 7, 2017
1 parent 864e629 commit d077248
Show file tree
Hide file tree
Showing 21 changed files with 506 additions and 689 deletions.
2 changes: 1 addition & 1 deletion buildsupport/db/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<packaging>pom</packaging>

<properties>
<orientdb.version>2.2.SONATYPE-SNAPSHOT</orientdb.version>
<orientdb.version>2.2.18</orientdb.version>
<hazelcast.version>3.6.6</hazelcast.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.common.app;

import org.sonatype.nexus.common.app.ManagedLifecycle.Phase;

/**
* Manages {@link ManagedLifecycle} components.
*
* @since 3.3
*/
public interface ManagedLifecycleManager
{
/**
* Returns the current phase.
*/
Phase getCurrentPhase();

/**
* Attempts to move to the target phase by starting (or stopping) components phase-by-phase. If any components have
* appeared since the last request which belong to the current phase or earlier then they are automatically started
* before the current phase is changed. Similarly components that have disappeared are stopped.
*/
void to(Phase targetPhase) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,11 @@ protected Object invokeMethod(final RegisteredMethod method, final Object action
}

private Response handleException(final RegisteredMethod method, final Throwable e) {
// debug logging for sanity
log.debug("Failed to invoke action method: {}, java-method: {}",
method.getFullName(), method.getFullJavaMethodName(), e);
// debug logging for sanity (without stacktrace for suppressed exception)
log.debug("Failed to invoke action method: {}, java-method: {}, exception message: {}",
method.getFullName(), method.getFullJavaMethodName(), e.getMessage(),
isSuppressedException(e) ? null : e);


// handle validation message responses which have contents
if (e instanceof ConstraintViolationException) {
Expand All @@ -261,14 +263,17 @@ private Response handleException(final RegisteredMethod method, final Throwable
}
}

log.error("FAILED to invoke action method: {}, java-method: {}",
method.getFullName(), method.getFullJavaMethodName(), suppressException(e));
// exception logging for all non-suppressed exceptions
if (!isSuppressedException(e)) {
log.error("Failed to invoke action method: {}, java-method: {}",
method.getFullName(), method.getFullJavaMethodName(), e);
}

return asResponse(error(e));
}

private Throwable suppressException(final Throwable e) {
return SUPPRESSED_EXCEPTIONS.stream().anyMatch(ex -> ex.isInstance(e)) ? null : e;
private boolean isSuppressedException(final Throwable e) {
return SUPPRESSED_EXCEPTIONS.stream().anyMatch(ex -> ex.isInstance(e));
}

private Response asResponse(final Object result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.sonatype.nexus.common.app.ManagedLifecycleManager;

import com.codahale.metrics.SharedMetricRegistries;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -114,7 +116,7 @@ public class NexusContextListener

private Injector injector;

private NexusLifecycleManager lifecycleManager;
private ManagedLifecycleManager lifecycleManager;

private ServiceRegistration<Filter> registration;

Expand Down Expand Up @@ -145,7 +147,7 @@ public void contextInitialized(final ServletContextEvent event) {
extender.doStart(); // start tracking nexus bundles

try {
lifecycleManager = injector.getInstance(NexusLifecycleManager.class);
lifecycleManager = injector.getInstance(ManagedLifecycleManager.class);

lifecycleManager.to(LOGGING);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import javax.servlet.ServletContext;

import org.sonatype.nexus.common.app.ManagedLifecycleManager;
import org.sonatype.nexus.common.stateguard.StateGuardModule;
import org.sonatype.nexus.security.WebSecurityModule;
import org.sonatype.nexus.transaction.TransactionModule;
Expand Down Expand Up @@ -66,7 +67,7 @@ protected void configure() {
requireBinding(GuiceFilter.class);
requireBinding(BeanManager.class);

bind(NexusLifecycleManager.class);
bind(ManagedLifecycleManager.class).to(NexusLifecycleManager.class);

bind(ServletContext.class).toInstance(servletContext);
bind(ParameterKeys.PROPERTIES).toInstance(nexusProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.sonatype.goodies.lifecycle.Lifecycle;
import org.sonatype.nexus.common.app.ManagedLifecycle;
import org.sonatype.nexus.common.app.ManagedLifecycle.Phase;
import org.sonatype.nexus.common.app.ManagedLifecycleManager;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.HashMultimap;
Expand All @@ -46,6 +47,7 @@
@Singleton
public class NexusLifecycleManager
extends ComponentSupport
implements ManagedLifecycleManager
{
private static final Phase[] PHASES = Phase.values();

Expand All @@ -64,15 +66,12 @@ public NexusLifecycleManager(BeanLocator locator) {
locator.watch(Key.get(BundleContext.class), new BundleContextMediator(), this);
}

@Override
public Phase getCurrentPhase() {
return currentPhase;
}

/**
* Attempts to move to the target phase by starting (or stopping) components phase-by-phase. If any components have
* appeared since the last request which belong to the current phase or earlier then they are automatically started
* before the current phase is changed. Similarly components that have disappeared are stopped.
*/
@Override
public synchronized void to(Phase targetPhase) throws Exception {

final int target = targetPhase.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ public static Option nexusDistribution(final MavenUrlReference frameworkZip) {
return composite(

// mimic nexus script
vmOption("-Xms1200M"),
vmOption("-Xmx1200M"),
vmOption("-Xms600M"),
vmOption("-Xmx600M"),
vmOption("-XX:MaxDirectMemorySize=2G"),
vmOption("-XX:+UnlockDiagnosticVMOptions"),
vmOption("-XX:+UnsyncloadClass"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
describe('NX.controller.Permissions', function() {
var data = [
{
id: 'permission1',
permitted: 'false'
}
];

beforeAll(function(done) {
Ext.onReady(function() {
NX.store.Permission.addMembers({
proxy: {
type: 'memory',
data: data,
reader: {
type: 'json'
}
}
});

done();
});
});

describe('fetchPermissions', function() {
it('loads data from the memory proxy', function() {
var permissions = Ext.create('NX.controller.Permissions');
permissions.fetchPermissions();
expect(permissions.getStore('Permission').getById('permission1').get('permitted')).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.repository.httpclient.internal;
package org.sonatype.nexus.repository.httpclient;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.sonatype.nexus.common.sequence.FibonacciNumberSequence;
import org.sonatype.nexus.common.sequence.NumberSequence;
import org.sonatype.nexus.repository.httpclient.FilteredHttpClientSupport;
import org.sonatype.nexus.repository.httpclient.RemoteBlockedIOException;
import org.sonatype.nexus.repository.httpclient.RemoteConnectionStatus;
import org.sonatype.nexus.repository.httpclient.RemoteConnectionStatusObserver;
import org.sonatype.nexus.repository.httpclient.RemoteConnectionStatusType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.sonatype.nexus.repository.config.Configuration;
import org.sonatype.nexus.repository.config.ConfigurationFacet;
import org.sonatype.nexus.repository.httpclient.HttpClientFacet;
import org.sonatype.nexus.repository.httpclient.internal.RemoteBlockedIOException;
import org.sonatype.nexus.repository.httpclient.RemoteBlockedIOException;
import org.sonatype.nexus.repository.view.Content;
import org.sonatype.nexus.repository.view.Context;
import org.sonatype.nexus.repository.view.payloads.HttpEntityPayload;
Expand Down Expand Up @@ -187,7 +187,7 @@ public Content get(final Context context) throws IOException {
}
catch (IOException e) {
Repository repository = context.getRepository();
log.trace("Failed to fetch: {}, from repository: {}", getUrl(context), repository.getName(), e);
log.trace("Failed to fetch: {} from repository: {}", getUrl(context), repository.getName(), e);
logContentOrThrow(content, getUrl(context), e);
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package org.sonatype.nexus.repository.tools

import java.util.concurrent.TimeUnit

import javax.annotation.Nullable
import javax.inject.Inject
import javax.inject.Named
import javax.validation.constraints.NotNull
Expand All @@ -34,13 +33,13 @@ import com.google.common.base.Stopwatch
import groovy.transform.ToString

import static com.google.common.base.Preconditions.checkNotNull
import static org.sonatype.nexus.repository.tools.DeadBlobFinder.ResultState.ASSET_DELETED
import static org.sonatype.nexus.repository.tools.DeadBlobFinder.ResultState.DELETED
import static org.sonatype.nexus.repository.tools.DeadBlobFinder.ResultState.MISSING_BLOB_REF
import static org.sonatype.nexus.repository.tools.DeadBlobFinder.ResultState.SHA1_DISAGREEMENT
import static org.sonatype.nexus.repository.tools.DeadBlobFinder.ResultState.UNAVAILABLE_BLOB
import static org.sonatype.nexus.repository.tools.DeadBlobFinder.ResultState.UNKNOWN
import static org.sonatype.nexus.repository.tools.DeadBlobFinder.ResultState.UNREADABLE_BLOB
import static org.sonatype.nexus.repository.tools.ResultState.ASSET_DELETED
import static org.sonatype.nexus.repository.tools.ResultState.DELETED
import static org.sonatype.nexus.repository.tools.ResultState.MISSING_BLOB_REF
import static org.sonatype.nexus.repository.tools.ResultState.SHA1_DISAGREEMENT
import static org.sonatype.nexus.repository.tools.ResultState.UNAVAILABLE_BLOB
import static org.sonatype.nexus.repository.tools.ResultState.UNKNOWN
import static org.sonatype.nexus.repository.tools.ResultState.UNREADABLE_BLOB

/**
* Examines Asset metadata and confirms the sha1 of all referenced blobs. Reports on any instances where
Expand Down Expand Up @@ -222,35 +221,4 @@ class DeadBlobFinder
private static lastUpdated(DeadBlobResult deadBlobResult) {
deadBlobResult.asset?.lastUpdated()
}

@ToString(includePackage = false)
class DeadBlobResult
{
final String repositoryName

final Asset asset

final String errorMessage

final ResultState resultState

DeadBlobResult(final String repositoryName, @Nullable final Asset asset, final ResultState resultState,
final String errorMessage)
{
this.repositoryName = checkNotNull(repositoryName)
this.asset = asset
this.resultState = checkNotNull(resultState)
this.errorMessage = checkNotNull(errorMessage)
}
}

enum ResultState {
ASSET_DELETED, // DB record was deleted during inspection
DELETED, // DB record references blobRef which has since been deleted
MISSING_BLOB_REF, // DB record has no blobRef
SHA1_DISAGREEMENT, // DB record and blob have different SHA1
UNAVAILABLE_BLOB, // blob has an inputstream that reports 0 when calling isAvailable()
UNKNOWN,
UNREADABLE_BLOB, // Unable to read blob from disk
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.repository.tools

import javax.annotation.Nullable

import org.sonatype.nexus.repository.storage.Asset

import groovy.transform.ToString

import static com.google.common.base.Preconditions.checkNotNull

/**
* @since 3.3
*/
@ToString(includePackage = false)
class DeadBlobResult
{
final String repositoryName

final Asset asset

final String errorMessage

final ResultState resultState

DeadBlobResult(final String repositoryName, @Nullable final Asset asset, final ResultState resultState,
final String errorMessage)
{
this.repositoryName = checkNotNull(repositoryName)
this.asset = asset
this.resultState = checkNotNull(resultState)
this.errorMessage = checkNotNull(errorMessage)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.repository.tools

/**
* Possible error states that can be detected by {@link DeadBlobFinder}.
* @since 3.3
*/
enum ResultState {
ASSET_DELETED, // DB record was deleted during inspection
DELETED, // DB record references blobRef which has since been deleted
MISSING_BLOB_REF, // DB record has no blobRef
SHA1_DISAGREEMENT, // DB record and blob have different SHA1
UNAVAILABLE_BLOB, // blob has an inputstream that reports 0 when calling isAvailable()
UNKNOWN,
UNREADABLE_BLOB, // Unable to read blob from disk
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.sonatype.nexus.repository.cache.CacheController;
import org.sonatype.nexus.repository.cache.CacheControllerHolder;
import org.sonatype.nexus.repository.cache.CacheInfo;
import org.sonatype.nexus.repository.httpclient.internal.RemoteBlockedIOException;
import org.sonatype.nexus.repository.httpclient.RemoteBlockedIOException;
import org.sonatype.nexus.repository.view.Content;
import org.sonatype.nexus.repository.view.Context;

Expand Down
Loading

0 comments on commit d077248

Please sign in to comment.