MasterofProject

Talking about the Postgres database of cloud_controller in Foundry Cloud

Label ActiverecordCloudFoundryServicedatabase
1253 people read comments(0) Collection Report
Classification:

Familiar with Foundry Cloud technical staff, certainly not unfamiliar to cloud_controller. Cloud_controller as Foundry Cloud management module, on the one hand, the management of the user's RESTful request, on the other hand, some of the important configuration information persistent, stored in the cloud_controller node database.

About cloud_controller node in the database, in-depth understanding of the Foundry Cloud, it will be found in fact is the Postgres 8.4 relational database. In addition to the Foundry Cloud there is a postgres9.0, the database will serve as a service for the user to use.

ActiveRecord is a component used to map objects to the database table in Rails. This function is calledObject relation mapping(Mapping Object-relational), it can also use the relational database (to support persistence) and object oriented programming (used to support business logic) to deal with the advantages of business. ActiveRecord can be used in Rails, but also can be used in ordinary procedures. In Rails applications, ActiveRecord is applied to the model ("M" in MVC).

The database in cloud_controller is an example of using ActiveRecord. The following introduction is based on the Postgres cloud_controller database service data table. Service data table is mainly to store the information of the gateway (label URL, gateway, description, etc.).

Service.rb mainly describes the format of the data table as well as the attribute description. The following one one said:

LABEL_REGEX = /^\S+-\S+$/
This code is mainly set up a regular expression, in order to verify the correctness of the label format.

Validates_format_of: Label: with = > LABEL_REGEX
Validate_format_of is mainly to verify the actual operation of the attribute data generated in a certain format, the specific format is: with behind the regular expression.

Validates_presence_of: label,: URL,: Token
The above code means: verify: lable,: URL,: token these three properties are non nil or null string.

On this verification of the operation, there will be very validation key words, such as in the service.rb file:

Validates_uniqueness_of: Label: scope: provider = >

Validates_format_of: URL: with: regexp = > URI: (%w (HTTP HTTPS))
Validates_format_of: info_url: with: regexp = > URI: (%w (HTTP HTTPS)),: allow_nil = > true
Validates_format_of: Label: with = > LABEL_REGEX
Validate: cf_plan_id_matches_plans
The uniqueness of validates_uniqueness_of validation data in the data table.

Validates_format_of validation data in the format of the data sheet.

Validate call save operation, in the case that the cf_plan_id and plan matching.

In addition, the method is validated:

Validates_length_of validation length, for exampleValidates_length_of: Numbers: maxmin>=100

Validates_numericality_of verify whether it is a number, and can limit the size of the number, such asValidates_numericality_of: age: greater_than = > 18

Validates_inclusion_of verify that the data is in some range of values, such asValidates_inclusion_of: status: in = > ["pending", "sent"]

The following is about the contents of the serialize:

Serialize: Tags
Serialize: Plans
Serialize: cf_plan_id
Serialize: plan_options
Serialize: binding_options
Serialize: ACLS
# supported_versions in array, like [1, 2]
Serialize: supported_versions
Optional alias hash for service versions #
# for example {"current" = "1", "2" = > "next"}
Serialize: version_aliases

One of the most important key word is serialize. Serialize is the meaning of serialization, and its role is to convert some of the things that can be stored or transmitted by the data table information.

Now look at this line of code:

Attr_accessible: label,: token,: URL,: description,: info_url,: tags,......
Which attr_accessible keyword is very important. Here will involve a assignment mass problem, that is, in a large number of assignment problems, for example, there is a property in the data table can not be visible to all users, then there may be some unsafe behavior in assignment mass, such as ordinary users do administrators to use the attributes were modified, etc.. And in the use of attr_accessible, these properties will be automatically ignored when assignment mass. If these attributes need to be assigned, then they can only be done manually.

top
Zero
tread
Zero
Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website
    personal data
    • Visit81625 times
    • Integral:One thousand three hundred and twenty-seven
    • Grade
    • Rank:18622nd name
    • Original47
    • Reproduced:0
    • Translation:1
    • Comments:49
    Blog column
    Contact information
    Latest comments