react 16 개발시 date/time 관련 패키지는 아래 react-datetime lib(https://github.com/YouCanBookMe/react-datetime)가 가장 나은 것 같다.




https://github.com/YouCanBookMe/react-datetime은 모멘트(moment) 기반으로 되어 있다. 


사용 법은 다음과 같다.


<td><Datetime locale="ko" dateFormat="YYYY-MM-DD" timeFormat="HH:mm" defaultValue={ this.props.fromTime } /></td>



Posted by '김용환'
,


scala 2.6에 react 16 연동 작업을 진행하다가 sbt-reactjs에서 사용 중인 graceful-readlink와 minimatch 라이브러리가 사라졌다. (scala-react 연동은 아주 작은 프로젝트만 사용가능하다..)


다음과 같이 수정하니 잘 동작한다. 



resolvers += "Typesafe Releases Repository" at "http://repo.typesafe.com/typesafe/releases/" resolvers += "Central Maven Repository" at "http://repo.maven.apache.org/maven2" resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.6") addSbtPlugin("com.github.ddispaltro" % "sbt-reactjs" % "0.6.8") dependencyOverrides += "org.webjars.npm" % "minimatch" % "3.0.4" dependencyOverrides += "org.webjars.npm" % "graceful-readlink" % "1.0.1"

https://raw.githubusercontent.com/knight76/play26-scala-reactjs-example/master/project/plugins.sbt

Posted by '김용환'
,



NIFI 프로세서에서 마지막 프로세스의 provenance history를 보면 event type을 보다가 DROP이라는 것이 눈에 띄여 조사를 해보았다.


DROP 이벤트 타입의 경우 Detail을 보면 Auto-Terminated by success Relationship으로 나타난다.



관련된 내용은 다음을 참고한다. 


https://nifi.apache.org/docs/nifi-docs/html/developer-guide.html



NIFI의 Data Provenance 기능은 수신된 각 데이터에서 무슨 일이 발생했는지 정확히 알 수 있다 FlowFile이 수신된 시간, 수정된 시간, 특정 방식으로 라우팅된 시간, 전송 시간 등을 보여주는 그래프를 제공한다. 또한 그래프에서 이벤트가 발생한 이유를 알 수 있다. 


이를 구분하는 단계로 Event Type이 구분하는 역할을 진행한다. 


DROP 타입은 FlowFile의 끝을 의미하는 것이고 Detail에 따라 성공했기 때문에 자동 종료했음을 나타내는 의미한다. 


 

'Cloud' 카테고리의 다른 글

[fluentd]의 fluent-plugin-forest(forest)  (0) 2018.01.22
[fluentd] filter/record에 예약어 존재  (0) 2017.12.18
NIFI 팁  (0) 2017.12.08
[nifi] tail -> cassandra 저장 예제  (0) 2017.12.01
Bad neighbors/Noisy neighbors  (0) 2017.11.15
Posted by '김용환'
,


리액트 웹앱 제작 총론(learning react)의 14장 예시에 화면 리프레시를 안하는 기능이 있어서 정리한다. 



var destination = document.querySelector("#container");
var TodoItems = React.createClass({
render() {
var todoEntries = this.props.entries;
function createTasks(item) {
return <li key={item.key}>{item.text}</li>
}

console.log("aaa")
var listItems = todoEntries.map(createTasks);
return (
<ul className="theList">
{listItems}
</ul>
);
}
});
var TodoList = React.createClass({
getInitialState: function() {
return {
items: []
};
},
addItem(e) {
var itemArray = this.state.items;
itemArray.push(
{
text: this._inputElement.value,
key: Date.now()
}
);
this.setState({
items: itemArray
});

this._inputElement.value = ""
this._inputElement.focus
e.preventDefault();
},
render() {
return (
<div className="todoListMain">
<div className="header">
<form onSubmit={this.addItem}>
<input ref={(a) => this._inputElement = a}
placeholder="enter task">
</input>
<button type="submit">add</button>
</form>
</div>
<TodoItems entries={this.state.items}/>
</div>
);
}
});

ReactDOM.render(
<div>
<TodoList/>
</div>,
destination
);



html에서 form onSubmit을 호출할 때는 무조건 페이지가 로딩된다.


그러나, addItem() 아래 부분에 아래를 추가하면.. 클릭 이벤트를 실행하지만 웹 브라우져는 이동하지 말라는 뜻이다. 


e.preventDefault();



java script에서 이벤트 전파를 중단하는 4가지 방법을 설명한 내용은 다음 블로그에 있다.



http://programmingsummaries.tistory.com/313


- event.preventDefault()

- event.stopPropagation()

- eventstopImmediatePropagation()

- return false


Posted by '김용환'
,


자바스크립트 지식이 전무해서 리액 웹앱 제작 총론(learning react)를 공부하고 있다.


책의 내용이 조금 다르지만 원래는 블로그였다. 중간까지는 거의 같은데, 뒷부분부터는 조금씩 달라진다. 


https://www.kirupa.com/react/




12장 내용은 저자 블로그에 아예 없는데,  중국 블로거 싸이트에 소스가 있으니 참조할 수 있다. 


http://www.zcfy.cc/article/1558





실제 책 소스는 아래를 참조한다. 


https://github.com/kirupa/kirupa/tree/master/reactjs






Posted by '김용환'
,

NIFI 팁

Cloud 2017. 12. 8. 10:59


NIFI 공부에 도움되는 문서


https://nifi.apache.org/docs/nifi-docs/html/user-guide.html


https://www.slideshare.net/KojiKawamura/apache-nifi-10-in-nutshell


https://nifi.apache.org/docs/nifi-docs/html/user-guide.html#Reporting_Tasks





* nifi 1.4 (최신) 설치


https://nifi.apache.org/download.html



* 설정

미리 zk 설정되야 한다. 



<nifi.properties 수정>



nifi.web.http.host=장비 이름


nifi.cluster.is.node=true

nifi.cluster.node.address=장비 이름



nifi.zookeeper.connect.string=zk서버들

nifi.zookeeper.connect.timeout=3 secs

nifi.zookeeper.session.timeout=3 secs

nifi.zookeeper.root.node=/samuel-nifi




<bootstrap.conf 수정>


# JVM memory settings

java.arg.2=-Xms16g

java.arg.3=-Xmx16g





* 시작


5대를 클러스터링할 수 있도록 설정을 수정하니 약 3분 정도 소요된다. (완전 좋은 장비를 이용했다)

클러스터링 시작 시간은 3분(디폴트)이며 수정가능하다. 수정한 내용은 뒤에서 설명..




$ bin/nifi.sh start


Java home: /usr/java/default

NiFi home: /home/deploy/nifi-1.4.0


Bootstrap Config File: /home/deploy/nifi-1.4.0/conf/bootstrap.conf




* 확인하기 


$ bin/nifi.sh  status


Java home: /usr/java/default

NiFi home: /home/deploy/nifi-1.4.0


Bootstrap Config File: /home/deploy/nifi-1.4.0/conf/bootstrap.conf


2017-12-07 15:30:32,753 INFO [main] org.apache.nifi.bootstrap.Command Apache NiFi is currently running, listening to Bootstrap on port 57300, PID=60012


로그(logs)를 보면서 정상적으로 동작하는 지 확인할 수 있다. 




* 중지/재시작 후 


$ bin/nifi.sh stop

$ bin/nifi.sh start





* 설정 수정 


1. master election 시간은 5 mins이라서 수정하는 것이 좋다.


nifi.cluster.flow.election.max.wait.time=1 mins



2. nifi 웹에서의 디폴트 타임아웃이 응근히 짧다. 5초인데.. single web application으로 구현된 UI라 좀 걸릴 수 있어서 느리게 해도 된다.


nifi.cluster.node.connection.timeout=30 sec

nifi.cluster.node.read.timeout=30 sec




3. 그룹 Thread 디폴트 값은 1이라서 그룹 Thread 크기를 늘리는 것이 좋다. 


Maximum Timer Driven Thread Count 

Maximum Event Driven Thread Count 





4. 커보로스 파일 설정은 다음과 같다. 


nifi.kerberos.krb5.file=/etc/krb5.conf



5. 재시작시 자동 플레이(autoresume)이 안되게 한다.

빅 데이터 처리로 이미 클러스터링이 깨진 상태에서 


nifi.flowcontroller.autoResumeState=false



 


* 주의 할 점


1. 

하둡 관련된 부분을 수정하면 nifi 전체 재시작을 해야 한다. 바로 동작되지 않는다. 




2.

클러스터링이 끊어진 상태에서 특정 서버에서만 설정을 바꾼 경우.. 다

서버 상태는 Status라고 나오지만,, 다음과 같은 에러가 발생할 수 있다. 



2017-12-07 19:22:40,170 ERROR [main] o.a.nifi.controller.StandardFlowService Failed to load flow from cluster due to: org.apache.nifi.controller.UninheritableFlowException: Failed to connect node to cluster because local flow is different than cluster flow.

org.apache.nifi.controller.UninheritableFlowException: Failed to connect node to cluster because local flow is different than cluster flow.

at org.apache.nifi.controller.StandardFlowService.loadFromConnectionResponse(StandardFlowService.java:937)



문제된 서버에 클러스터링된 conf/flow.xml.gz을 삭제하고 다른 서버의 conf/flow.xml.gz을 복사한 후, 재시작하면 잘 연결된다. 


nifi.properties에 설정 파일을 가르킬 수 있다. 

nifi.flow.configuration.file=./conf/flow.xml.gz



3. 


스토리지가 죽으면 nifi는 열리지 않는다.. bottleneck은 스토리지이다. 최대 개수의 효과를 누리고 싶지만 잘못하고 connection 수가 너무 많아 storage 죽을 수 있다는 점을 명심할 필요가 있다. 



4.  

nifi web이 동작하지 못할 정도로 문제가 되어 강제 재시작하면 다음 에러가 발생할 수 있다. 


2017-12-07 20:43:38,006 ERROR [NiFi logging handler] org.apache.nifi.StdErr

2017-12-07 20:43:38,007 ERROR [NiFi logging handler] org.apache.nifi.StdErr Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "logback-1"

2017-12-07 20:44:32,213 ERROR [NiFi logging handler] org.apache.nifi.StdErr

2017-12-07 20:44:32,213 ERROR [NiFi logging handler] org.apache.nifi.StdErr Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "cluster1-timeouter-0"

2017-12-07 20:44:56,169 ERROR [NiFi logging handler] org.apache.nifi.StdErr

2017-12-07 20:44:56,169 ERROR [NiFi logging handler] org.apache.nifi.StdErr Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Listen to Bootstrap"

2017-12-07 20:45:08,175 ERROR [NiFi logging handler] org.apache.nifi.StdErr

2017-12-07 20:45:08,175 ERROR [NiFi logging handler] org.apache.nifi.StdErr Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Provenance Maintenance Thread-2"

2017-12-07 20:46:08,291 ERROR [NiFi logging handler] org.apache.nifi.StdErr

2017-12-07 20:46:08,292 ERROR [NiFi logging handler] org.apache.nifi.StdErr Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "StandardProcessScheduler Thread-7"

2017-12-07 20:46:14,292 ERROR [NiFi logging handler] org.apache.nifi.StdErr

2017-12-07 20:46:14,293 ERROR [NiFi logging handler] org.apache.nifi.StdErr Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Provenance Maintenance Thread-3"

2017-12-07 20:47:14,481 ERROR [NiFi logging handler] org.apache.nifi.StdErr

2017-12-07 20:47:14,482 ERROR [NiFi logging handler] org.apache.nifi.StdErr Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "Timer-Driven Process Thread-37"




그래도 안되면 재시작하고.. 다시 재시작하면 된다.

그러면서 NIFI는 split brain (split network)이 생기기도 하니.. 

최대한 NIFI를 죽지 않게 잘 운영하는 것이 중요한 부분이 되지 않을까 생각되었다. cpu 부하가 50%를 넘게 하지 않는 운영의 묘가 필요한 것 같다. 




5. 모니터링 정보는 다음과 같다. 


https://nifi.apache.org/docs/nifi-docs/rest-api/

 

https://community.hortonworks.com/questions/69004/nifi-monitoring-processor-and-nifi-service.html


'Cloud' 카테고리의 다른 글

[fluentd] filter/record에 예약어 존재  (0) 2017.12.18
NIFI의 provenance 의 drop event  (0) 2017.12.12
[nifi] tail -> cassandra 저장 예제  (0) 2017.12.01
Bad neighbors/Noisy neighbors  (0) 2017.11.15
ha_proxy 인증서 pem 파일  (0) 2017.11.10
Posted by '김용환'
,


미국의 한 뉴스 기사에서 현재 거품에 대한 글을 내놓았다. 


http://news.goldseek.com/GoldSeek/1512313800.php



1991년을 기준으로 자산 가격과 GDP와의 간격을 보면 점점 버블이 올라가고 있다고 보고 있다.







미국의 불평등 지수에 따르면 상위 0.1%가 하위 90%를 갖고 있다고 소개했다. 





두번째 장은 유료라.. 볼수 없지만.. 전체적인 문맥상 좋은 징조는 아닌 듯 하다.. 

https://www.peakprosperity.com/insider/113505/when-bubbles-burst

Posted by '김용환'
,





kafka(kafka_2.11-0.10.1.0)에서 delete.topic.enable을 설정하지 않으면(delete.topic.enable=false) 토픽을 삭제하지 못하는 데모를 보여준다. 



1. 로컬에서 간단히 실행하기


- 주키퍼를 실행한다


[/usr/local/kafka_2.11-0.10.1.0] ./bin/zookeeper-server-start.sh -daemon config/zookeeper.properties


반대로 kafka 주키퍼 종료하려면 다음을 실행한다. 


[/usr/local/kafka_2.11-0.10.1.0] ./bin/zookeeper-server-stop.sh



2. kafka를 실행한다.


kafka를 실행하기 전에 먼저 설정이 delete.topic.enable 기본값(false)로 둔다.


[/usr/local/kafka_2.11-0.10.1.0] cat config/server.properties | grep delete.topic

#delete.topic.enable=true


[/usr/local/kafka_2.11-0.10.1.0] ./bin/kafka-server-start.sh  -daemon config/server.properties



x라는 토픽을 생성한다.


[/usr/local/kafka_2.11-0.10.1.0] bin/kafka-topics.sh --create --zookeeper localhost --replication-factor 1 -partition 1 --topic x

Created topic "x".


[/usr/local/kafka_2.11-0.10.1.0] bin/kafka-topics.sh --list --zookeeper localhost

x




토픽 잘 동작하는지 producer/consumer를 실행한다.


[/usr/local/kafka_2.11-0.10.1.0] bin/kafka-console-producer.sh --broker-list localhost:9092 --topic x

aaa


[/usr/local/kafka_2.11-0.10.1.0] bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic x --from-beginning

aaa



이제 x 토픽을 삭제하고 토픽 리스트를 보면 삭제라고 마크가 되어 있다.



[/usr/local/kafka_2.11-0.10.1.0] bin/kafka-topics.sh --delete --zookeeper localhost --topic x

Topic x is marked for deletion.

Note: This will have no impact if delete.topic.enable is not set to true.



[/usr/local/kafka_2.11-0.10.1.0] bin/kafka-topics.sh --list --zookeeper localhost

x - marked for deletion





없는 x 토픽에 추가하면, 다음과 같이 warning 에러가 많이 나온다. 


[/usr/local/kafka_2.11-0.10.1.0] bin/kafka-console-producer.sh --broker-list localhost:9092 --topic x

aaa

[2017-12-06 14:59:35,645] WARN Error while fetching metadata with correlation id 0 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:35,846] WARN Error while fetching metadata with correlation id 1 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:35,951] WARN Error while fetching metadata with correlation id 2 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:36,059] WARN Error while fetching metadata with correlation id 3 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:36,168] WARN Error while fetching metadata with correlation id 4 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:36,277] WARN Error while fetching metadata with correlation id 5 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:36,383] WARN Error while fetching metadata with correlation id 6 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:36,492] WARN Error while fetching metadata with correlation id 7 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:36,599] WARN Error while fetching metadata with correlation id 8 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:36,706] WARN Error while fetching metadata with correlation id 9 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:36,815] WARN Error while fetching metadata with correlation id 10 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:36,924] WARN Error while fetching metadata with correlation id 11 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:37,031] WARN Error while fetching metadata with correlation id 12 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)

