cloud:gcp
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
cloud:gcp [2023/11/01 07:13] – removed - external edit (Unknown date) 127.0.0.1 | cloud:gcp [2023/11/01 07:13] (current) – ↷ Page moved from business_process_management:camunda:cloud:gcp to cloud:gcp skipidar | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Google Cloud Platform ===== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Goolge App Engine ==== | ||
+ | |||
+ | === Maven === | ||
+ | == Deploy the app to the Google server== | ||
+ | < | ||
+ | mvn appengine: | ||
+ | </ | ||
+ | After deployment the app will be available under: PROJECTAME.appspot.com | ||
+ | |||
+ | == Start local development server== | ||
+ | < | ||
+ | mvn appengine: | ||
+ | </ | ||
+ | available under localhost: | ||
+ | |||
+ | e.g. http:// | ||
+ | |||
+ | == Stops the server== | ||
+ | < | ||
+ | mvn appengine: | ||
+ | </ | ||
+ | |||
+ | === Project === | ||
+ | Use the HelloWorld project from here: | ||
+ | https:// | ||
+ | |||
+ | Create a Project on the " | ||
+ | https:// | ||
+ | |||
+ | |||
+ | === Servlets === | ||
+ | Inherit from **HttpServlet**. | ||
+ | Registered in **webapp/ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== Google Datastore ==== | ||
+ | The documentation for the datastore can be found here: | ||
+ | https:// | ||
+ | |||
+ | |||
+ | === Spring boots with datastore === | ||
+ | The Codelabs tutorial about creation of a new Spring boot application for app engine | ||
+ | https:// | ||
+ | |||
+ | |||
+ | === Datastore dependencies === | ||
+ | The maven dependencies are listed here | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | https:// | ||
+ | |||
+ | For the time of writing - it is important to reference Guava directly. | ||
+ | Otherwise there will be MethodNotFOund exceptions, because wrong versions of Guava are referenced by transitive dependencies. | ||
+ | < | ||
+ | <!-- | ||
+ | VERY IMPORTANT | ||
+ | Otherwise there will be a " | ||
+ | |||
+ | --> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Enable APIs === | ||
+ | Enable the APIs like " | ||
+ | |||
+ | https:// | ||
+ | |||
+ | |||
+ | === Enable Web Credentials === | ||
+ | The web credentials must be enabled, so that one can reach the API from the URS like | ||
+ | * http:// | ||
+ | * http:// | ||
+ | |||
+ | How to do so is stated in the bookshelf example too: | ||
+ | https:// | ||
+ | |||
+ | |||
+ | === Datastore usage === | ||
+ | |||
+ | Create a JSON key using the online console: https:// | ||
+ | |||
+ | Download the key e.g. as projectiname-e1234567891.p12 and put it into your WEB-INF folder, e.g. into Keys subfolder: \\ | ||
+ | WEB-INF/ | ||
+ | |||
+ | <sxh java> | ||
+ | public static final String PROJECT_ID = " | ||
+ | public static final String PATH_TO_JSON_KEY = "/ | ||
+ | |||
+ | |||
+ | public static Datastore initDataStore(GenericServlet servlet) { | ||
+ | try { | ||
+ | URL theurl = servlet.getServletContext().getResource(PATH_TO_JSON_KEY); | ||
+ | File file = new File(theurl.toURI()); | ||
+ | FileInputStream fileInputStreamKey = new FileInputStream(file); | ||
+ | |||
+ | return DatastoreOptions.builder().projectId(PROJECT_ID) | ||
+ | .authCredentials(AuthCredentials.createForJson(fileInputStreamKey)).build().service(); | ||
+ | } catch (URISyntaxException | IOException e1) { | ||
+ | return null; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Now you can query the DB: | ||
+ | |||
+ | <sxh java> | ||
+ | Datastore datastore = initDataStore(servlet); | ||
+ | |||
+ | Builder queryBuilder = Query.entityQueryBuilder() | ||
+ | .kind(FILM_DATA_KEY); | ||
+ | |||
+ | // filter if imdbId is given | ||
+ | if(imdbId!=null && !imdbId.isEmpty()){ | ||
+ | String imdbUrl = String.format(" | ||
+ | Filter imdbUrlFilter = PropertyFilter.eq(" | ||
+ | queryBuilder.filter(imdbUrlFilter); | ||
+ | } | ||
+ | |||
+ | // sort | ||
+ | queryBuilder.orderBy(OrderBy.asc(" | ||
+ | |||
+ | Query< | ||
+ | Iterator< | ||
+ | </ | ||
+ | |||
+ | |||
+ | === index === | ||
+ | To query the DB an index for the queried Entity properties must be created. Here the properties are: | ||
+ | * imdbUrl | ||
+ | * created | ||
+ | |||
+ | The index is created in a index.yaml file, which is: | ||
+ | * put into the WEB-INF folder | ||
+ | * deployed together with the app | ||
+ | |||
+ | Example index.yaml | ||
+ | < | ||
+ | indexes: | ||
+ | |||
+ | - kind: FilmData | ||
+ | ancestor: no | ||
+ | properties: | ||
+ | - name: imdbUrl | ||
+ | - name: created | ||
+ | direction: asc | ||
+ | </ | ||
+ | |||
+ | |||
+ | === appengine-web.xml === | ||
+ | Dexcribes the app: | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | === Logging === | ||
+ | Described in a WEB-INF/ | ||
+ | |||
+ | < | ||
+ | # Set the default logging level for all loggers to WARNING | ||
+ | .level = INFO | ||
+ | </ | ||
+ | |||
+ | The logs are visible in the console window, where the server is running. | ||
+ | |||
+ | |||
+ | ==== Run in Intellij Idea ==== | ||
+ | To run a Google App Engine applicaiton locally - use the " | ||
+ | |||
+ | {{https:// | ||
+ | |||
+ | After that a new launch configuration will be created: | ||
+ | {{https:// | ||
+ | |||
+ | |||
+ | === Importing a Gradle project to Idea === | ||
+ | |||
+ | |||
+ | * Import from github, directly via the Idea, via "VCS > Checkout from Version COntrol" | ||
+ | * add to Project Structure > Modules > youtube4kidz > youtube4kidz_main via " | ||
+ | * first build the project completele. Building is not part of the appengine-start process: build > rebuild project. Or you will receive a ClassNotFound / MethodNotFound | ||
+ | * then start project via Run " | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== gcloud | ||
+ | The gcloud command-line interface is the primary CLI tool to create and manage Google Cloud resources. | ||
+ | |||
+ | Installation | ||
+ | https:// | ||
+ | |||
+ | |||
+ | |||
+ | |||