correct spelling; add drop type to initial sql

Signed-off-by: liang chenye <liangchenye@huawei.com>
This commit is contained in:
liang chenye 2016-04-27 15:06:53 +08:00
parent 6d2f462d06
commit b2e6fd114b
9 changed files with 23 additions and 11 deletions

View File

@ -122,7 +122,7 @@ Server: clair
{
"Layer": {
"Name": "17675ec01494d651e1ccf81dc9cf63959ebfeed4f978fddb1666b6ead008ed52",
"NamespaceName": "debian:8",
"NamespaceNames": ["debian:8"],
"ParentName": "140f9bdfeb9784cf8730e9dab5dd12fbd704151cf555ac8cae650451794e5ac2",
"IndexedByVersion": 1,
"Features": [

View File

@ -35,7 +35,7 @@ type Error struct {
type Layer struct {
Name string `json:"Name,omitempty"`
NamespacesName []string `json:"NamespacesName,omitempty"`
NamespaceNames []string `json:"NamespaceNames,omitempty"`
Path string `json:"Path,omitempty"`
ParentName string `json:"ParentName,omitempty"`
Format string `json:"Format,omitempty"`
@ -54,7 +54,7 @@ func LayerFromDatabaseModel(dbLayer database.Layer, withFeatures, withVulnerabil
}
for _, namespace := range dbLayer.Namespaces {
layer.NamespacesName = append(layer.NamespacesName, namespace.Name)
layer.NamespaceNames = append(layer.NamespaceNames, namespace.Name)
}
if withFeatures || withVulnerabilities && dbLayer.Features != nil {

View File

@ -55,7 +55,9 @@ func (pgSQL *pgSQL) FindLayer(name string, withFeatures, withVulnerabilities boo
}
// Find its parent's namespaces
t = time.Now()
rows, err := pgSQL.Query(searchLayerNamespace, parentID)
observeQueryTime("FindLayer", "searchParentLayerNamespace", t)
if err != nil {
return layer, handleError("searchLayerNamespace", err)
}
@ -76,7 +78,9 @@ func (pgSQL *pgSQL) FindLayer(name string, withFeatures, withVulnerabilities boo
}
// Find its namespaces
t = time.Now()
rows, err := pgSQL.Query(searchLayerNamespace, layer.ID)
observeQueryTime("FindLayer", "searchLayerNamespace", t)
if err != nil {
return layer, handleError("searchLayerNamespace", err)
}
@ -280,8 +284,9 @@ func (pgSQL *pgSQL) InsertLayer(layer database.Layer) error {
}
// Layer's namespaces has high priority than its parent.
// Once a layer has a 'same' namespace (the content before ':' is the same)
// with its parent, it will only keep its namespace.
// Once a layer has a 'same' namespace with its parent,
// it will only keep its namespace.
//TODO: add 'Version' to Namespace and use 'Name' directly
name := strings.Split(layer.Namespaces[i].Name, ":")
mapNamespaceIDs[name[0]] = id
}
@ -297,6 +302,7 @@ func (pgSQL *pgSQL) InsertLayer(layer database.Layer) error {
parentID = zero.IntFrom(int64(layer.Parent.ID))
for _, pn := range layer.Parent.Namespaces {
//TODO: add 'Version' to Namespace and use 'Name' directly
name := strings.Split(pn.Name, ":")
if _, ok := mapNamespaceIDs[name[0]]; !ok {
// Layer will inherit its parent's namespace

View File

@ -184,3 +184,8 @@ DROP TABLE IF EXISTS Namespace,
KeyValue,
Lock
CASCADE;
DROP TYPE IF EXISTS modification,
severity,
LOCK
CASCADE;

View File

@ -113,7 +113,7 @@ const (
searchLayerNamespace = `
SELECT n.id, n.name
From LayerNamespace ln, Namespace n
FROM LayerNamespace ln, Namespace n
WHERE ln.layer_id = $1 AND ln.namespace_id = n.id`
insertLayer = `

View File

@ -114,7 +114,7 @@ func (detector *DpkgFeaturesDetector) GetRequiredFiles() []string {
return []string{"var/lib/dpkg/status"}
}
//Supported check if the input Namespace is supported by the underling detector
//Supported checks if the input Namespace is supported by the underling detector
func (detector *DpkgFeaturesDetector) Supported(namespace database.Namespace) bool {
supports := []string{"debian", "ubuntu"}

View File

@ -119,7 +119,7 @@ func (detector *RpmFeaturesDetector) GetRequiredFiles() []string {
return []string{"var/lib/rpm/Packages"}
}
//Supported check if the input Namespace is supported by the underling detector
//Supported checks if the input Namespace is supported by the underling detector
func (detector *RpmFeaturesDetector) Supported(namespace database.Namespace) bool {
supports := []string{"centos", "red hat", "fedora"}

View File

@ -28,7 +28,7 @@ type FeaturesDetector interface {
// GetRequiredFiles returns the list of files required for Detect, without
// leading /.
GetRequiredFiles() []string
//Supported check if the input Namespace is supported by the underling detector
//Supported checks if the input Namespace is supported by the underling detector
Supported(namespace database.Namespace) bool
}

View File

@ -161,6 +161,7 @@ func detectNamespaces(data map[string][]byte, parent *database.Layer) (namespace
if parent != nil {
mapNamespaces := make(map[string]database.Namespace)
for _, pn := range parent.Namespaces {
//TODO: add 'Version' to Namespace and use 'Name' directly
name := strings.Split(pn.Name, ":")
mapNamespaces[name[0]] = pn
}
@ -168,6 +169,7 @@ func detectNamespaces(data map[string][]byte, parent *database.Layer) (namespace
// Once a layer has a 'same' namespace (the content before ':' is the same)
// with its parent, it will only keep its namespace.
for _, n := range namespaces {
//TODO: add 'Version' to Namespace and use 'Name' directly
name := strings.Split(n.Name, ":")
mapNamespaces[name[0]] = n
}
@ -184,8 +186,7 @@ func detectNamespaces(data map[string][]byte, parent *database.Layer) (namespace
func detectFeatures(name string, data map[string][]byte, namespaces []database.Namespace) (features []database.FeatureVersion, err error) {
// TODO(Quentin-M): We need to pass the parent image DetectFeatures because it's possible that
// some detectors would need it in order to produce the entire feature list (if they can only
// detect a diff). Also, we should probably pass the detected namespace so detectors could
// make their own decision.
// detect a diff).
features, err = detectors.DetectFeatures(data, namespaces)
if err != nil {
return