app/models/user_workspace.rb
# create a new benchmark workspace by cloning the reference workspace
create a new benchmark workspace by cloning the reference workspace
create a new benchmark workspace by cloning the reference workspace
def create_benchmark_workspace
    begin
      user_client = FireCloudClient.new(self.user)
      Rails.logger.info "Creating user_workspace: #{self.full_name} from #{self.reference_analysis.display_name}"
      workspace = user_client.clone_workspace(self.reference_analysis.firecloud_project, self.reference_analysis.firecloud_workspace,
                                              self.namespace, self.name)
      ws_name = workspace['name']
      unless ws_name == self.name
        user_client.delete_workspace(self.namespace, self.name)
        errors.add(:name, ' was not created properly (workspace name did not match or was not created).  Please try again later.')
        return false
      end
      Rails.logger.info "Setting bucket ID for #{self.full_name}"
      bucket = workspace['bucketName']
      self.bucket_id = bucket
      if self.bucket_id.nil?
        user_client.delete_workspace(self.namespace, self.name)
        errors.add(:name, ' was not created properly (storage bucket was not set).  Please try again later.')
        return false
      end
      Rails.logger.info "Adding GCS Admin ACL to #{self.full_name}"
      gcs_admin_acl = user_client.create_workspace_acl(ApplicationController.gcs_client.issuer, 'WRITER', true, false)
      user_client.update_workspace_acl(self.namespace, self.name, gcs_admin_acl)
    rescue => e
      Rails.logger.error "Error creating user workspace #{self.full_name}: #{e.message}"
      if e.message.include?("Workspace #{self.full_name} already exists")
        errors.add(:name, ' - there is already an existing benchmarking workspace using this name.  Please choose another name.')
      else
        begin
          FireCloudClient.new(self.user).delete_workspace(self.namespace, self.name)
        rescue => e
          Rails.logger.error "Cannot remove workspace #{self.full_name} due to error: #{e.message}"
        end
          errors.add(:name, " creation failed: #{e.message}; Please try again.")
      end
    end
  end
def create_benchmark_workspace begin user_client = FireCloudClient . new ( self . user ) Rails . logger . info "Creating user_workspace: #{self.full_name} from #{self.reference_analysis.display_name}" workspace = user_client . clone_workspace ( self . reference_analysis . firecloud_project , self . reference_analysis . firecloud_workspace , self . namespace , self . name ) ws_name = workspace [ 'name' ] unless ws_name == self . name user_client . delete_workspace ( self . namespace , self . name ) errors . add ( :name , ' was not created properly (workspace name did not match or was not created).  Please try again later.' ) return false end Rails . logger . info "Setting bucket ID for #{self.full_name}" bucket = workspace [ 'bucketName' ] self . bucket_id = bucket if self . bucket_id . nil? user_client . delete_workspace ( self . namespace , self . name ) errors . add ( :name , ' was not created properly (storage bucket was not set).  Please try again later.' ) return false end Rails . logger . info "Adding GCS Admin ACL to #{self.full_name}" gcs_admin_acl = user_client . create_workspace_acl ( ApplicationController . gcs_client . issuer , 'WRITER' , true , false ) user_client . update_workspace_acl ( self . namespace , self . name , gcs_admin_acl ) rescue => e Rails . logger . error "Error creating user workspace #{self.full_name}: #{e.message}" if e . message . include? ( "Workspace #{self.full_name} already exists" ) errors . add ( :name , ' - there is already an existing benchmarking workspace using this name.  Please choose another name.' ) else begin FireCloudClient . new ( self . user ) . delete_workspace ( self . namespace , self . name ) rescue => e Rails . logger . error "Cannot remove workspace #{self.full_name} due to error: #{e.message}" end errors . add ( :name , " creation failed: #{e.message}; Please try again." ) end end end
create a new benchmark workspace by cloning the reference workspace
create a new benchmark workspace by cloning the reference workspace
# clone reference space into new workspace # validate creation # delete workspace on validation fail