server: Startup message now prints configured ARNs. (#2653)

Fixes #2628
master
Harshavardhana 8 years ago committed by GitHub
parent e3de237eb8
commit 040af08473
  1. 4
      cmd/bucket-handlers.go
  2. 8
      cmd/bucket-notification-handlers.go
  3. 16
      cmd/config-v7_test.go
  4. 18
      cmd/event-notifier.go
  5. 68
      cmd/event-notifier_test.go
  6. 8
      cmd/object-handlers.go
  7. 6
      cmd/server-main.go
  8. 5
      cmd/server-startup-msg.go
  9. 2
      cmd/web-handlers.go

@ -290,7 +290,7 @@ func (api objectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter,
// Write success response. // Write success response.
writeSuccessResponse(w, encodedSuccessResponse) writeSuccessResponse(w, encodedSuccessResponse)
if eventN.IsBucketNotificationSet(bucket) { if globalEventNotifier.IsBucketNotificationSet(bucket) {
// Notify deleted event for objects. // Notify deleted event for objects.
for _, dobj := range deletedObjects { for _, dobj := range deletedObjects {
eventNotify(eventData{ eventNotify(eventData{
@ -403,7 +403,7 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
// Write successful response. // Write successful response.
writeSuccessNoContent(w) writeSuccessNoContent(w)
if eventN.IsBucketNotificationSet(bucket) { if globalEventNotifier.IsBucketNotificationSet(bucket) {
// Fetch object info for notifications. // Fetch object info for notifications.
objInfo, err := api.ObjectAPI.GetObjectInfo(bucket, object) objInfo, err := api.ObjectAPI.GetObjectInfo(bucket, object)
if err != nil { if err != nil {

@ -141,7 +141,7 @@ func (api objectAPIHandlers) PutBucketNotificationHandler(w http.ResponseWriter,
} }
// Set bucket notification config. // Set bucket notification config.
eventN.SetBucketNotificationConfig(bucket, &notificationCfg) globalEventNotifier.SetBucketNotificationConfig(bucket, &notificationCfg)
// Success. // Success.
writeSuccessResponse(w, nil) writeSuccessResponse(w, nil)
@ -227,7 +227,7 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit
return return
} }
notificationCfg := eventN.GetBucketNotificationConfig(bucket) notificationCfg := globalEventNotifier.GetBucketNotificationConfig(bucket)
if notificationCfg == nil { if notificationCfg == nil {
writeErrorResponse(w, r, ErrARNNotification, r.URL.Path) writeErrorResponse(w, r, ErrARNNotification, r.URL.Path)
return return
@ -249,9 +249,9 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit
defer close(nEventCh) defer close(nEventCh)
// Set sns target. // Set sns target.
eventN.SetSNSTarget(topicARN, nEventCh) globalEventNotifier.SetSNSTarget(topicARN, nEventCh)
// Remove sns listener after the writer has closed or the client disconnected. // Remove sns listener after the writer has closed or the client disconnected.
defer eventN.RemoveSNSTarget(topicARN, nEventCh) defer globalEventNotifier.RemoveSNSTarget(topicARN, nEventCh)
// Start sending bucket notifications. // Start sending bucket notifications.
sendBucketNotification(w, nEventCh) sendBucketNotification(w, nEventCh)

@ -1,3 +1,19 @@
/*
* Minio Cloud Storage, (C) 2016 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cmd package cmd
import ( import (

@ -19,7 +19,6 @@ package cmd
import ( import (
"bytes" "bytes"
"encoding/xml" "encoding/xml"
"errors"
"fmt" "fmt"
"net/url" "net/url"
"path" "path"
@ -112,7 +111,7 @@ func (en *eventNotifier) SetSNSTarget(snsARN string, listenerCh chan []Notificat
en.rwMutex.Lock() en.rwMutex.Lock()
defer en.rwMutex.Unlock() defer en.rwMutex.Unlock()
if listenerCh == nil { if listenerCh == nil {
return errors.New("invalid argument") return errInvalidArgument
} }
en.snsTargets[snsARN] = append(en.snsTargets[snsARN], listenerCh) en.snsTargets[snsARN] = append(en.snsTargets[snsARN], listenerCh)
return nil return nil
@ -161,7 +160,7 @@ func (en *eventNotifier) SetBucketNotificationConfig(bucket string, notification
en.rwMutex.Lock() en.rwMutex.Lock()
defer en.rwMutex.Unlock() defer en.rwMutex.Unlock()
if notificationCfg == nil { if notificationCfg == nil {
return errors.New("invalid argument") return errInvalidArgument
} }
en.notificationConfigs[bucket] = notificationCfg en.notificationConfigs[bucket] = notificationCfg
return nil return nil
@ -178,8 +177,11 @@ func eventNotify(event eventData) {
// - s3:ObjectCreated:CompleteMultipartUpload // - s3:ObjectCreated:CompleteMultipartUpload
// - s3:ObjectRemoved:Delete // - s3:ObjectRemoved:Delete
nConfig := eventN.GetBucketNotificationConfig(event.Bucket) nConfig := globalEventNotifier.GetBucketNotificationConfig(event.Bucket)
// No bucket notifications enabled, drop the event notification. // No bucket notifications enabled, drop the event notification.
if nConfig == nil {
return
}
if len(nConfig.QueueConfigs) == 0 && len(nConfig.TopicConfigs) == 0 && len(nConfig.LambdaConfigs) == 0 { if len(nConfig.QueueConfigs) == 0 && len(nConfig.TopicConfigs) == 0 && len(nConfig.LambdaConfigs) == 0 {
return return
} }
@ -198,7 +200,7 @@ func eventNotify(event eventData) {
eventMatch := eventMatch(eventType, qConfig.Events) eventMatch := eventMatch(eventType, qConfig.Events)
ruleMatch := filterRuleMatch(objectName, qConfig.Filter.Key.FilterRules) ruleMatch := filterRuleMatch(objectName, qConfig.Filter.Key.FilterRules)
if eventMatch && ruleMatch { if eventMatch && ruleMatch {
targetLog := eventN.GetQueueTarget(qConfig.QueueARN) targetLog := globalEventNotifier.GetQueueTarget(qConfig.QueueARN)
if targetLog != nil { if targetLog != nil {
targetLog.WithFields(logrus.Fields{ targetLog.WithFields(logrus.Fields{
"Records": notificationEvent, "Records": notificationEvent,
@ -211,7 +213,7 @@ func eventNotify(event eventData) {
ruleMatch := filterRuleMatch(objectName, topicConfig.Filter.Key.FilterRules) ruleMatch := filterRuleMatch(objectName, topicConfig.Filter.Key.FilterRules)
eventMatch := eventMatch(eventType, topicConfig.Events) eventMatch := eventMatch(eventType, topicConfig.Events)
if eventMatch && ruleMatch { if eventMatch && ruleMatch {
targetListeners := eventN.GetSNSTarget(topicConfig.TopicARN) targetListeners := globalEventNotifier.GetSNSTarget(topicConfig.TopicARN)
for _, listener := range targetListeners { for _, listener := range targetListeners {
listener <- notificationEvent listener <- notificationEvent
} }
@ -352,7 +354,7 @@ func loadAllQueueTargets() (map[string]*logrus.Logger, error) {
} }
// Global instance of event notification queue. // Global instance of event notification queue.
var eventN *eventNotifier var globalEventNotifier *eventNotifier
// Initialize event notifier. // Initialize event notifier.
func initEventNotifier(objAPI ObjectLayer) error { func initEventNotifier(objAPI ObjectLayer) error {
@ -373,7 +375,7 @@ func initEventNotifier(objAPI ObjectLayer) error {
} }
// Inititalize event notifier queue. // Inititalize event notifier queue.
eventN = &eventNotifier{ globalEventNotifier = &eventNotifier{
rwMutex: &sync.RWMutex{}, rwMutex: &sync.RWMutex{},
notificationConfigs: configs, notificationConfigs: configs,
queueTargets: queueTargets, queueTargets: queueTargets,

@ -16,7 +16,73 @@
package cmd package cmd
import "testing" import (
"reflect"
"testing"
)
// Tests event notify.
func TestEventNotify(t *testing.T) {
ExecObjectLayerTest(t, testEventNotify)
}
func testEventNotify(obj ObjectLayer, instanceType string, t TestErrHandler) {
bucketName := getRandomBucketName()
// initialize the server and obtain the credentials and root.
// credentials are necessary to sign the HTTP request.
rootPath, err := newTestConfig("us-east-1")
if err != nil {
t.Fatalf("Init Test config failed")
}
// remove the root folder after the test ends.
defer removeAll(rootPath)
initEventNotifier(obj)
// Notify object created event.
eventNotify(eventData{
Type: ObjectCreatedPost,
Bucket: bucketName,
ObjInfo: ObjectInfo{
Bucket: bucketName,
Name: "object1",
},
ReqParams: map[string]string{
"sourceIPAddress": "localhost:1337",
},
})
if err := globalEventNotifier.SetBucketNotificationConfig(bucketName, nil); err != errInvalidArgument {
t.Errorf("Expected error %s, got %s", errInvalidArgument, err)
}
if err := globalEventNotifier.SetBucketNotificationConfig(bucketName, &notificationConfig{}); err != nil {
t.Errorf("Expected error to be nil, got %s", err)
}
if !globalEventNotifier.IsBucketNotificationSet(bucketName) {
t.Errorf("Notification expected to be set, but notification not set.")
}
nConfig := globalEventNotifier.GetBucketNotificationConfig(bucketName)
if !reflect.DeepEqual(nConfig, &notificationConfig{}) {
t.Errorf("Mismatching notification configs.")
}
// Notify object created event.
eventNotify(eventData{
Type: ObjectCreatedPost,
Bucket: bucketName,
ObjInfo: ObjectInfo{
Bucket: bucketName,
Name: "object1",
},
ReqParams: map[string]string{
"sourceIPAddress": "localhost:1337",
},
})
}
// Tests various forms of inititalization of event notifier. // Tests various forms of inititalization of event notifier.
func TestInitEventNotifier(t *testing.T) { func TestInitEventNotifier(t *testing.T) {

@ -357,7 +357,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re
// write success response. // write success response.
writeSuccessResponse(w, encodedSuccessResponse) writeSuccessResponse(w, encodedSuccessResponse)
if eventN.IsBucketNotificationSet(bucket) { if globalEventNotifier.IsBucketNotificationSet(bucket) {
// Notify object created event. // Notify object created event.
eventNotify(eventData{ eventNotify(eventData{
Type: ObjectCreatedCopy, Type: ObjectCreatedCopy,
@ -456,7 +456,7 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req
} }
writeSuccessResponse(w, nil) writeSuccessResponse(w, nil)
if eventN.IsBucketNotificationSet(bucket) { if globalEventNotifier.IsBucketNotificationSet(bucket) {
// Fetch object info for notifications. // Fetch object info for notifications.
objInfo, err := api.ObjectAPI.GetObjectInfo(bucket, object) objInfo, err := api.ObjectAPI.GetObjectInfo(bucket, object)
if err != nil { if err != nil {
@ -797,7 +797,7 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
w.Write(encodedSuccessResponse) w.Write(encodedSuccessResponse)
w.(http.Flusher).Flush() w.(http.Flusher).Flush()
if eventN.IsBucketNotificationSet(bucket) { if globalEventNotifier.IsBucketNotificationSet(bucket) {
// Fetch object info for notifications. // Fetch object info for notifications.
objInfo, err := api.ObjectAPI.GetObjectInfo(bucket, object) objInfo, err := api.ObjectAPI.GetObjectInfo(bucket, object)
if err != nil { if err != nil {
@ -851,7 +851,7 @@ func (api objectAPIHandlers) DeleteObjectHandler(w http.ResponseWriter, r *http.
} }
writeSuccessNoContent(w) writeSuccessNoContent(w)
if eventN.IsBucketNotificationSet(bucket) { if globalEventNotifier.IsBucketNotificationSet(bucket) {
// Notify object deleted event. // Notify object deleted event.
eventNotify(eventData{ eventNotify(eventData{
Type: ObjectRemovedDelete, Type: ObjectRemovedDelete,

@ -256,15 +256,15 @@ func serverMain(c *cli.Context) {
// Fetch endpoints which we are going to serve from. // Fetch endpoints which we are going to serve from.
endPoints := finalizeEndpoints(tls, &apiServer.Server) endPoints := finalizeEndpoints(tls, &apiServer.Server)
// Prints the formatted startup message.
printStartupMessage(endPoints)
// Register generic callbacks. // Register generic callbacks.
globalShutdownCBs.AddGenericCB(func() errCode { globalShutdownCBs.AddGenericCB(func() errCode {
// apiServer.Stop() // apiServer.Stop()
return exitSuccess return exitSuccess
}) })
// Prints the formatted startup message.
printStartupMessage(endPoints)
// Start server. // Start server.
// Configure TLS if certs are available. // Configure TLS if certs are available.
if tls { if tls {

@ -60,6 +60,11 @@ func printServerCommonMsg(endPoints []string) {
console.Println(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKeyID))) console.Println(colorBlue("AccessKey: ") + colorBold(fmt.Sprintf("%s ", cred.AccessKeyID)))
console.Println(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretAccessKey))) console.Println(colorBlue("SecretKey: ") + colorBold(fmt.Sprintf("%s ", cred.SecretAccessKey)))
console.Println(colorBlue("Region: ") + colorBold(fmt.Sprintf(getFormatStr(len(region), 3), region))) console.Println(colorBlue("Region: ") + colorBold(fmt.Sprintf(getFormatStr(len(region), 3), region)))
arnMsg := colorBlue("SqsARNs: ")
for queueArn := range globalEventNotifier.queueTargets {
arnMsg += colorBold(fmt.Sprintf(getFormatStr(len(queueArn), 2), queueArn))
}
console.Println(arnMsg)
console.Println(colorBlue("\nBrowser Access:")) console.Println(colorBlue("\nBrowser Access:"))
console.Println(fmt.Sprintf(getFormatStr(len(endPointStr), 3), endPointStr)) console.Println(fmt.Sprintf(getFormatStr(len(endPointStr), 3), endPointStr))

@ -396,7 +396,7 @@ func (web *webAPIHandlers) Upload(w http.ResponseWriter, r *http.Request) {
return return
} }
if eventN.IsBucketNotificationSet(bucket) { if globalEventNotifier.IsBucketNotificationSet(bucket) {
// Notify object created event. // Notify object created event.
eventNotify(eventData{ eventNotify(eventData{
Type: ObjectCreatedPut, Type: ObjectCreatedPut,

Loading…
Cancel
Save