RDS リードレプリカ

リードレプリカというのは、読み込み専用として利用することができるマスターの複製データベース
非同期のため常にマスターと完全に内容が一致しているわけではなく常に最新のデータが取得できるということではありませんので、マスターの負荷分散用として利用するのがよい

Amazon RDS リードレプリカによって、データベース (DB) インスタンスのパフォーマンスと耐久性が向上する

1 つの DB インスタンスのキャパシティーを伸縮自在にスケールし、読み取り頻度の高いデータベースのワークロードを緩和

Amazon RDS for MySQL、MariaDB、PostgreSQL、および Amazon Aurora
読み込みクエリをアプリケーションからリードレプリカにルーティングすることにより、ソース DB インスタンスへの負荷を減らすことができる

AWS Athena

Amazon Athena は、標準的な SQL を使用して Amazon S3 のデータを簡単に分析できるインタラクティブなクエリサービス
S3 のデータを指定し、スキーマを定義して、標準的な SQL を使用してデータのクエリを開始するだけ

Examples include CSV, JSON, or columnar data formats such as Apache Parquet and Apache ORC. You can use Athena to run ad-hoc queries using ANSI SQL, without the need to aggregate or load the data into Athena.

([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*):([0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) (-|[0-9]*) (-|[0-9]*) ([-0-9]*) ([-0-9]*) “([^ ]*) ([^ ]*) (- |[^ ]*)” (“[^”]*”) ([A-Z0-9-]+) ([A-Za-z0-9.-]*)$

AWS SNS

概念図

putty

console

aws iot create-keys-and-certificate --set-as-active \
--certificate-pem-outfile certs/certificate.pem.crt \
--public-key-outfile certs/public.pem.key \
--private-key-outfile certs/private.pem.key \
--region us-west-2

backlogの課題を取得

<?php
$params = array(
    'apiKey' => 'API key',
    'projectId[]' => 'project id',
    'statusId' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4),
    'sort' => 'updated',
    'count' => 100,
);
$url = 'https://{$hoge}.backlog.com/api/v2/issues?'.http_build_query($params, '','&');
$headers = array('Content-Type:application/x-www-form-urlencoded');
$context = array(
    'http' => array(
        'method' => 'GET',
        'header' => $headers,
        'ignore_errors' => true,
    )
);
$response = file_get_contents($url, false, stream_context_create($context));
$json = mb_convert_encoding($response, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
$json = json_decode($json, true);
echo "<pre>";
var_dump($json);
echo "</pre>";
?>

複数projectなら、こんな感じで書く。

'projectId' => array(42107 => 42107, 42116 => 42116),

$jsonは連想配列で返ってくる。
foreachでいってみよう!

foreach($json as $value){
     echo $value["issueType"]["name"] ." ".$value["issueKey"]." ". $value["summary"]." " .$value["assignee"]["name"]. " ".$value["status"]["name"]." ".$value["priority"]["name"]."".$value["created"]." ".$value["dueDate"]." " .$value["updated"]." ".$value["createdUser"]["name"]."<br>";
}

うお。

tableで表示したい。その前に、日付フォーマット。date(‘m/d’, strtotime($value[“created”]))とする。

foreach($json as $value){
     echo $value["issueType"]["name"] ." ".$value["issueKey"]." ". $value["summary"]." " .$value["assignee"]["name"]. " ".$value["status"]["name"]." ".$value["priority"]["name"]."".date('m/d', strtotime($value["created"]))." ".date('m/d', strtotime($value["dueDate"]))." " .date('m/d', strtotime($value["updated"]))." ".$value["createdUser"]["name"]."<br>";
}

うお、nullだと01/01になる。。冗長だが。。

foreach($json as $value){
     if(!is_null($value["dueDate"])){
        echo $value["issueType"]["name"] ." ".$value["issueKey"]." ". $value["summary"]." " .$value["assignee"]["name"]. " ".$value["status"]["name"]." ".$value["priority"]["name"]."".date('m/d', strtotime($value["created"]))." ".date('m/d', strtotime($value["dueDate"]))." " .date('m/d', strtotime($value["updated"]))." ".$value["createdUser"]["name"]."<br>";
     } else {
        echo $value["issueType"]["name"] ." ".$value["issueKey"]." ". $value["summary"]." " .$value["assignee"]["name"]. " ".$value["status"]["name"]." ".$value["priority"]["name"]."".date('m/d', strtotime($value["created"]))." "." "." " .date('m/d', strtotime($value["updated"]))." ".$value["createdUser"]["name"]."<br>";
     }
}

backlog api

1. APIキーを取得
Backlogログイン -> 個人設定 -> API -> 新しいAPIキーを設定 -> APIキー発行
2. spaceIdを確認
https://{$spaceID}.backlog.com/
3. 課題の種別のID
https://{$spaceID}.backlog.com/ListIssueType.action?projectId={$課題の種別のID}

string(66) “{“errors”:[{“message”:”Not Found Space.”,”code”:6,”moreInfo”:””}]}”

スペースがない!?

https://hoge.backlog.jp/api/v2/issues?

よくみたら.jp ではなく、.com ならいけますな

https://hoge.backlog.com/api/v2/issues?

Embulkを使ってみる

wget -O test.tar.gz https://github.com/livedoor/datasets/blob/master/ldgourmet.tar.gz?raw=true

[vagrant@localhost embulk]$ ls
test.tar.gz
[vagrant@localhost embulk]$ tar xvfz test.tar.gz
areas.csv
categories.csv
prefs.csv
ratings.csv
rating_votes.csv
restaurants.csv
stations.csv

Embulk

Embulkとは
~Pluggable Bulk Data Loader~
-並列データ転送ツール
-Fluentd開発者 古橋氏が開発
-Fluentdのバッチ版
-プラグインアーキテクチャ

An open-source plugin-based parallel bulk data loader that makes painful data integration work relaxed.
Founder & Software Architect, Treasure Data, inc.

CSV Files, S3, SequenceFile, HDFS, MySQL、Salesforce.com
⇒ bulk load =>
Hive, Elasticsearch, Cassandra, Redis

fluentdはstream、embulkはstorage
巨大データに対応(並列分散処理)
高速性、トランザクション制御
スキーマを使ったバリデーション
実行はコマンド

Input Plugin
RDBS ( mysql, postgres, jdbc… )
NoSQL ( redis, mongodb)
Cloud Service (redshift, s3 )
Files (CSV, JSON …)
Etc ( hdfs, http, elastic search, slack-history, google analitics )

Output Plugin
RDBS ( mysql, postgres, oracle, jdbc…)
Cloud Service ( redshift, s3, bigquery)
NoSQL ( redis, hdfs )
Files
Etc ( elastic search, hdfs, swift)

Filter Plugin
column (カラムを削る)
insert 指定した場所にホスト名などのカラム追加する
row 所定の条件に合致するローのみ抽出する
rearrange 一行のデータを複数行に再構成する

File parser Plugin
json
xml
csv
apache log
query_string
regex

File formatter Plugin
json
レコードの内容をjsonl(1 json 1行)の形式に整形するプラグイン
poi_excel
Excel(xls,xlsx)形式のデータに変換するプラグイン

mapreduce
EmbulkのタスクをHadoop上で実行するためのプラグイン
Executor Plugin

とりあえる、入れます。
[vagrant@localhost embulk]$ brew install embulk
[vagrant@localhost embulk]$ embulk –version
embulk 0.9.7

0.9.7ですね。

config/deploy/stage.rb

server 'localhost', user: 'vagrant', roles: %w{web}
set :repo_url, 'git@github.com:mumoshu/finagle_sample_app'

fetch :repo_url
#=> "git@github.com:mumoshu/finagle_sample_app"

task :uptime do
	run_locally do
		output = capture "uptime"
	end
	on roles(:web) do
		output = caputer "uptime"
	end
end

# ソースコードの取得
set :application, 'finalge_sample_app'
set :repo_url, 'git@github.com:mumoshu/finagle_sample.git'

task :update do
	run_locall do
		application = fetch :application
		if test "[ -d #{application} ]"
			execute "cd #{application}; git pull"
		end
	else
		execute "git clone #{fetch :repo_url} #{application}"
	end
  end
end

task :archive => :update do
	run_locally do
		sbt_output = capture "cd #{fetch :application}; sbt pack-archive"

		sbt_output_without_escape_sequences = sbt_output.lines.map {|line| line.gsub(/\e\[\d{1,2}m/,''])}.join

		archive_relative_path = sbt_output_without_escape_sequences.match(/\[info\] Generating (?<archive_path>.+\.tar\.gz)\s*$[:archive_path]
		archive_name =archive_relative_path.match(/(?<archive_name>[^\/]+\.tar\.gz)$/)[:archive_name]
		archive_absolute_path = File.join(capter("cd #{fetch(:application)}; pwd").chomp, archive_relative_path)

		info archive_absolute_path
		info archive_name

		set :archive_absolute_path, archive_absolute_path
		set :archive_name, archive_name
	end
end 

task :deploy => :archive do
	archive_path = fetch :archive_absolute_path
	archive_name = fetch :archive_name
	release_path = File.join(fetch(:deploy_to), fetch(:application))

	on roles(:web) do
		unless test "[ -d #{release_path} ]"
			execute "mkdir -p #{release_path}"
		end

		upload! archive_path, release_path

		execute "cd #{relase_path}; tar -zxvf #{archive_name}"

	end
end