React datetime lib(https://github.com/YouCanBookMe/react-datetime) 를 사용하고 있다. 


react datetime은 내부적으로 momentjs를 사용하고 있다. 



ISO8601 데이터를 원하는 포맷(dateFormat, timeFormat)으로 맞춘다. 

<Datetime locale="ko" dateFormat="YYYY-MM-DD" timeFormat="HH:mm" 
            defaultValue={ this.props.toTime } onChange={this.changeToTime} 
            ref={(c) => this.state.toTime = c} /></td>


onChange 이벤트일 때는 내부적으로 정의한 이벤트가 아니라 momentjs 객체가 전달되는 구조이다. 




onChangefunctionempty functionCallback trigger when the date changes. The callback receives the selected moment

 object as only parameter, if the date in the input is valid. If the date in the input is not valid, the callback receives the value of the input (a string).


따라서 setState를 호출해 e.target.value 를 사용하면 value가 없다는 에러가 발생한다.


moment 객체를 이벤트로 보내기 때문이다.  


 
changeToTime(e) {
this.setState({
toTime: moment(e).format()
});
}



moment(e)로 감싸고, format()을 호출하면 변경된 시간 문자열을 얻을 수 있다.








Posted by '김용환'
,



React 16으로 컴포넌트 개발 중, input 필드를 잘 정의하고. 


<input type="text" placeholder="검색할 개수를 입력하세요." defaultValue={ this.props.number } onChange={this.changeNumber} className="form-control" ref={(c) => this.state.number = c} name="number" /></td>


event도 잘 정의했다. 

changeNumber(e) {
console.log(e)
this.setState({
number: e.target.value
});
}



Cannot read property 'setState' of undefined 라는 에러가 발생했다!!



다음과 같이 state와 event를 바인딩을 잘 했는지 잘 살펴본다. 



constructor(props) {

    super(props);


    this.state = {

        count : 1

    };


    this.changeNumber = this.changeNumber.bind(this);

}






아. 생성자에서 event 바인딩을 놓쳤다..


아래 코드를 추가하면 된다. 

this.changeNumber = this.changeNumber.bind(this);



Posted by '김용환'
,


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 '김용환'
,