クラウドインフラ構築記

現在AWSの構築支援に携わっております。今注視しているのは、GKE、BigQuery、Google Dataflowなどサービスを展開しているGoolge Cloud Platformです。

2012年11月25日
から hiruta
Amazon Reloaded for WordPress はコメントを受け付けていません

Amazon Reloaded for WordPress

Amazon Reloaded for WordPressでProduct Advertising APIのSecret KeyとAPI Keyが必要になったので、Product Advertising APIのサインアップサイトから行おうとした。

http://www.sprouthead.com/blog/wordpress/wordpress_plugin_amazon_reloaded_version_up-html.html

以前AWSのアカウント作成していたので、「I am a returning customer, and my password is」の後の入力欄にパスワードを入れてSign in ボタンを押しても以下のようにアカウントがサスペンドされているとかで先に進まない

上記件においてAWSサポートセンターのメール問い合わせから行いました。

その後回答をいただきましたが、問い合わせ先が違う旨の回答だった。

AWSのAccount Activityで無効になっていたみたいだったので、有効にしたところ、

Product Advertising APIのサインアップ自体は正常に完了しましたが、AWS Keyと

Secret Keyで、行っても、エラーになってしまう。

「Your credentials seem to be incorrect. Please check them and try again.」


誠に申し訳ございませんが、こちらは AWS (Amazon クラウド) のお客様のアカウントや課金についてのお問い合わせ窓口となっております。

大変お手数ではございますが、API 関連のお問い合わせは下記リンクよりAmazon マーケットプレイスWebサービス(MWS)をご利用ください。

http://developer.amazonservices.jp/

Amazon マーケットプレイスWebサービス(MWS)のお問い合わせフォームは下記リンクをご利用ください。

2012年11月25日
から hiruta
JavaFX Scene Graphにおけるコンテナの切替 はコメントを受け付けていません

JavaFX Scene Graphにおけるコンテナの切替

一度以下のように、Scene Graphを初期化(インスタンス生成)しておけば、

