Search in sources :

Example 6 with OrderedRows

use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.

the class CassandraMetadataRepository method updateFacets.

/**
 * iterate over available facets to remove/add from the artifactMetadata
 *
 * @param facetedMetadata
 * @param artifactMetadataModel only use for the key
 */
private void updateFacets(final FacetedMetadata facetedMetadata, final ArtifactMetadataModel artifactMetadataModel) {
    String cf = cassandraArchivaManager.getMetadataFacetFamilyName();
    for (final String facetId : metadataFacetFactories.keySet()) {
        MetadataFacet metadataFacet = facetedMetadata.getFacet(facetId);
        if (metadataFacet == null) {
            continue;
        }
        // clean first
        QueryResult<OrderedRows<String, String, String>> result = // 
        HFactory.createRangeSlicesQuery(keyspace, ss, ss, ss).setColumnFamily(// 
        cf).setColumnNames(// 
        REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
        artifactMetadataModel.getRepositoryId()).addEqualsExpression(NAMESPACE_ID.toString(), // 
        artifactMetadataModel.getNamespace()).addEqualsExpression(PROJECT_ID.toString(), // 
        artifactMetadataModel.getProject()).addEqualsExpression(PROJECT_VERSION.toString(), // 
        artifactMetadataModel.getProjectVersion()).addEqualsExpression(FACET_ID.toString(), // 
        facetId).execute();
        for (Row<String, String, String> row : result.get().getList()) {
            this.metadataFacetTemplate.deleteRow(row.getKey());
        }
        Map<String, String> properties = metadataFacet.toProperties();
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            String key = new MetadataFacetModel.KeyBuilder().withKey(entry.getKey()).withArtifactMetadataModel(artifactMetadataModel).withFacetId(facetId).withName(metadataFacet.getName()).build();
            Mutator<String> mutator = // 
            metadataFacetTemplate.createMutator().addInsertion(key, cf, // 
            column(REPOSITORY_NAME.toString(), artifactMetadataModel.getRepositoryId())).addInsertion(key, cf, // 
            column(NAMESPACE_ID.toString(), artifactMetadataModel.getNamespace())).addInsertion(key, cf, // 
            column(PROJECT_ID.toString(), artifactMetadataModel.getProject())).addInsertion(key, cf, // 
            column(PROJECT_VERSION.toString(), artifactMetadataModel.getProjectVersion())).addInsertion(key, cf, // 
            column(FACET_ID.toString(), facetId)).addInsertion(key, cf, // 
            column(KEY.toString(), entry.getKey())).addInsertion(key, cf, column(VALUE.toString(), entry.getValue()));
            if (metadataFacet.getName() != null) {
                mutator.addInsertion(key, cf, column(NAME.toString(), metadataFacet.getName()));
            }
            mutator.execute();
        }
    }
}
Also used : MetadataFacetModel(org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with OrderedRows

use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.

the class CassandraMetadataRepository method getOrCreateRepository.

/**
 * if the repository doesn't exist it will be created
 *
 * @param repositoryId
 * @return
 */
public Repository getOrCreateRepository(String repositoryId) throws MetadataRepositoryException {
    String cf = cassandraArchivaManager.getRepositoryFamilyName();
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, StringSerializer.get(), StringSerializer.get(), // 
    StringSerializer.get()).setColumnFamily(// 
    cf).setColumnNames(// 
    REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repositoryId).execute();
    if (result.get().getCount() < 1) {
        // we need to create the repository
        Repository repository = new Repository(repositoryId);
        try {
            MutationResult mutationResult = // 
            HFactory.createMutator(keyspace, StringSerializer.get()).addInsertion(repositoryId, cf, // 
            CassandraUtils.column(REPOSITORY_NAME.toString(), repository.getName())).execute();
            logger.debug("time to insert repository: {}", mutationResult.getExecutionTimeMicro());
            return repository;
        } catch (HInvalidRequestException e) {
            logger.error(e.getMessage(), e);
            throw new MetadataRepositoryException(e.getMessage(), e);
        }
    }
    return new Repository(result.get().getList().get(0).getColumnSlice().getColumnByName(REPOSITORY_NAME.toString()).getValue());
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) HInvalidRequestException(me.prettyprint.hector.api.exceptions.HInvalidRequestException) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) MutationResult(me.prettyprint.hector.api.mutation.MutationResult)