[2017-12-06 14:59:37,140] WARN Error while fetching metadata with correlation id 13 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)







[/usr/local/kafka_2.11-0.10.1.0] bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic x --from-beginning

[2017-12-06 14:59:22,928] WARN Error while fetching metadata with correlation id 1 : {x=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)





2. delete.topic.enable=true로 설정한 후 kafka 실행하기 




[/usr/local/kafka_2.11-0.10.1.0] cat config/server.properties | grep delete.topic

delete.topic.enable=true



그리고, kafka를 재시작(Stop/start)한다.



토픽 만들고 다시 삭제해본다. 정상적이다.


[/usr/local/kafka_2.11-0.10.1.0] bin/kafka-topics.sh --create --zookeeper localhost --replication-factor 1 -partition 1 --topic x

Created topic "x".


[/usr/local/kafka_2.11-0.10.1.0]  bin/kafka-topics.sh --list --zookeeper localhost

x


[/usr/local/kafka_2.11-0.10.1.0] bin/kafka-topics.sh --delete --zookeeper localhost --topic x

Topic x is marked for deletion.

Note: This will have no impact if delete.topic.enable is not set to true.


[/usr/local/kafka_2.11-0.10.1.0]  bin/kafka-topics.sh --list --zookeeper localhost

test




3. 이슈