private Stage stage;
public void start(Stage stage){
AnchorPane root = FXMLLoader.load(getClass().getResource("/layout1.fxml"));
stage.setScene(new Scene(root, 1366, 768));

Scene Graphの中のコンテナ(Container)を切り替える場合setRootメソッドで行えば画面が切り替わります。

AnchorPane root2 = FXMLLoader.load(getClass().getResource("/layout2.fxml"));
stage.setRoot(root2);

JavaFXをはじめて使う上で、豊富なサンプルを載っているので、新しくコードを作成する上で役に立つと思います。

2012年11月25日
から hiruta
Remiリポジトリを使わないでサーバー再構築 はコメントを受け付けていません

Remiリポジトリを使わないでサーバー再構築

CentOS6の場合、デフォルトでPHP 5.3系が使用できるので、外部リポジトリのRemiを使わないでサーバー環境を構築し直した。

Remiリポジトリを使ってインストールしたMySQL、PHPをアンインストールする際、postfix、SASLとかも一端アンインストールさせないとインストールできない。

*.conf.rpmsaveとかアンインストール際残っているので、標準リポジトリでインストールしたあと、このファイルを*.confに戻してやれば問題なく復旧します。

2012年11月24日
から hiruta
テキストスクロール はコメントを受け付けていません

テキストスクロール

以下はjavafx scriptでテキストスクロールを実装している。javafx 2.0で使えるように実現してみた。なお、javafx 2.xではjavafx scriptは廃止される意向(Oracle)

Swing UIよりvisualなことが実現できるし、Java 8だとJavaFXが標準UIになることから、SwingUIを使っている場合はJavaFXにマイグレーションするのがよさそう。

JavaFx Animations – Auto text scrolling using Timeline and KeyFrame


public class TextScroll extends VBox
{
 private Number x;
 private Number y;
 private double width;
 private double height;
 private Paint stroke;
 private Number strokeWidth;
 private Text scrollingText;

 public TextScroll()
 {

Group root = new Group();

String scroll_char = "ここにスクロールする文字を入れる";

 scrollingText = TextBuilder.create()
 .text(scroll_char)
 .layoutX(50)
 .textOrigin(VPos.TOP)
 .textAlignment(TextAlignment.JUSTIFY)
 .fill(Color.PINK)
 .font(Font.font("SansSerif", FontPosture.ITALIC, 25))
 .build();

 Group myGroup = GroupBuilder.create()
 .children(scrollingText)
 .clip(RectangleBuilder.create()
 .width(1000)
 .height(40)
 .build()
 )
 .build();

width = scroll_char.length()* 20;

 root.getChildren().add(myGroup);
 this.getChildren().add(root);

 scrollUp();

 }

public boolean isScrollingText ()
 {
 return true;
 }

 public void scrollUp ()
 {
 autoTimer.play();
 }

 public void stopScrolling ()
 {
 autoTimer.stop ();
 }

 @SuppressWarnings("unchecked")
 private Timeline autoTimer = TimelineBuilder.create()
 .cycleCount(Timeline.INDEFINITE)
 .keyFrames(new KeyFrame(
 new Duration(10L),
 new EventHandler(){

public void handle(Event arg0) {
 if (scrollingText.getTranslateX() + width < 0)
 {
 scrollingText.setTranslateX(0.0);
 }
 // scrollingText.setTranslateY(scrollingText.getTranslateX()-0.5);
 scrollingText.setTranslateX(scrollingText.getTranslateX()-0.5);
 }

}
 )).build();

}

2012年11月23日
から hiruta
Secure WordPressを導入しました。 はコメントを受け付けていません

Secure WordPressを導入しました。

WordPressのセキュリティを高めることができる便利なプラグインがありました。企業向けとか構築する際に入れておいたほうがいいと思われます。
以下のようなことをプラグイン1つで行えるので、便利。最後のバージョンアップ通知を管理者のみにしておくことも可能です。
  • ログイン失敗時に出るエラーメッセージを無効化
  • 表示されるWordPressのバージョンの非表示
  • プラグインやテーマファイルを格納しているフォルダへのセキュリティ対策
  • WordPress本体やプラグイン、テーマなどのバージョンアップ通知を「管理者のみ」に制限

2012年11月23日
から hiruta
Dropbox chooser はコメントを受け付けていません

Dropbox chooser

Dropboxに保存されているファイルを選択できるエクスプロラーみたいなのが、ある。WEBアプリでDropboxと連携するものを作る場合使えそう。

https://www.dropbox.com/developers/chooser

動画など大容量ファイルを通常のWEBサーバーでは扱うのはトラフィック、負荷(アップロードサイズを上げることも可能だが、あまり上げ過ぎるとサーバーがメモリ不足が不安定になる)のことを考えるとAmazonS3に代表されるクラウド型ストレージを使うのが得策と思う。

CGIはperlの仕様上、アップロードサイズの制限はないようだが、大きすぎるファイルをアップロードすると、同じくメモリ不足になる可能性があります。プログラム側でサイズを制限するのが必須。

2012年11月23日
から hiruta
Dropbox java SDKにて認証情報をファイル(jsonフォーマット)への保存 はコメントを受け付けていません

Dropbox java SDKにて認証情報をファイル(jsonフォーマット)への保存

Dropboxへ接続できるようにWEB認証を利用して認証情報をファイルに保存するサンプルになります。認証情報をファイルに保存しておくことでWEB認証しなくてもファイルのアップロードなどが行えるようになります。HTTP POSTでアップロードするとWEBサーバーの設定、スペックによりアップロードできない場合がありますが、HTTPを使用しないで行えばHTTP POSTの制約はなくなります。


    	AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
        WebAuthSession targetSession = new WebAuthSession(appKeys,
        WebAuthInfo authInfo = targetSession.getAuthInfo();

        RequestTokenPair pair = authInfo.requestTokenPair;
        String url = authInfo.url;

        Desktop.getDesktop().browse(new URL(url).toURI());
        JOptionPane.showMessageDialog(null, "Press ok to continue once you have authenticated.");
        String uid = targetSession.retrieveWebAccessToken(pair);

        State state = new State(appKeys);

        state.links.put(uid, targetSession.getAccessTokenPair());
        state.save(STATE_FILE);

    }
  

 

    // ------------------------------------------------------------------------
    private static RuntimeException die(String message)
    {
        System.err.println(message);
        return die();
    }
    private static RuntimeException die()
    {
        System.exit(1);
        return new RuntimeException();
    }
    // ------------------------------------------------------------------------
    // State model (load+save to JSON)
    public static final class State
    {
        public final AppKeyPair appKey;
        public final Map links = new HashMap();
        public State(AppKeyPair appKey)
        {
            this.appKey = appKey;
        }
        public void save(String fileName)
        {
            JSONObject jstate = new JSONObject();
            // Convert app key
            JSONArray japp = new JSONArray();
            japp.add(appKey.key);
            japp.add(appKey.secret);
            jstate.put("app_key", japp);
            // Convert 'Link' objects (uid -> access token)
            JSONObject jlinks = new JSONObject();
            for (Map.Entry link : links.entrySet()) {
                String uid = link.getKey();
                AccessTokenPair access = link.getValue();
                JSONArray jaccess = new JSONArray();
                jaccess.add(access.key);
                jaccess.add(access.secret);
                jlinks.put(uid, jaccess);
            }
            jstate.put("links", jlinks);
            try {
                FileWriter fout = new FileWriter(fileName);
                try {
                    jstate.writeJSONString(fout);
                }
                finally {
                    fout.close();
                }
            }
            catch (IOException ex) {
                throw die("ERROR: unable to save to state file \"" + fileName + "\": " + ex.getMessage());
            }
        }
        public static State load(String fileName)
        {
            JsonThing j;
            try {
                FileReader fin = new FileReader(fileName);
                try {
                    j = new JsonThing(new JSONParser().parse(fin));
                } catch (ParseException ex) {
                    throw die("ERROR: State file \"" + fileName + "\" isn't valid JSON: " + ex.getMessage());
                } finally {
                    fin.close();
                }
            }
            catch (IOException ex) {
                throw die("ERROR: unable to load state file \"" + fileName + "\": " + ex.getMessage());
            }
            try {
                JsonMap jm = j.expectMap();
                JsonList japp = jm.get("app_key").expectList();
                AppKeyPair appKey = new AppKeyPair(japp.get(0).expectString(), japp.get(1).expectString());
                State state = new State(appKey);
                JsonMap jlinks = jm.get("links").expectMap();
                for (Map.Entry jlink : jlinks) {
                    JsonList jaccess = jlink.getValue().expectList();
                    AccessTokenPair access = new AccessTokenPair(jaccess.get(0).expectString(), jaccess.get(1).expectString());
                    state.links.put(jlink.getKey(), access);
                }
                return state;
            }
            catch (JsonExtractionException ex) {
                throw die ("ERROR: State file has incorrect structure: " + ex.getMessage());
            }
        }
    }
    public static final class Link
    {
        public final String uid;
        public final AccessTokenPair accessToken;
        public Link(String uid, AccessTokenPair accessToken)
        {
            this.uid = uid;
            this.accessToken = accessToken;
        }
    }

    private static String getLinkid(String fileName) {
        JsonThing j;
        String linkid = "";

        try {
            FileReader fin = new FileReader(fileName);
            try {
                j = new JsonThing(new JSONParser().parse(fin));
            } catch (ParseException ex) {
                throw die("ERROR: State file \"" + fileName + "\" isn't valid JSON: " + ex.getMessage());
            } finally {
                fin.close();
            }
        }
        catch (IOException ex) {
            throw die("ERROR: unable to load state file \"" + fileName + "\": " + ex.getMessage());
        }
        try {
            JsonMap jm = j.expectMap();
            JsonMap jlinks = jm.get("links").expectMap();

            for (Map.Entry jlink : jlinks) {
                linkid = jlink.getKey();
                break;
            }
            return linkid;
        }
        catch (JsonExtractionException ex) {
            throw die ("ERROR: State file has incorrect structure: " + ex.getMessage());
        }
    }
}