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;
}
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);
}
}
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));
}
}
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);
}
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);
}
Aggregations