delete.topic.enable을 true로 설정했다 하더라도 토픽 삭제가 안되는 경우가 발생할 수 있다. 


예)


https://stackoverflow.com/questions/23976670/when-how-does-a-topic-marked-for-deletion-get-finally-removed


https://stackoverflow.com/questions/44564606/how-can-i-remove-kafka-topics-marked-for-deletion



이럴 때는 재시작을 하거나..  (실제로 재시작을 통해서 삭제된 경우가 있었음..)


설정의 log.dir (보통 /tmp 디렉토리)의 파일을 삭제하고 재시작하면 된다고 한다..ㅡㅡ;






4. 


참고로 한글 토픽은 생성할 수 없다. ASCII만 된다. 일부 특수 문자만 허용한다.



bin/kafka-topics.sh --create --zookeeper localhost --replication-factor 1 -partition 1 --topic 우와

Error while executing topic command : topic name 우와 is illegal,  contains a character other than ASCII alphanumerics, '.', '_' and '-'

[2017-12-06 15:02:33,492] ERROR org.apache.kafka.common.errors.InvalidTopicException: topic name 우와 is illegal,  contains a character other than ASCII alphanumerics, '.', '_' and '-'

 (kafka.admin.TopicCommand$)

Posted by '김용환'
,


7-8년 전 쯤인가... configuration server를 개발한 적이 있다.