Example 8 with OrderedRows

use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.

the class CassandraMetadataRepository method getProjectVersion.

@Override
public ProjectVersionMetadata getProjectVersion(final String repoId, final String namespace, final String projectId, final String projectVersion) throws MetadataResolutionException {
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(// 
    PROJECT_VERSION.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repoId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespace).addEqualsExpression(PROJECT_ID.toString(), // 
    projectId).addEqualsExpression(PROJECT_VERSION.toString(), // 
    projectVersion).execute();
    if (result.get().getCount() < 1) {
        return null;
    }
    String key = result.get().iterator().next().getKey();
    ColumnFamilyResult<String, String> columnFamilyResult = this.projectVersionMetadataTemplate.queryColumns(key);
    if (!columnFamilyResult.hasResults()) {
        return null;
    }
    ProjectVersionMetadata projectVersionMetadata = new ProjectVersionMetadata();
    projectVersionMetadata.setId(columnFamilyResult.getString(PROJECT_VERSION.toString()));
    projectVersionMetadata.setDescription(columnFamilyResult.getString(DESCRIPTION.toString()));
    projectVersionMetadata.setName(columnFamilyResult.getString(NAME.toString()));
    projectVersionMetadata.setIncomplete(Boolean.parseBoolean(columnFamilyResult.getString("incomplete")));
    projectVersionMetadata.setUrl(columnFamilyResult.getString(URL.toString()));
    {
        String ciUrl = columnFamilyResult.getString("ciManagement.url");
        String ciSystem = columnFamilyResult.getString("ciManagement.system");
        if (StringUtils.isNotEmpty(ciSystem) || StringUtils.isNotEmpty(ciUrl)) {
            projectVersionMetadata.setCiManagement(new CiManagement(ciSystem, ciUrl));
        }
    }
    {
        String issueUrl = columnFamilyResult.getString("issueManagement.url");
        String issueSystem = columnFamilyResult.getString("issueManagement.system");
        if (StringUtils.isNotEmpty(issueSystem) || StringUtils.isNotEmpty(issueUrl)) {
            projectVersionMetadata.setIssueManagement(new IssueManagement(issueSystem, issueUrl));
        }
    }
    {
        String organizationUrl = columnFamilyResult.getString("organization.url");
        String organizationName = columnFamilyResult.getString("organization.name");
        if (StringUtils.isNotEmpty(organizationUrl) || StringUtils.isNotEmpty(organizationName)) {
            projectVersionMetadata.setOrganization(new Organization(organizationName, organizationUrl));
        }
    }
    {
        String devConn = columnFamilyResult.getString("scm.developerConnection");
        String conn = columnFamilyResult.getString("scm.connection");
        String url = columnFamilyResult.getString("scm.url");
        if (StringUtils.isNotEmpty(devConn) || StringUtils.isNotEmpty(conn) || StringUtils.isNotEmpty(url)) {
            projectVersionMetadata.setScm(new Scm(conn, devConn, url));
        }
    }
    projectVersionMetadata.setMailingLists(getMailingLists(key));
    projectVersionMetadata.setLicenses(getLicenses(key));
    projectVersionMetadata.setDependencies(getDependencies(key));
    // facets
    result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getMetadataFacetFamilyName()).setColumnNames(FACET_ID.toString(), KEY.toString(), VALUE.toString(), // 
    NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repoId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespace).addEqualsExpression(PROJECT_ID.toString(), // 
    projectId).addEqualsExpression(PROJECT_VERSION.toString(), // 
    projectVersion).execute();
    Map<String, Map<String, String>> metadataFacetsPerFacetIds = new HashMap<>();
    for (Row<String, String, String> row : result.get()) {
        ColumnSlice<String, String> columnSlice = row.getColumnSlice();
        String facetId = getStringValue(columnSlice, FACET_ID.toString());
        Map<String, String> metaValues = metadataFacetsPerFacetIds.get(facetId);
        if (metaValues == null) {
            metaValues = new HashMap<>();
            metadataFacetsPerFacetIds.put(facetId, metaValues);
        }
        metaValues.put(getStringValue(columnSlice, KEY.toString()), getStringValue(columnSlice, VALUE.toString()));
    }
    if (!metadataFacetsPerFacetIds.isEmpty()) {
        for (Map.Entry<String, Map<String, String>> entry : metadataFacetsPerFacetIds.entrySet()) {
            MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(entry.getKey());
            if (metadataFacetFactory != null) {
                MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet();
                metadataFacet.fromProperties(entry.getValue());
                projectVersionMetadata.addFacet(metadataFacet);
            }
        }
    }
    return projectVersionMetadata;
}
Also used : Organization(org.apache.archiva.metadata.model.Organization) HashMap(java.util.HashMap) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) CiManagement(org.apache.archiva.metadata.model.CiManagement) Scm(org.apache.archiva.metadata.model.Scm) Map(java.util.Map) HashMap(java.util.HashMap) IssueManagement(org.apache.archiva.metadata.model.IssueManagement)

