Search in sources :

Example 1 with UserDAO

use of io.dockstore.webservice.jdbi.UserDAO in project dockstore by dockstore.

the class AbstractImageRegistry method refreshTools.

/**
 * Updates/Adds/Deletes tools and their associated tags
 *
 * @param userId            The ID of the user
 * @param userDAO           ...
 * @param toolDAO           ...
 * @param tagDAO            ...
 * @param fileDAO           ...
 * @param githubToken       The user's GitHub token
 * @param bitbucketToken    The user's Bitbucket token
 * @param gitlabToken       The user's GitLab token
 * @param organization      If not null, only refresh tools belonging to the specific organization. Otherwise, refresh all.
 * @param dashboardPrefix   A string that prefixes logging statements to indicate that it will be used for Cloudwatch & Grafana.
 * @return The list of tools that have been updated
 */
@SuppressWarnings("checkstyle:parameternumber")
public List<Tool> refreshTools(final long userId, final UserDAO userDAO, final ToolDAO toolDAO, final TagDAO tagDAO, final FileDAO fileDAO, final FileFormatDAO fileFormatDAO, final Token githubToken, final Token bitbucketToken, final Token gitlabToken, String organization, final EventDAO eventDAO, final String dashboardPrefix) {
    // Get all the namespaces for the given registry
    List<String> namespaces;
    if (organization != null) {
        namespaces = Collections.singletonList(organization);
    } else {
        namespaces = getNamespaces();
    }
    // Get all the tools based on the found namespaces
    List<Tool> apiTools = getToolsFromNamespace(namespaces);
    String registryString = getRegistry().getDockerPath();
    // Add manual tools to list of api tools
    User user = userDAO.findById(userId);
    List<Tool> userTools = toolDAO.findByUserRegistryNamespace(userId, registryString, organization);
    // manualTools:
    // - isManualMode
    // - isTool
    // - belongs to user
    // - correct registry
    // - correct organization/namespace
    List<Tool> manualTools = userTools.stream().filter(tool -> ToolMode.MANUAL_IMAGE_PATH.equals(tool.getMode())).collect(Collectors.toList());
    // notManualTools is similar except it's not manualMode
    List<Tool> notManualTools = userTools.stream().filter(tool -> !ToolMode.MANUAL_IMAGE_PATH.equals(tool.getMode())).collect(Collectors.toList());
    apiTools.addAll(manualTools);
    // Update api tools with build information
    updateAPIToolsWithBuildInformation(apiTools);
    // Update db tools by copying over from api tools
    List<Tool> newDBTools = updateTools(apiTools, notManualTools, user, toolDAO);
    // Get tags and update for each tool
    for (Tool tool : newDBTools) {
        logToolRefresh(dashboardPrefix, tool);
        List<Tag> toolTags = getTags(tool);
        final SourceCodeRepoInterface sourceCodeRepo = SourceCodeRepoFactory.createSourceCodeRepo(tool.getGitUrl(), bitbucketToken == null ? null : bitbucketToken.getContent(), gitlabToken == null ? null : gitlabToken.getContent(), githubToken);
        updateTags(toolTags, tool, sourceCodeRepo, tagDAO, fileDAO, toolDAO, fileFormatDAO, eventDAO, user);
    }
    return newDBTools;
}
Also used : GitLabTag(io.dockstore.webservice.core.gitlab.GitLabTag) SourceCodeRepoFactory.parseGitUrl(io.dockstore.webservice.helpers.SourceCodeRepoFactory.parseGitUrl) TypeToken(com.google.gson.reflect.TypeToken) SortedSet(java.util.SortedSet) URL(java.net.URL) Date(java.util.Date) Results(io.dockstore.webservice.core.dockerhub.Results) LoggerFactory(org.slf4j.LoggerFactory) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) HttpStatus(org.apache.http.HttpStatus) GitLabContainerRegistry(io.dockstore.webservice.core.gitlab.GitLabContainerRegistry) Registry(io.dockstore.common.Registry) SourceFile(io.dockstore.webservice.core.SourceFile) Gson(com.google.gson.Gson) Map(java.util.Map) User(io.dockstore.webservice.core.User) DockerHubImage(io.dockstore.webservice.core.dockerhub.DockerHubImage) TagDAO(io.dockstore.webservice.jdbi.TagDAO) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Tag(io.dockstore.webservice.core.Tag) Tool(io.dockstore.webservice.core.Tool) Collectors(java.util.stream.Collectors) DockerHubTag(io.dockstore.webservice.core.dockerhub.DockerHubTag) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Type(java.lang.reflect.Type) Optional(java.util.Optional) Validation(io.dockstore.webservice.core.Validation) DescriptorLanguage(io.dockstore.common.DescriptorLanguage) VersionTypeValidation(io.dockstore.common.VersionTypeValidation) Image(io.dockstore.webservice.core.Image) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LanguageHandlerFactory(io.dockstore.webservice.languages.LanguageHandlerFactory) FileFormatDAO(io.dockstore.webservice.jdbi.FileFormatDAO) Checksum(io.dockstore.webservice.core.Checksum) EventDAO(io.dockstore.webservice.jdbi.EventDAO) Token(io.dockstore.webservice.core.Token) UserDAO(io.dockstore.webservice.jdbi.UserDAO) FileDAO(io.dockstore.webservice.jdbi.FileDAO) ToolDAO(io.dockstore.webservice.jdbi.ToolDAO) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) IOException(java.io.IOException) ToolMode(io.dockstore.webservice.core.ToolMode) Collections(java.util.Collections) User(io.dockstore.webservice.core.User) GitLabTag(io.dockstore.webservice.core.gitlab.GitLabTag) Tag(io.dockstore.webservice.core.Tag) DockerHubTag(io.dockstore.webservice.core.dockerhub.DockerHubTag) Tool(io.dockstore.webservice.core.Tool)