DB 아이디와 패스워드를 암호화하여 소스 리파지토리 서버, 노트북, 물리 장비가 해킹되더라도 아이디/패스워드가 노출되지 않도록.. configuration server를 개발했다.


빌드 툴, 빌드/배포 서버에서 ant/maven 플러그인으로 configuration server에 접속해 암호화된 정보를 읽도록 하고 파일을 교체하도록 했다.  또한 개인정보보호법에 따라 3개월마다 무조건 DBA가 id와 패스워드를 변경하게 하고 DBA가 책임을 지도록 했다.





요즘은 어떨까?



https://12factor.net/ko/config 도 이런 문맥에서 얘기하고 있다. 


애플리케이션의 설정 배포 (스테이징, 프로덕션, 개발 환경 등) 마다 달라질 수 있는 모든 것들입니다. 설정에는 다음이 포함됩니다.

  • 데이터베이스, memcached 등 백엔드 서비스들의 리소스 핸들
  • Amazon S3 이나 트위터 등의 외부 서비스 인증 정보
  • 배포된 호스트의 정규화된 호스트 이름(canonical hostname)처럼 각 배포마다 달라지는 값

애플리케이션은 종종 설정을 상수로 코드에 저장합니다. 이것은 Twelve-Factor를 위반하며, Twelve-Factor는 설정을 코드에서 엄격하게 분리하는 것을 요구합니다. 설정은 배치마다 크게 다르지만, 코드는 그렇지 않습니다.

