diff --git a/pom.xml b/pom.xml index 7c4ec31..a966a5c 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,6 @@ 3.12.1 3.11.2.0 5.4.33.Final - 1.9.2 2.2.220 false 2.21.20 @@ -110,11 +109,6 @@ pom import - - org.commonjava.util - o11yphant-metrics-api - ${o11yphantVersion} - diff --git a/storage/pom.xml b/storage/pom.xml index b6c7a8c..c18e462 100644 --- a/storage/pom.xml +++ b/storage/pom.xml @@ -33,10 +33,6 @@ org.commonjava.util path-mapped-common - - org.commonjava.util - o11yphant-metrics-api - io.netty diff --git a/storage/src/main/java/org/commonjava/storage/pathmapped/metrics/MeasuredPathDB.java b/storage/src/main/java/org/commonjava/storage/pathmapped/metrics/MeasuredPathDB.java deleted file mode 100644 index b3f0adb..0000000 --- a/storage/src/main/java/org/commonjava/storage/pathmapped/metrics/MeasuredPathDB.java +++ /dev/null @@ -1,224 +0,0 @@ -/** - * Copyright (C) 2019 Red Hat, Inc. (nos-devel@redhat.com) - * - * Licensed 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.commonjava.storage.pathmapped.metrics; - -import org.commonjava.o11yphant.metrics.MetricsManager; -import org.commonjava.storage.pathmapped.model.FileChecksum; -import org.commonjava.storage.pathmapped.model.PathMap; -import org.commonjava.storage.pathmapped.model.Reclaim; -import org.commonjava.storage.pathmapped.spi.PathDB; - -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Supplier; - -import static org.commonjava.o11yphant.metrics.util.NameUtils.name; - -public class MeasuredPathDB - implements PathDB -{ - private final PathDB decorated; - - private final MetricsManager metricsManager; - - private final String metricPrefix; - - public MeasuredPathDB( PathDB decorated, MetricsManager metricsManager, String metricPrefix ) - { - this.decorated = decorated; - this.metricsManager = metricsManager; - this.metricPrefix = metricPrefix; - } - - @Override - public FileChecksum getFileChecksum( String checksum ) - { - return measure( () -> decorated.getFileChecksum( checksum ), "getFileChecksum" ); - } - - @Override - public Set getPathsByFileId( String fileId ) - { - return measure( () -> decorated.getPathsByFileId( fileId ), "getPathsByFileId" ); - } - - @Override - public List list( String fileSystem, String path, FileType fileType ) - { - return measure( () -> decorated.list( fileSystem, path, fileType ), "list" ); - } - - @Override - public List list( String fileSystem, String path, boolean recursive, int limit, FileType fileType ) - { - return measure( () -> decorated.list( fileSystem, path, recursive, limit, fileType ), "listRecursively" ); - } - - @Override - public PathMap getPathMap(String fileSystem, String path) { - return measure( () -> decorated.getPathMap( fileSystem, path ), "getPathMap" ); - } - - @Override - public long getFileLength( String fileSystem, String path ) - { - return measure( () -> decorated.getFileLength( fileSystem, path ), "getFileLength" ); - } - - @Override - public long getFileLastModified( String fileSystem, String path ) - { - return measure( () -> decorated.getFileLastModified( fileSystem, path ), "getFileLastModified" ); - } - - @Override - public FileType exists( String fileSystem, String path ) - { - return measure( () -> decorated.exists( fileSystem, path ), "exists" ); - } - - @Override - public boolean existsFile( String fileSystem, String path ) - { - return measure( () -> decorated.existsFile( fileSystem, path ), "existsFile" ); - } - - @Override - public void insert( String fileSystem, String path, Date creation, Date expiration, String fileId, long size, String fileStorage, - String checksum ) - { - measure( () -> decorated.insert( fileSystem, path, creation, expiration, fileId, size, fileStorage, checksum ), "insert" ); - } - - @Override - public boolean isDirectory( String fileSystem, String path ) - { - return measure( () -> decorated.isDirectory( fileSystem, path ), "isDirectory" ); - } - - @Override - public boolean isFile( String fileSystem, String path ) - { - return measure( () -> decorated.isFile( fileSystem, path ), "isFile" ); - } - - @Override - public boolean delete( String fileSystem, String path ) - { - return measure( () -> decorated.delete( fileSystem, path ), "delete" ); - } - - @Override - public boolean delete(String fileSystem, String path, boolean force) - { - return measure( () -> decorated.delete( fileSystem, path, force ), "delete" ); - } - - @Override - public Set getFileSystemContaining( Collection candidates, String path ) - { - return measure( () -> decorated.getFileSystemContaining( candidates, path ), "getFileSystemContaining" ); - } - - @Override - public String getFirstFileSystemContaining( List candidates, String path ) - { - return measure( () -> decorated.getFirstFileSystemContaining( candidates, path ), "getFirstFileSystemContaining" ); - } - - @Override - public void traverse( String fileSystem, String path, Consumer consumer, int limit, FileType fileType ) - { - measure( () -> decorated.traverse( fileSystem, path, consumer, limit, fileType ), "traverse" ); - } - - @Override - public String getStorageFile( String fileSystem, String path ) - { - return measure( () -> decorated.getStorageFile( fileSystem, path ), "getStorageFile" ); - } - - @Override - public boolean copy( String fromFileSystem, String fromPath, String toFileSystem, String toPath ) - { - return measure( () -> decorated.copy( fromFileSystem, fromPath, toFileSystem, toPath ), "copy" ); - } - - @Override - public boolean copy(String fromFileSystem, String fromPath, String toFileSystem, String toPath, Date creation, Date expiration) { - return measure( () -> decorated.copy( fromFileSystem, fromPath, toFileSystem, toPath, creation, expiration ), "copy" ); - } - - @Override - public void expire(String fileSystem, String path, Date expiration) - { - measure( () -> decorated.expire( fileSystem, path, expiration ), "expire" ); - } - - @Override - public void makeDirs( String fileSystem, String path ) - { - measure( () -> decorated.makeDirs( fileSystem, path ), "makeDirs" ); - } - - @Override - public List listOrphanedFiles( int limit ) - { - return measure( () -> decorated.listOrphanedFiles( limit ), "listOrphanedFiles" ); - } - - @Override - public void removeFromReclaim( Reclaim reclaim ) - { - decorated.removeFromReclaim( reclaim ); - } - - private void measure( Runnable runnable, String metricName ) - { - if ( metricsManager != null && isMetricEnabled( metricName ) ) - { - metricsManager.wrapWithStandardMetrics( () -> { - runnable.run(); - return null; - }, () -> name( metricPrefix, metricName ) ); - } - else - { - runnable.run(); - } - } - - private T measure( Supplier methodSupplier, String metricName ) - { - if ( metricsManager != null && isMetricEnabled( metricName ) ) - { - return metricsManager.wrapWithStandardMetrics( methodSupplier, () -> name( metricPrefix, metricName ) ); - } - else - { - return methodSupplier.get(); - } - } - - protected boolean isMetricEnabled( String metricName ) - { - return true; - } - -} diff --git a/storage/src/test/java/org/commonjava/storage/pathmapped/MeasuredPathDBTest.java b/storage/src/test/java/org/commonjava/storage/pathmapped/MeasuredPathDBTest.java deleted file mode 100644 index 7fb32f0..0000000 --- a/storage/src/test/java/org/commonjava/storage/pathmapped/MeasuredPathDBTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Copyright (C) 2019 Red Hat, Inc. (nos-devel@redhat.com) - * - * Licensed 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.commonjava.storage.pathmapped; - -/* -import org.apache.commons.io.IOUtils; -import org.cassandraunit.utils.EmbeddedCassandraServerHelper; -import org.commonjava.o11yphant.metrics.DefaultMetricRegistry; -import org.commonjava.o11yphant.metrics.DefaultMetricsManager; -import org.commonjava.storage.pathmapped.config.DefaultPathMappedStorageConfig; -import org.commonjava.storage.pathmapped.core.FileBasedPhysicalStore; -import org.commonjava.storage.pathmapped.core.PathMappedFileManager; -import org.commonjava.storage.pathmapped.metrics.MeasuredPathDB; -import org.commonjava.storage.pathmapped.pathdb.datastax.CassandraPathDB; -import org.commonjava.storage.pathmapped.spi.PathDB; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -*/ -import org.junit.Ignore; -/* -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import java.io.File; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import static java.lang.Thread.sleep; -import static org.commonjava.o11yphant.metrics.util.MetricUtils.newDefaultMetricRegistry; -import static org.commonjava.storage.pathmapped.pathdb.datastax.util.CassandraPathDBUtils.PROP_CASSANDRA_HOST; -import static org.commonjava.storage.pathmapped.pathdb.datastax.util.CassandraPathDBUtils.PROP_CASSANDRA_KEYSPACE; -import static org.commonjava.storage.pathmapped.pathdb.datastax.util.CassandraPathDBUtils.PROP_CASSANDRA_PORT; -*/ - -@Ignore -public class MeasuredPathDBTest -{ -/* - private final String TEST_FS = "test"; - - private final String PATH = "foo/bar/1.0/bar-1.0.pom"; - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - private PathMappedFileManager fileManager; - - private MeasuredPathDB measuredPathDB; - - @Before - public void setup() throws Exception - { - EmbeddedCassandraServerHelper.startEmbeddedCassandra(); - Map props = new HashMap<>(); - props.put( PROP_CASSANDRA_HOST, "localhost" ); - props.put( PROP_CASSANDRA_PORT, 9142 ); - props.put( PROP_CASSANDRA_KEYSPACE, "indystorage" ); - - DefaultPathMappedStorageConfig config = new DefaultPathMappedStorageConfig( props ); - // In test, we should let gc happened immediately when triggered. - config.setGcGracePeriodInHours( 0 ); - config.setDeduplicatePattern( "^(generic|npm|test).*" ); - PathDB pathDB = new CassandraPathDB( config ); - - DefaultMetricRegistry metricRegistry = newDefaultMetricRegistry(); - measuredPathDB = new MeasuredPathDB( pathDB, new DefaultMetricsManager( metricRegistry ), "pathDB" ); - - File baseDir = temp.newFolder(); - fileManager = new PathMappedFileManager( config, measuredPathDB, new FileBasedPhysicalStore( baseDir ) ); - - metricRegistry.startConsoleReporter( 3 ); - } - - @After - public void shutdown() - { - } - - @Test - public void run() throws Exception - { - try (OutputStream os = fileManager.openOutputStream( TEST_FS, PATH )) - { - Assert.assertNotNull( os ); - IOUtils.write( "This is a test".getBytes(), os ); - } - - try (InputStream in = fileManager.openInputStream( TEST_FS, PATH )) - { - IOUtils.toString( in ); - } - - fileManager.getFileSystemContaining( Arrays.asList( TEST_FS ), PATH ); - - fileManager.exists( TEST_FS, PATH ); - - sleep( 10000 ); - - } -*/ - -}