Example 2 with UserDAO

use of io.dockstore.webservice.jdbi.UserDAO in project dockstore by dockstore.

the class AbstractImageRegistry method refreshTool.

@SuppressWarnings("checkstyle:ParameterNumber")
public void refreshTool(final long userId, final UserDAO userDAO, final ToolDAO toolDAO, final TagDAO tagDAO, final FileDAO fileDAO, final FileFormatDAO fileFormatDAO, final Token githubToken, final Token bitbucketToken, final Token gitlabToken, String organization, final EventDAO eventDAO, final String dashboardPrefix, String repository) {
    // Get all the tools based on the found namespaces
    List<Tool> apiTools;
    if (repository != null) {
        apiTools = new ArrayList<>(Collections.singletonList(getToolFromNamespaceAndRepo(organization, repository)));
    } else {
        throw new CustomWebApplicationException("Trying to refresh/register a tool without a repository name", HttpStatus.SC_BAD_REQUEST);
    }
    // Add manual tools to list of api tools
    String registryString = getRegistry().getDockerPath();
    User user = userDAO.findById(userId);
    List<Tool> userRegistryNamespaceRepositoryTools = toolDAO.findByUserRegistryNamespaceRepository(userId, registryString, organization, repository);
    List<Tool> manualTools = userRegistryNamespaceRepositoryTools.stream().filter(tool -> ToolMode.MANUAL_IMAGE_PATH.equals(tool.getMode())).collect(Collectors.toList());
    List<Tool> notManualTools = userRegistryNamespaceRepositoryTools.stream().filter(tool -> !ToolMode.MANUAL_IMAGE_PATH.equals(tool.getMode())).collect(Collectors.toList());
    apiTools.addAll(manualTools);
    // Update api tools with build information
    updateAPIToolsWithBuildInformation(apiTools);
    // Update db tools by copying over from api tools
    List<Tool> newDBTools = updateTools(apiTools, notManualTools, user, toolDAO);
    // Get tags and update for each tool
    for (Tool tool : newDBTools) {
        logToolRefresh(dashboardPrefix, tool);
        List<Tag> toolTags = getTags(tool);
        final SourceCodeRepoInterface sourceCodeRepo = SourceCodeRepoFactory.createSourceCodeRepo(tool.getGitUrl(), bitbucketToken == null ? null : bitbucketToken.getContent(), gitlabToken == null ? null : gitlabToken.getContent(), githubToken);
        updateTags(toolTags, tool, sourceCodeRepo, tagDAO, fileDAO, toolDAO, fileFormatDAO, eventDAO, user);
    }
}
Also used : GitLabTag(io.dockstore.webservice.core.gitlab.GitLabTag) SourceCodeRepoFactory.parseGitUrl(io.dockstore.webservice.helpers.SourceCodeRepoFactory.parseGitUrl) TypeToken(com.google.gson.reflect.TypeToken) SortedSet(java.util.SortedSet) URL(java.net.URL) Date(java.util.Date) Results(io.dockstore.webservice.core.dockerhub.Results) LoggerFactory(org.slf4j.LoggerFactory) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) HttpStatus(org.apache.http.HttpStatus) GitLabContainerRegistry(io.dockstore.webservice.core.gitlab.GitLabContainerRegistry) Registry(io.dockstore.common.Registry) SourceFile(io.dockstore.webservice.core.SourceFile) Gson(com.google.gson.Gson) Map(java.util.Map) User(io.dockstore.webservice.core.User) DockerHubImage(io.dockstore.webservice.core.dockerhub.DockerHubImage) TagDAO(io.dockstore.webservice.jdbi.TagDAO) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Tag(io.dockstore.webservice.core.Tag) Tool(io.dockstore.webservice.core.Tool) Collectors(java.util.stream.Collectors) DockerHubTag(io.dockstore.webservice.core.dockerhub.DockerHubTag) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Type(java.lang.reflect.Type) Optional(java.util.Optional) Validation(io.dockstore.webservice.core.Validation) DescriptorLanguage(io.dockstore.common.DescriptorLanguage) VersionTypeValidation(io.dockstore.common.VersionTypeValidation) Image(io.dockstore.webservice.core.Image) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LanguageHandlerFactory(io.dockstore.webservice.languages.LanguageHandlerFactory) FileFormatDAO(io.dockstore.webservice.jdbi.FileFormatDAO) Checksum(io.dockstore.webservice.core.Checksum) EventDAO(io.dockstore.webservice.jdbi.EventDAO) Token(io.dockstore.webservice.core.Token) UserDAO(io.dockstore.webservice.jdbi.UserDAO) FileDAO(io.dockstore.webservice.jdbi.FileDAO) ToolDAO(io.dockstore.webservice.jdbi.ToolDAO) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) IOException(java.io.IOException) ToolMode(io.dockstore.webservice.core.ToolMode) Collections(java.util.Collections) User(io.dockstore.webservice.core.User) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) GitLabTag(io.dockstore.webservice.core.gitlab.GitLabTag) Tag(io.dockstore.webservice.core.Tag) DockerHubTag(io.dockstore.webservice.core.dockerhub.DockerHubTag) Tool(io.dockstore.webservice.core.Tool)