애플리케이션의 모든 설정이 정상적으로 코드 바깥으로 분리되어 있는지 확인할 수 있는 간단한 테스트는 어떠한 인증정보도 유출시키지 않고 코드베이스가 지금 당장 오픈 소스가 될 수 있는지 확인하는 것입니다.


ansible(https://docs.ansible.com/ansible/2.4/vault.html)의 경우는 암호 파일을 두어 배포를 가능하게 해두었다. 

Posted by '김용환'
,


예전 jquery를 쓰던 때를 생각하고 전역변수를 사용해보려 했다. 

<script>var data = @Html(Json.stringify(Json.toJson(title)));</script>


그러나, 크롬에서는 에러를 발생한다.


Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-lfyc2lBqjP0Km9O0kTi2WbS/mSUMSiDX55goNiumC30='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.


XSS 공격을 막는 크롬의 CSP 정책이다. 

https://developer.chrome.com/extensions/contentSecurityPolicy



결론은 meta 태그를 생성해 별의 별 짓을 했지만, 소용없었다. 처음부터 전역 변수를 사용하기 위해 인라인 스크립트를 쓰지 않는 것이 좋다.


=> common.js라는 파일에 자바 스크립트를 정의하고 호출하는 형태만 사용 가능하다. 


하지만.. input hidden을 사용하는 방식을 사용해서 전역 변수를 활용했다.




전역 변수로 쓰일 html 파일에는 다음과 같이 정의하고,

<input type="hidden" id="kemiTag" value="@kemiTag"/>

번들(분리된) java script 파일에는 document를 읽도록 했더니. 읽히긴 한다..

console.log(document.getElementById("serviceTag"))







Posted by '김용환'
,