Class: AstroboaCLI::Command::Repository
- Defined in:
- lib/astroboa-cli/command/repository.rb
Overview
create, delete, backup, restore repositories
Instance Attribute Summary
Attributes inherited from Base
#args, #log, #log_file, #options
Instance Method Summary collapse
- #backup ⇒ Object
-
#create ⇒ Object
repository:create REPOSITORY_NAME.
-
#delete ⇒ Object
repository:delete REPOSITORY_NAME.
- #disable ⇒ Object
- #enable ⇒ Object
-
#list ⇒ Object
repository:list REPOSITORY_NAME.
- #populate ⇒ Object
Methods inherited from Base
Methods included from Util
#ask, #astroboa_running?, #check_if_running_with_sudo, #create_postgresql_db, #delete_file_content_between_regex, #delete_file_lines, #dir_writable?, #display, #drop_postgresql_db, #error, #extract_archive_command, #fail, #format_with_bang, #gem_available?, #get_password, #get_postgresql_config, #get_server_conf_file, #get_server_configuration, #has_executable, #has_executable_with_version, #has_version_in_grep, #jruby_ok?, #jruby_version_ok?, #linux?, #load_pg_library, #longest, #mac_os_x?, #output_with_bang, #postgres_connectivity?, #process_os_command, #render_template_to_file, #repository?, #repository_in_repos_config?, #repository_in_server_config?, #ruby_ok?, #ruby_version_ok?, #running_with_sudo?, #runs_with_jruby?, #save_server_configuration, #shell, #strip_text_nodes, #unzip_file, #windows?, #write_xml
Constructor Details
This class inherits a constructor from AstroboaCLI::Command::Base
Instance Method Details
#backup ⇒ Object
234 235 236 |
# File 'lib/astroboa-cli/command/repository.rb', line 234 def backup end |
#create ⇒ Object
repository:create REPOSITORY_NAME
Creates a new astroboa repository with the provided ‘REPOSITORY_NAME’. The ‘REPOSITORY_NAME’ is the internal repository name. It should be at least 3 characters long and should not contain spaces and special symbols (!#@?-*). Only english word characters are allowed (a-z or A-Z or 0-9 or _) You may use the -l option to provide friendly localized (for different languages) labels with spaces A directory named after the name of the new repository will be created to store repository configuration, indexes and blobs. This directory will be created under the global repositories directory that has been setup during astroboa server installation. A database will also be created to store repository data (except blobs). The database server, db user and db password that have been configured during astroboa server setup will be used.
-l, –localized_labels REPO_LABELS # Provide friendly labels for different languages # The format is “locale1:localized_string1,locale2:localized_string2” # YOU SHOULD SURROUND THE LABELS WITH SINGLE OR DOUBLE QUOTES # By default the ‘REPOSITORY_NAME’ will be used as the english label # Example: -l “en:Dali Paintings,fr:Dali Peintures,es:Dali Pinturas” -d, –domain_name REPO_DOMAIN_NAME # Specify the fully qualified domain name and port under which all the repository resources will be exposed by the REST API # The default is ‘localhost:8080’ # If you specify other than the default (e.g. www.mydomain.com) you need to appropriately setup a reverse proxy in front of astroboa -p, –api_base_path REST_API_BASE_PATH # Specify the base_path of the REST API URLs # The default is ‘/resource-api’ # If you provide other than the default you should appropriately setup a reverse proxy in front of astroboa -n, –db_name DATABASE_NAME # Specify the name of the database to create # Default is REPOSITORY_NAME (i.e. the name of the new repository)
Examples:
Create the repository ‘dali_paintings’. It will be stored in db named ‘dali_paintings’ and its RESOURCES will be available under localhost:8080/resource-api/dali_paintings $ astroboa-cli repository:create dali_paintings
Specify i18n labels for the repository name. Expose the repo resources under www.art.com/art-api/dali_paintings $ astroboa-cli repository:create dali_paintings -l “en:Dali Paintings,fr:Dali Peintures,es:Dali Pinturas” -d www.art.com -p art-api
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/astroboa-cli/command/repository.rb', line 38 def create if repository_name = args.shift repository_name = repository_name.strip else error "Please specify the repository name. Usage: repository:create REPOSITORY_NAME" end error "Please use at least 3 english word characters (a-zA-Z0-9_) without spaces for the repository name" unless repository_name =~ /^\w{3,}$/ server_configuration = get_server_configuration check_repo_existense(server_configuration, repository_name) database_name = [:db_name] ||= repository_name begin astroboa_dir = server_configuration['install_dir'] repos_dir = server_configuration['repos_dir'] # if OS is linux or [OS is mac and repos_dir is not writable by current user] # then astroboa-cli should run with sudo in order to have the required privileges to write files check_if_running_with_sudo if linux? || (mac_os_x? && !dir_writable?(repos_dir)) repo_dir = File.join(repos_dir, repository_name) FileUtils.mkdir_p(repo_dir) display "Create repository dir '#{repo_dir}': OK" schema_dir = File.join(repo_dir, "astroboa_schemata") FileUtils.mkdir(schema_dir) display %(Create dir '#{schema_dir}': OK) # create postgres database unless server_configuration['database'] == 'derby' begin create_postgresql_db(server_configuration, database_name) rescue FileUtils.rm_r repo_dir, :secure=>true error "Removing #{repo_dir} and Exiting..." end end # config jcr repository (create repository.xml) configure_jcr_repo(server_configuration, astroboa_dir, repo_dir, repository_name, database_name) # config astroboa repository (create configuration in repositories-conf.xml) configure_astroboa_repo(astroboa_dir,repos_dir, repo_dir, repository_name) # save repo configuration into astroboa server config file add_repo_conf_to_server_conf(server_configuration, repository_name) # change ownership of repo dir # In mac os x astroboa is installed and run under the ownership of the user that runs the installation command. # So if the same user that did the install runs the repo creation command ownership is ok. # if however repo creation is done by another user (using sudo) then we need to change the ownership of repo dir # to the user that installed and thus owns astroboa. if mac_os_x? astroboa_owner_uid = File.stat(astroboa_dir).uid astroboa_owner = Etc.getpwuid(astroboa_owner_uid).name process_uid = Process.uid if astroboa_owner_uid != process_uid FileUtils.chown_R(astroboa_owner, nil, repo_dir) display "Change (recursively) user owner of #{repo_dir} to #{astroboa_owner}: OK" end end # In linux a special user 'astroboa' and group 'astroboa' is created for owning a running astroboa. # So we need to change the ownership of the installation dir and the repositories dir to # belong to user 'astroboa' and group 'astroboa' if linux? FileUtils.chown_R('astroboa', 'astroboa', repo_dir) display "Change (recursively) user and group owner of #{repo_dir} to 'astroboa': OK" end rescue => e display %(An error has occured \n The error is: '#{e.to_s}' \n The error trace is: \n #{e.backtrace.join("\n")}) display %(Repository configuration, the db and the related directories will be removed) unconfigure_astroboa_repo(repos_dir, repository_name) FileUtils.rm_r repo_dir, :secure=>true display "Remove #{repo_dir} : OK" drop_postgresql_db(server_configuration, database_name) if server_configuration['database'] =~ /postgres/ error 'Exiting...' end end |
#delete ⇒ Object
repository:delete REPOSITORY_NAME
Unconfigures and deletes an existing astroboa repository named ‘REPOSITORY_NAME’. BE VERY CAREFUL with this operation. All Repository configuration and data will be permanently lost. You are adviced to use the repository:backup command before deleting a repository in the case that you would like to recover it back. If you just want to disable the repository use the repository:disable / repository:enable commands The ‘REPOSITORY_NAME’ is the internal repository name. To find which repositories are available and see their internal names use the repository:list command
-f, –force # Use this option if you wish to enforce the removal of the ‘identities’ repository # You must have already removed all other repositories before enforcing the ‘identities’ removal
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/astroboa-cli/command/repository.rb', line 134 def delete if repository_name = args.shift repository_name = repository_name.strip else error "Please specify the repository name. Usage: repository:delete REPOSITORY_NAME" end server_configuration = get_server_configuration repos_dir = server_configuration["repos_dir"] # if OS is linux or [OS is mac and repos_dir is not writable by current user] # then astroboa-cli should run with sudo in order to have the required privileges to remove files check_if_running_with_sudo if linux? || (mac_os_x? && !dir_writable?(repos_dir)) # check if repo exists repo_dir = File.join(repos_dir, repository_name) error "Repository #{repository_name} does not exist in directory #{repo_dir}" unless File.exists? repo_dir error %(Repository #{repository_name} does not exist in astroboa server configuration file "#{get_server_conf_file}") unless repository_in_server_config?(server_configuration, repository_name) # we treat 'identities' repo very carefully if repository_name == 'identities' error "You must remove all other repositories before removing the 'identities' repository" if server_configuration['repositories'].keys.length > 1 error "Use the '--force' option if you want to remove the identities repository" unless [:force] end # first stop serving the repository unconfigure_astroboa_repo(repos_dir, repository_name) # remove dir with indexes, blobs and schemas FileUtils.rm_r repo_dir, :secure=>true display "Remove #{repo_dir} : OK" # get the name of the repo database before we remove the server configuration database_name = server_configuration['repositories'][repository_name]['database'] # remove repo conf from astroboa server configuration delete_repo_conf_from_server_conf(server_configuration, repository_name) # remove the repo database, we leave it last so that everything else has been removed in the case something goes wrong # with db removal if server_configuration['database'] =~ /postgres/ error <<-MSG.gsub(/^ {6}/, '') unless database_name It is not possible to remove the database because the database name for this repository was not found in the server configuration file. However the repository has been disabled and all configuration and related directories have been removed except the database. So it is safe to manually remove the database. MSG begin drop_postgresql_db(server_configuration, database_name) rescue => e display %(An error has occured while deleting the database. The error is #{e.}.) display %(The repository has been disabled and all configuration and related directories have been removed except the database.) display %(It is safe to manually remove the database) end end end |
#disable ⇒ Object
195 196 197 |
# File 'lib/astroboa-cli/command/repository.rb', line 195 def disable end |
#enable ⇒ Object
200 201 202 |
# File 'lib/astroboa-cli/command/repository.rb', line 200 def enable end |
#list ⇒ Object
repository:list REPOSITORY_NAME
Lists the available repositories. If the name of an existing repository is provided it displays information about the repository.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/astroboa-cli/command/repository.rb', line 208 def list server_configuration = get_server_configuration repos_dir = server_configuration["repos_dir"] if repository_name = args.shift repository_name = repository_name.strip # check if repo exists error %(Repository #{repository_name} does not exist") unless repository_in_server_config?(server_configuration, repository_name) repo = server_configuration['repositories'][repository_name] display "Repository Name: #{repo['id']}" repo['localized_labels'].split(',').each do |localized_label| locale, label = localized_label.split(':') display "Label for locale '#{locale}': #{label}" end display "Authentication Token Timeout: #{repo['authenticationTokenTimeout']}" display "Domain of Generated URLs: #{repo['serverAliasURL']}" display "REST API Base Path: #{repo['restfulApiBasePath']}" else server_configuration['repositories'].each do |repo_name, repo_conf| display "Repository Name: #{repo_name}" end end end |
#populate ⇒ Object
239 240 241 |
# File 'lib/astroboa-cli/command/repository.rb', line 239 def populate end |