Example 9 with OrderedRows

use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.

the class CassandraMetadataRepository method getRepositories.

@Override
public Collection<String> getRepositories() throws MetadataRepositoryException {
    try {
        logger.debug("getRepositories");
        final // 
        QueryResult<OrderedRows<String, String, String>> cResult = // 
        HFactory.createRangeSlicesQuery(// 
        cassandraArchivaManager.getKeyspace(), ss, ss, // 
        ss).setColumnFamily(// 
        cassandraArchivaManager.getRepositoryFamilyName()).setColumnNames(// 
        REPOSITORY_NAME.toString()).setRange(null, null, false, // 
        Integer.MAX_VALUE).execute();
        List<String> repoIds = new ArrayList<>(cResult.get().getCount());
        for (Row<String, String, String> row : cResult.get()) {
            repoIds.add(getStringValue(row.getColumnSlice(), REPOSITORY_NAME.toString()));
        }
        return repoIds;
    } catch (PersistenceException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) ArrayList(java.util.ArrayList) PersistenceException(javax.persistence.PersistenceException)

Example 10 with OrderedRows

use of me.prettyprint.hector.api.beans.OrderedRows in project archiva by apache.

the class CassandraMetadataRepository method updateProjectVersion.

@Override
public void updateProjectVersion(String repositoryId, String namespaceId, String projectId, ProjectVersionMetadata versionMetadata) throws MetadataRepositoryException {
    try {
        Namespace namespace = getNamespace(repositoryId, namespaceId);
        if (namespace == null) {
            updateOrAddNamespace(repositoryId, namespaceId);
        }
        if (getProject(repositoryId, namespaceId, projectId) == null) {
            ProjectMetadata projectMetadata = new ProjectMetadata();
            projectMetadata.setNamespace(namespaceId);
            projectMetadata.setId(projectId);
            updateProject(repositoryId, projectMetadata);
        }
    } catch (MetadataResolutionException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(// 
    PROJECT_VERSION.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
    namespaceId).addEqualsExpression(PROJECT_ID.toString(), // 
    projectId).addEqualsExpression(PROJECT_VERSION.toString(), // 
    versionMetadata.getId()).execute();
    ProjectVersionMetadataModel projectVersionMetadataModel = null;
    boolean creation = true;
    if (result.get().getCount() > 0) {
        projectVersionMetadataModel = mapProjectVersionMetadataModel(result.get().getList().get(0).getColumnSlice());
        creation = false;
    } else {
        projectVersionMetadataModel = getModelMapper().map(versionMetadata, ProjectVersionMetadataModel.class);
    }
    projectVersionMetadataModel.setProjectId(projectId);
    projectVersionMetadataModel.setNamespace(new Namespace(namespaceId, new Repository(repositoryId)));
    projectVersionMetadataModel.setCiManagement(versionMetadata.getCiManagement());
    projectVersionMetadataModel.setIssueManagement(versionMetadata.getIssueManagement());
    projectVersionMetadataModel.setOrganization(versionMetadata.getOrganization());
    projectVersionMetadataModel.setScm(versionMetadata.getScm());
    projectVersionMetadataModel.setMailingLists(versionMetadata.getMailingLists());
    projectVersionMetadataModel.setDependencies(versionMetadata.getDependencies());
    projectVersionMetadataModel.setLicenses(versionMetadata.getLicenses());
    // we don't test of repository and namespace really exist !
    String key = // 
    new ProjectVersionMetadataModel.KeyBuilder().withRepository(// 
    repositoryId).withNamespace(// 
    namespaceId).withProjectId(// 
    projectId).withProjectVersion(// 
    versionMetadata.getVersion()).withId(// 
    versionMetadata.getId()).build();
    // FIXME nested objects to store!!!
    if (creation) {
        String cf = cassandraArchivaManager.getProjectVersionMetadataFamilyName();
        Mutator<String> mutator = projectVersionMetadataTemplate.createMutator().addInsertion(key, cf, // 
        column(PROJECT_ID.toString(), projectId)).addInsertion(key, cf, // 
        column(REPOSITORY_NAME.toString(), repositoryId)).addInsertion(key, cf, // 
        column(NAMESPACE_ID.toString(), namespaceId)).addInsertion(key, cf, // 
        column(PROJECT_VERSION.toString(), versionMetadata.getVersion()));
        addInsertion(mutator, key, cf, DESCRIPTION.toString(), versionMetadata.getDescription());
        addInsertion(mutator, key, cf, NAME.toString(), versionMetadata.getName());
        addInsertion(mutator, key, cf, "incomplete", Boolean.toString(versionMetadata.isIncomplete()));
        addInsertion(mutator, key, cf, URL.toString(), versionMetadata.getUrl());
        {
            CiManagement ci = versionMetadata.getCiManagement();
            if (ci != null) {
                addInsertion(mutator, key, cf, "ciManagement.system", ci.getSystem());
                addInsertion(mutator, key, cf, "ciManagement.url", ci.getUrl());
            }
        }
        {
            IssueManagement issueManagement = versionMetadata.getIssueManagement();
            if (issueManagement != null) {
                addInsertion(mutator, key, cf, "issueManagement.system", issueManagement.getSystem());
                addInsertion(mutator, key, cf, "issueManagement.url", issueManagement.getUrl());
            }
        }
        {
            Organization organization = versionMetadata.getOrganization();
            if (organization != null) {
                addInsertion(mutator, key, cf, "organization.name", organization.getName());
                addInsertion(mutator, key, cf, "organization.url", organization.getUrl());
            }
        }
        {
            Scm scm = versionMetadata.getScm();
            if (scm != null) {
                addInsertion(mutator, key, cf, "scm.url", scm.getUrl());
                addInsertion(mutator, key, cf, "scm.connection", scm.getConnection());
                addInsertion(mutator, key, cf, "scm.developerConnection", scm.getDeveloperConnection());
            }
        }
        recordMailingList(key, versionMetadata.getMailingLists());
        recordLicenses(key, versionMetadata.getLicenses());
        recordDependencies(key, versionMetadata.getDependencies(), repositoryId);
        MutationResult mutationResult = mutator.execute();
    } else {
        ColumnFamilyUpdater<String, String> updater = projectVersionMetadataTemplate.createUpdater(key);
        addUpdateStringValue(updater, PROJECT_ID.toString(), projectId);
        addUpdateStringValue(updater, REPOSITORY_NAME.toString(), repositoryId);
        addUpdateStringValue(updater, NAMESPACE_ID.toString(), namespaceId);
        addUpdateStringValue(updater, PROJECT_VERSION.toString(), versionMetadata.getVersion());
        addUpdateStringValue(updater, DESCRIPTION.toString(), versionMetadata.getDescription());
        addUpdateStringValue(updater, NAME.toString(), versionMetadata.getName());
        updater.setString("incomplete", Boolean.toString(versionMetadata.isIncomplete()));
        addUpdateStringValue(updater, URL.toString(), versionMetadata.getUrl());
        {
            CiManagement ci = versionMetadata.getCiManagement();
            if (ci != null) {
                addUpdateStringValue(updater, "ciManagement.system", ci.getSystem());
                addUpdateStringValue(updater, "ciManagement.url", ci.getUrl());
            }
        }
        {
            IssueManagement issueManagement = versionMetadata.getIssueManagement();
            if (issueManagement != null) {
                addUpdateStringValue(updater, "issueManagement.system", issueManagement.getSystem());
                addUpdateStringValue(updater, "issueManagement.url", issueManagement.getUrl());
            }
        }
        {
            Organization organization = versionMetadata.getOrganization();
            if (organization != null) {
                addUpdateStringValue(updater, "organization.name", organization.getName());
                addUpdateStringValue(updater, "organization.url", organization.getUrl());
            }
        }
        {
            Scm scm = versionMetadata.getScm();
            if (scm != null) {
                addUpdateStringValue(updater, "scm.url", scm.getUrl());
                addUpdateStringValue(updater, "scm.connection", scm.getConnection());
                addUpdateStringValue(updater, "scm.developerConnection", scm.getDeveloperConnection());
            }
        }
        // update is a delete record
        removeMailingList(key);
        recordMailingList(key, versionMetadata.getMailingLists());
        removeLicenses(key);
        recordLicenses(key, versionMetadata.getLicenses());
        removeDependencies(key);
        recordDependencies(key, versionMetadata.getDependencies(), repositoryId);
        projectVersionMetadataTemplate.update(updater);
    }
    ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
    artifactMetadataModel.setRepositoryId(repositoryId);
    artifactMetadataModel.setNamespace(namespaceId);
    artifactMetadataModel.setProject(projectId);
    artifactMetadataModel.setProjectVersion(versionMetadata.getVersion());
    artifactMetadataModel.setVersion(versionMetadata.getVersion());
    updateFacets(versionMetadata, artifactMetadataModel);
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ArtifactMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel) Organization(org.apache.archiva.metadata.model.Organization) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) ProjectVersionMetadataModel(org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) Repository(org.apache.archiva.metadata.repository.cassandra.model.Repository) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) CiManagement(org.apache.archiva.metadata.model.CiManagement) Scm(org.apache.archiva.metadata.model.Scm) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) MutationResult(me.prettyprint.hector.api.mutation.MutationResult)

Aggregations

OrderedRows (me.prettyprint.hector.api.beans.OrderedRows)16 ArrayList (java.util.ArrayList)5 Namespace (org.apache.archiva.metadata.repository.cassandra.model.Namespace)5 HashMap (java.util.HashMap)4 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)4 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)3 ProjectMetadata (org.apache.archiva.metadata.model.ProjectMetadata)3 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)3 Repository (org.apache.archiva.metadata.repository.cassandra.model.Repository)3 Map (java.util.Map)2 HInvalidRequestException (me.prettyprint.hector.api.exceptions.HInvalidRequestException)2 MutationResult (me.prettyprint.hector.api.mutation.MutationResult)2 CiManagement (org.apache.archiva.metadata.model.CiManagement)2 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)2 MetadataFacetFactory (org.apache.archiva.metadata.model.MetadataFacetFactory)2 Organization (org.apache.archiva.metadata.model.Organization)2 Scm (org.apache.archiva.metadata.model.Scm)2 ArtifactMetadataModel (org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel)2 Project (org.apache.archiva.metadata.repository.cassandra.model.Project)2 ProjectVersionMetadataModel (org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel)2