Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print the ListUserResourcesQuery statement to the console and exit. #1225

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions src/main/scala/org/broadinstitute/dsde/workbench/sam/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import cats.data.NonEmptyList
import cats.effect._
import cats.implicits._
import com.typesafe.scalalogging.LazyLogging
import io.prometheus.client.CollectorRegistry
import org.broadinstitute.dsde.workbench.dataaccess.PubSubNotificationDAO
import org.broadinstitute.dsde.workbench.google.GoogleCredentialModes.{Json, Pem}
import org.broadinstitute.dsde.workbench.google.{
Expand All @@ -20,7 +19,7 @@ import org.broadinstitute.dsde.workbench.google.{
HttpGoogleStorageDAO
}
import org.broadinstitute.dsde.workbench.google2.{GoogleStorageInterpreter, GoogleStorageService}
import org.broadinstitute.dsde.workbench.model.WorkbenchEmail
import org.broadinstitute.dsde.workbench.model.{WorkbenchEmail, WorkbenchUserId}
import org.broadinstitute.dsde.workbench.oauth2.{ClientId, ClientSecret, OpenIDConnectConfiguration}
import org.broadinstitute.dsde.workbench.openTelemetry.OpenTelemetryMetrics
import org.broadinstitute.dsde.workbench.sam.api.{LivenessRoutes, SamRoutes, StandardSamUserDirectives}
Expand All @@ -32,6 +31,7 @@ import org.broadinstitute.dsde.workbench.sam.db.DbReference
import org.broadinstitute.dsde.workbench.sam.google._
import org.broadinstitute.dsde.workbench.sam.model._
import org.broadinstitute.dsde.workbench.sam.service._
import org.broadinstitute.dsde.workbench.sam.util.SamRequestContext
import org.broadinstitute.dsde.workbench.sam.util.Sentry.initSentry
import org.broadinstitute.dsde.workbench.util.DelegatePool
import org.typelevel.log4cats.StructuredLogger
Expand All @@ -42,7 +42,6 @@ import java.nio.file.{Files, Paths}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.jdk.CollectionConverters._
import scala.util.control.NonFatal

object Boot extends IOApp with LazyLogging {

Expand All @@ -51,39 +50,39 @@ object Boot extends IOApp with LazyLogging {
initSentry()
implicit val system = ActorSystem("sam")

(startup() *> ExitCode.Success.pure[IO]).recoverWith { case NonFatal(t) =>
logger.error("sam failed to start, trying again in 5s", t)

// Shutdown all akka http connection pools/servers so we can re-bind to the ports
Http().shutdownAllConnectionPools() *> system.terminate()
// Clean up prometheus registry so it will be fresh on reboot
CollectorRegistry.defaultRegistry.clear()

IO.sleep(5 seconds) *> run(args)
}
startup() *> ExitCode.Success.pure[IO]
}

private def startup()(implicit system: ActorSystem): IO[Unit] = {
val appConfig = AppConfig.load
val appDependencies = createAppDependencies(appConfig)

appDependencies.use { dependencies => // this is where the resource is used
livenessServerStartup(dependencies.directoryDAO)
for {
_ <- dependencies.samApplication.resourceService.initResourceTypes().onError { case t: Throwable =>
IO(logger.error("FATAL - failure starting http server", t)) *> IO.raiseError(t)
}

_ <- dependencies.policyEvaluatorService.initPolicy()

_ <- dependencies.cloudExtensionsInitializer.onBoot(dependencies.samApplication)

binding <- IO.fromFuture(IO(Http().newServerAt("0.0.0.0", 8080).bind(dependencies.samRoutes.route))).onError { case t: Throwable =>
IO(logger.error("FATAL - failure starting http server", t)) *> IO.raiseError(t)
}
_ <- IO.fromFuture(IO(binding.whenTerminated))
_ <- IO(system.terminate())
} yield ()
import cats.effect.unsafe.implicits.global
dependencies.accessPolicyDAO
.listUserResourcesWithRolesAndActions(
ResourceTypeName("workspace"),
WorkbenchUserId("123"),
SamRequestContext()
)
.unsafeRunSync()
IO(system.terminate())
// livenessServerStartup(dependencies.directoryDAO)
// for {
// _ <- dependencies.samApplication.resourceService.initResourceTypes().onError { case t: Throwable =>
// IO(logger.error("FATAL - failure starting http server", t)) *> IO.raiseError(t)
// }
//
// _ <- dependencies.policyEvaluatorService.initPolicy()
//
// _ <- dependencies.cloudExtensionsInitializer.onBoot(dependencies.samApplication)
//
// binding <- IO.fromFuture(IO(Http().newServerAt("0.0.0.0", 8080).bind(dependencies.samRoutes.route))).onError { case t: Throwable =>
// IO(logger.error("FATAL - failure starting http server", t)) *> IO.raiseError(t)
// }
// _ <- IO.fromFuture(IO(binding.whenTerminated))
// _ <- IO(system.terminate())
// } yield ()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ class PostgresAccessPolicyDAO(protected val writeDbRef: DbReference, protected v
}

val listUserResourcesQuery = new ListUserResourcesQuery()
logger.info(listUserResourcesQuery.query.statement)
val queryResults = listUserResourcesQuery.query
.map { rs =>
val rolesAndActions = RolesAndActions(
Expand Down
Loading