Skip to content
Snippets Groups Projects
Select Git revision
  • 19d613f582b6cee4e7b9b2ff1a41475b8f238fcc
  • master default protected
  • replication_test
  • dev protected
  • release-1.10 protected
  • release-1.9 protected
  • 551-init-broker-service-permissions
  • 549-test-oai-pmh
  • 545-saving-multiple-times-breaks-pid-metadata
  • 499-standalone-compute-service-2
  • 539-load-tests
  • hotfix/helm-chart
  • luca_ba_new_interface
  • 534-bug-when-adding-access-to-user-that-is-not-registered-at-dashboard-service
  • release-1.8 protected
  • 533-integrate-semantic-recommendation
  • feature/openshift
  • 518-spark-doesn-t-map-the-headers-correct
  • 485-fixity-checks
  • 530-various-schema-problems-with-subsets
  • release-1.7 protected
  • v1.10.2 protected
  • v1.10.1 protected
  • v1.10.0-rc13 protected
  • v1.10.0-rc12 protected
  • v1.10.0-rc11 protected
  • v1.10.0-rc10 protected
  • v1.10.0-rc9 protected
  • v1.10.0-rc8 protected
  • v1.10.0-rc7 protected
  • v1.10.0-rc6 protected
  • v1.10.0-rc5 protected
  • v1.10.0-rc4 protected
  • v1.10.0-rc3 protected
  • v1.10.0-rc2 protected
  • v1.10.0rc1 protected
  • v1.10.0rc0 protected
  • v1.10.0 protected
  • v1.9.3 protected
  • v1.9.2 protected
  • v1.9.2-rc0 protected
41 results

CreateDB.vue

Blame
  • CreateDB.vue 5.51 KiB
    <template>
      <div>
        <v-form ref="form" v-model="valid" @submit.prevent="submit">
          <v-card>
            <v-progress-linear v-if="loading" :color="loadingColor" :indeterminate="!error" />
            <v-card-title>
              Create Database
            </v-card-title>
            <v-card-text>
              <v-alert
                border="left"
                color="amber lighten-4 black--text">
                Choose an expressive database name and select a database engine.
              </v-alert>
              <v-text-field
                id="database"
                v-model="database"
                name="database"
                label="Name *"
                autofocus
                :rules="[v => !!v || $t('Required')]"
                required />
              <v-textarea
                id="description"
                v-model="description"
                name="description"
                rows="2"
                label="Description *"
                :rules="[v => !!v || $t('Required')]"
                required />
              <v-select
                id="engine"
                v-model="engine"
                name="engine"
                label="Engine *"
                :items="engines"
                :item-text="item => `${item.repository}:${item.tag}`"
                :rules="[v => !!v || $t('Required')]"
                return-object
                required />
              <v-checkbox
                id="public"
                v-model="isPublic"
                name="public"
                disabled
                label="Public" />
            </v-card-text>
            <v-card-actions>
              <v-spacer />
              <v-btn
                class="mb-2"
                @click="cancel">
                Cancel
              </v-btn>
              <v-btn
                id="createDB"
                class="mb-2"
                :disabled="!valid || loading"
                color="primary"
                type="submit"
                @click="createDB">
                Create
              </v-btn>
            </v-card-actions>
          </v-card>
        </v-form>
      </div>
    </template>
    
    <script>
    export default {
      data () {
        return {
          valid: false,
          loading: false,
          error: false,
          database: null,
          description: null,
          isPublic: true,
          engine: null,
          engines: [],
          container: null
        }
      },
      computed: {
        loadingColor () {
          return this.error ? 'red lighten-2' : 'primary'
        },
        token () {
          return this.$store.state.token
        }
      },
      beforeMount () {
        this.getImages()
      },
      methods: {
        submit () {
          this.$refs.form.validate()
        },
        cancel () {
          this.$parent.$parent.$parent.$parent.createDbDialog = false
        },
        async getImages () {
          let res
          try {
            this.loading = true
            this.error = false
            res = await this.$axios.get('/api/image')
            this.engines = res.data
            console.debug('engines', this.engines)
            this.loading = false
          } catch (err) {
            this.error = true
            this.$toast.error('Failed to fetch supported engines. Try reload the page.')
          }
          this.loading = false
        },
        sleep (ms) {
          return new Promise((resolve) => {
            setTimeout(resolve, ms)
          })
        },
        async createDB () {
          let res
          // create a container
          let containerId
          console.debug('model', this.engine)
          try {
            this.loading = true
            this.error = false
            res = await this.$axios.post('/api/container', {
              name: this.database,
              description: this.description,
              repository: this.engine.repository,
              tag: this.engine.tag
            }, {
              headers: { Authorization: `Bearer ${this.token}` }
            })
            containerId = res.data.id
            console.debug('created container', res.data)
            this.loading = false
          } catch (err) {
            this.error = true
            this.loading = false
            if (err.status === 401) {
              this.$toast.error('Authentication missing')
              console.error('permission denied', err)
              return
            }
            console.error('failed to create container', err)
            this.$toast.error('Could not create container.')
            return
          }
    
          // start the container
          try {
            this.loading = true
            this.error = false
            res = await this.$axios.put(`/api/container/${containerId}`, { action: 'START' }, {
              headers: { Authorization: `Bearer ${this.token}` }
            })
            console.debug('started container', res.data)
          } catch (err) {
            this.error = true
            this.$toast.error('Could not start container.')
            return
          }
    
          // Pause.
          // DB fails to create when container has not started up yet
          await new Promise(resolve => setTimeout(resolve, 2000))
    
          // wait for it to finish
          this.loading = true
          this.error = false
          for (let i = 0; i < 5; i++) {
            try {
              res = await this.$axios.post(`/api/container/${containerId}/database`, {
                name: this.database,
                description: this.description,
                is_public: this.isPublic
              }, {
                headers: { Authorization: `Bearer ${this.token}` }
              })
              console.debug('created database', res)
              break
            } catch (err) {
              console.debug('wait', res)
              await this.sleep(3000)
            }
          }
          if (res.status !== 201) {
            this.loading = false
            this.error = true
            this.$toast.error('Could not create database.')
            return
          }
          this.loading = false
          this.$toast.success(`Database "${res.data.name}" created.`)
          this.$emit('close')
          await this.$router.push(`/container/${containerId}/database/${res.data.id}/info`)
        }
      }
    }
    </script>