Example 3 with UserDAO

use of io.dockstore.webservice.jdbi.UserDAO in project dockstore by dockstore.

the class AdvancedIndexingBenchmarkIT method testCreate10000Tools.

@Test
public void testCreate10000Tools() {
    this.sessionFactory = application.getHibernate().getSessionFactory();
    try {
        Transaction transaction = this.sessionFactory.openSession().getTransaction();
        transaction.begin();
        TokenDAO tokenDAO = new TokenDAO(sessionFactory);
        User user = new User();
        user.setIsAdmin(true);
        user.setUsername("travistest");
        Token token = new Token();
        token.setUserId(1);
        token.setUsername("travistest");
        token.setContent("iamafakedockstoretoken");
        token.setTokenSource(TokenType.DOCKSTORE);
        tokenDAO.create(token);
        Token token2 = new Token();
        token2.setUserId(1);
        token2.setUsername("travistest");
        token2.setContent("iamafakegithubtoken");
        token2.setTokenSource(TokenType.GITHUB_COM);
        tokenDAO.create(token2);
        UserDAO userDAO = new UserDAO(sessionFactory);
        userDAO.create(user);
        transaction.commit();
    } finally {
        session.close();
    }
    session = application.getHibernate().getSessionFactory().openSession();
    ManagedSessionContext.bind(session);
    for (int i = 0; i < TOOL_COUNT; i++) {
        createTool();
    }
    Response response = client.target("http://localhost:" + SUPPORT.getLocalPort() + "/containers/published").request().get();
    List<Tool> tools = response.readEntity(new GenericType<List<Tool>>() {
    });
    int actualToolCount = tools.size();
    assertEquals("Supposed to have " + TOOL_COUNT + " tools.  Instead got " + actualToolCount + " tools.", actualToolCount, TOOL_COUNT);
    LOGGER.error("Amount of tools created: " + String.valueOf(actualToolCount));
    for (Long indexTime : indexTimes) {
        LOGGER.error(String.valueOf(indexTime));
    }
}
Also used : Response(javax.ws.rs.core.Response) User(io.dockstore.webservice.core.User) Transaction(org.hibernate.Transaction) UserDAO(io.dockstore.webservice.jdbi.UserDAO) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) Token(io.dockstore.webservice.core.Token) ArrayList(java.util.ArrayList) List(java.util.List) Tool(io.dockstore.webservice.core.Tool) Test(org.junit.Test) BenchmarkTest(io.dockstore.common.BenchmarkTest) ToolTest(io.dockstore.common.ToolTest)

