Exemplo n.º 1
0
func (self *TDynamoDBStore) InitTable() {
	glog.Info("Initializing tables")
	newTableDesc := DynamoDBDemoTableDescription()
	tableExists := self.findTableByName(newTableDesc.TableName)
	if tableExists {
		glog.Infof("Table %s exists, skipping init", newTableDesc.TableName)
		glog.Infof("Waiting until table %s becomes active", newTableDesc.TableName)
		self.waitUntilTableIsActive(newTableDesc.TableName)
		glog.Infof("Table %s is active", newTableDesc.TableName)
		return
	} else {
		glog.Infof("Creating table %s", newTableDesc.TableName)
		status, err := self.dynamoServer.CreateTable(newTableDesc)
		contract.RequireNoError(err)
		if status == TableStatusCreating {
			glog.Infof("Waiting until table %s becomes active", newTableDesc.TableName)
			self.waitUntilTableIsActive(newTableDesc.TableName)
			glog.Infof("Table %s is active", newTableDesc.TableName)
			return
		}
		if status == TableStatusActive {
			glog.Infof("Table %s is active", newTableDesc.TableName)
			return
		}
		glog.Fatal("Unexpected status:", status)
	}
}
Exemplo n.º 2
0
func (self *TDynamoDBStore) DestroyTable() {
	glog.Info("Destroying tables")
	newTableDesc := DynamoDBDemoTableDescription()
	tableExists := self.findTableByName(newTableDesc.TableName)
	if !tableExists {
		glog.Infof("Table %s doesn't exists, skipping deletion", newTableDesc.TableName)
		return
	} else {
		_, err := self.dynamoServer.DeleteTable(newTableDesc)
		if err != nil {
			glog.Fatal(err)
		}
		glog.Infof("Table %s deleted successfully", newTableDesc.TableName)
	}
}