Example 4 with UserDAO

use of io.dockstore.webservice.jdbi.UserDAO in project dockstore by dockstore.

the class TokenResourceIT method setup.

@Before
public void setup() throws Exception {
    CommonTestUtilities.dropAndCreateWithTestData(SUPPORT, false, DROPWIZARD_CONFIGURATION_FILE_PATH);
    DockstoreWebserviceApplication application = SUPPORT.getApplication();
    SessionFactory sessionFactory = application.getHibernate().getSessionFactory();
    this.tokenDAO = new TokenDAO(sessionFactory);
    this.userDAO = new UserDAO(sessionFactory);
    // non-confidential test database sequences seem messed up and need to be iterated past, but other tests may depend on ids
    testingPostgres.runUpdateStatement("alter sequence enduser_id_seq increment by 50 restart with 100");
    testingPostgres.runUpdateStatement("alter sequence token_id_seq increment by 50 restart with 100");
    // used to allow us to use tokenDAO outside of the web service
    Session session = application.getHibernate().getSessionFactory().openSession();
    ManagedSessionContext.bind(session);
    initialTokenCount = testingPostgres.runSelectStatement("select count(*) from token", long.class);
}
Also used : SessionFactory(org.hibernate.SessionFactory) UserDAO(io.dockstore.webservice.jdbi.UserDAO) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) Session(org.hibernate.Session) Before(org.junit.Before)

Example 5 with UserDAO

use of io.dockstore.webservice.jdbi.UserDAO in project dockstore by dockstore.

the class ServiceIT method setup.

@Before
public void setup() {
    DockstoreWebserviceApplication application = SUPPORT.getApplication();
    SessionFactory sessionFactory = application.getHibernate().getSessionFactory();
    this.workflowDAO = new WorkflowDAO(sessionFactory);
    this.serviceDAO = new ServiceDAO(sessionFactory);
    this.userDAO = new UserDAO(sessionFactory);
    this.fileDAO = new FileDAO(sessionFactory);
    // non-confidential test database sequences seem messed up and need to be iterated past, but other tests may depend on ids
    testingPostgres.runUpdateStatement("alter sequence enduser_id_seq increment by 50 restart with 100");
    testingPostgres.runUpdateStatement("alter sequence token_id_seq increment by 50 restart with 100");
    // used to allow us to use tokenDAO outside of the web service
    this.session = application.getHibernate().getSessionFactory().openSession();
    ManagedSessionContext.bind(session);
}
Also used : SessionFactory(org.hibernate.SessionFactory) WorkflowDAO(io.dockstore.webservice.jdbi.WorkflowDAO) UserDAO(io.dockstore.webservice.jdbi.UserDAO) FileDAO(io.dockstore.webservice.jdbi.FileDAO) ServiceDAO(io.dockstore.webservice.jdbi.ServiceDAO) Before(org.junit.Before)

Aggregations

UserDAO (io.dockstore.webservice.jdbi.UserDAO)6 User (io.dockstore.webservice.core.User)4 FileDAO (io.dockstore.webservice.jdbi.FileDAO)4 Token (io.dockstore.webservice.core.Token)3 Tool (io.dockstore.webservice.core.Tool)3 EventDAO (io.dockstore.webservice.jdbi.EventDAO)3 TagDAO (io.dockstore.webservice.jdbi.TagDAO)3 TokenDAO (io.dockstore.webservice.jdbi.TokenDAO)3 ToolDAO (io.dockstore.webservice.jdbi.ToolDAO)3 Gson (com.google.gson.Gson)2 TypeToken (com.google.gson.reflect.TypeToken)2 DescriptorLanguage (io.dockstore.common.DescriptorLanguage)2 Registry (io.dockstore.common.Registry)2 VersionTypeValidation (io.dockstore.common.VersionTypeValidation)2 CustomWebApplicationException (io.dockstore.webservice.CustomWebApplicationException)2 Checksum (io.dockstore.webservice.core.Checksum)2 Image (io.dockstore.webservice.core.Image)2 SourceFile (io.dockstore.webservice.core.SourceFile)2 Tag (io.dockstore.webservice.core.Tag)2 ToolMode (io.dockstore.webservice.core.ToolMode)2