2013년 10월 13일 일요일

AssertionError: write() argument must be string | 구글 앱 엔진

파이선으로 구글 앱 엔진 예제를 동작 시키던 중
위와 같은 에러가 생기면서 동작이 안되었다.

많은 내용들을 보니 유니코드로 바꾸면 된다는 결론
하지만 유니코드로 바꿀 때 안되는 부분이 있었다.
self.response.out.write(content.encode('utf-8'))
이 부분은 제대로 동작하지 않는듯 하다.
self.response.out.write(unicode(template.render('main.html', {})))
다시 찾다보니 위와 같이 바꾸니까 된다.

출처:
1. 동작안했던 유니코드 변환 부분
http://stackoverflow.com/questions/8558323/error-in-deployed-gae-requesthandler-using-webapp2
2. 동작하는 유니코드 변환부분
http://chrislee.kr/wp/tag/wsgirefhandlers-py-assertionerror-write-argument-must-be-string-python/

2013년 9월 25일 수요일

Android - display | getWidth(), getHeight()

Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
윈도우 매니저의 getDefaultDisplay() 메소드를 통해 Display 객체를 얻은 후 이 객체의 getWidth(), getHeight() 함수를 사용해 현재 화면의 가로, 세로 해상도를 추출한 코드이다.
하지만 이 코드들은 deprecated 되었다.

다른 방법을 찾아서 노트로 남겨 놓는다.
Point pOutSize = new Point();
getWindowManager().getDefaultDisplay().getSize(pOutSize);
int width = pOutSize.x;
int height = pOutSize.y;

EditText et1 = (EditText)findViewById(R.id.et1);
et1.setWidth(width -100);


코드 출처: 노규남, Q&A로 배우는 안드로이드 프로그래밍, WellBook, Q36(330page)
내용 출처: http://sshioi.tistory.com/125, 안드로이드 The method getWidth() from the type Display is deprecated :: 프잡 파트

2013년 8월 27일 화요일

Spring Batch | Tasklet 옵션

Copied from : http://stackoverflow.com/questions/11119036/spring-batch-how-to-limit-the-no-of-executions-of-a-chunk

<batch:step id="mig-chain-data">
<batch:tasklet allow-start-if-complete="false" start-limit="1">
<batch:chunk commit-interval="1" reader="reader" writer="writer"></batch:chunk>
</batch:tasklet>
</batch:step>


 start-limit controls the number of times a Step may be started, not the chunk configured for this step.

From : http://www.codeproject.com/Articles/445856/Getting-Started-With-Spring-Batch-Part-Two

commit-interval 은 한번에 수행할 청크의 갯수를 지정 (processes 'N'  chunk at a time as indicated by the commit-interval)

Copied from : http://springsource.tistory.com/93
Tasklet
Tasklet 은 Step 내부의 트랜잭션 또는 반복될 수 있는 처리작업을 의미한다. 개발자들은 Tasklet 인터페이스를 직접 구현해서 사용하거나 스프링 배치가 제공하는 구현체를 사용할 수도 있다. 압축파일을 해제한다거나 특정 디렉토리를 정리하는 등의 특정 작업에는 직접 구현한 Tasklet 이 유용하다. 스프링 배치는 시스템 명령을 호출한다거나 chunk 기반(chunk-oriented) 처리를 수행할 수 있도록 좀더 일반화된 Tasklet 구현체를 제공한다. 
tasklet 엘리먼트가 제공하는 어트리뷰트는 다음과 같다.
ref : Tasklet 인터페이스를 구현한 스프링 빈의 id 를 의미한다. 커스텀 tasklet 을 사용하려면 이 어트리뷰트를 설정해 줘야 한다.
transaction-manager : Tasklet 에서 트랜젝션처리 시에 사용할 스프링 트랜젝션 매니저를 설정한다. tasklet 에서는 기본적으로 트랜잭션 처리가 가능하다. 디폴트 값은 transactionManager 이다.
allow-start-if-complete : Tasklet 의 실행이 성공했을 경우라도 스프링 배치가 이 Tasklet 을 재실행 가능한지 여부를 설정한다.

Reference : http://www.pfl-cepia.inra.fr/uploads/gdp_docs/spring-batch-2.0.pdf

Hadoop mode - 하둡 모드, 각 요소 노트

하둡은 Stand alone, Pseudo-distributed, Fully-distributed 총 3가지 모드로 설치할 수 있다.
(설치 후 설정 파일을 어떻게 설정하냐에 따라서)

Stand alone mode와 Pseudo-distributed mode의 공통점은 하나의 머신에서 실행된다는 것이다.
하지만 stand alone 모드는 tasktacker와 namenode, datanode, jobtracker 모두 하나의 JVM에서 실행된다는 것이 다르다. (Pseudo-distributed mode는 각각의 JVM에서 실행된다)
그래서 stand alone 모드에서는 데이터의 직렬화가 크게 중요한 문제는 아니다. 하지만 가상 분산 모드에서는 맵퍼와 리듀서간에 직렬화된 데이터를 주고 받으므로 직렬화가 중요하다.
(그렇다는 내용을 StackOverflow에서 봤었다)

하둡은 마스터와 슬레이브 구조로 이루어져 있는데
마스터는 Namenode, Jobtracker (추가적으로 SecondaryNamenode) 로 이루어져 있고
슬레이브는 Datanode, Tasktracker로 이루어져 있다.
마스터/슬레이브의 설정, Namenode, Datanode 설정 Job/Task tracker 설정 등 모두 하둡의 conf 폴더에서 직접 설정 해 줄 수 있다.



각 요소들의 기능
Copy From : http://amalgjose.wordpress.com/2012/12/08/making-a-pseudo-distributed-hadoop-cluster/
NameNodes
Name node is the master server of the cluster. It  doesnot store any file but knows where the blocks are stored in the child nodes and can give pointers and can re-assemble .Namenodes  comes up with  two  features  say Fsimage  and the edit log.FSImage   and edit log
Features
  1. Highly memory intensive
  2. Keeping it safe and isolated is necessary
  3. Manages the file system namespaces
DataNodes
Child nodes are attached to the main node.
Features:
  1. Data node  has  a configuration file to make itself  available in the cluster .Again they stores  data regarding storage capacity(Ex:5 out f 10 is available) of   that  particular data  node.
  2. Data nodes are independent ,since they are not pointing to any other data nodes.
  3. Manages the storage  attached to the  node.
  4. There  will be  multiple data nodes  in a cluster.
Job Tracker
  1. Schedules and assign task to the different datanodes.
  2. Work Flow
  3. Takes  the request.
  4. Assign the  task.
  5. Validate the requested work.
  6. Checks  whether  all the  data nodes  are working properly.
  7. If not, reschedule the tasks.
Task Tracker
Job Tracker and  task tracker   works   in  a master slave model. Every  datanode has got a  task tracker which  actually performs  the  task  which ever  assigned to it by the Job tracker.
Secondary Name Node
Secondaryname node  is not  a redundant  namenode but  this actually  provides  the  check pointing  and  housekeeping tasks  periodically.

2013년 8월 26일 월요일

사진-링크|하둡 맵리듀스의 전반적인 과정 설명

하둡의 맵리듀스 과정에 대한 설명을 보기 좋게 정리한 내용이 있어서
나중에 참고하고자 담아왔다.

Please refer the following url

Original: http://grepalex.com/2012/09/24/map-partition-sort-spill/
http://develop.sunshiny.co.kr/897
 

Spring EL 사용하기

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<util:properties id="mySettings" location="classpath:my.properties"/>
<context:component-scan base-package="com.my.classes" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="#{mySettings['jdbc.driver']}" />
<property name="url" value="#{mySettings['jdbc.url']}" />
<property name="username" value="#{mySettings['jdbc.user']}" />
<property name="password" value="#{mySettings['jdbc.password']}" />

</bean>
</beans>

자바에서 Spring EL을 사용해서 Annotation으로 기본 변수 값을 지정하려 하니 null 값이 반환되서 원인을 찾다보니 내가 사용할 클래스의 패키지를 스프링이 알게 해야 한다는것을 알았다.
진하게 표시된 부분을 통해서 Annotation을 찾을 수 있도록 해줬다.
java에서 사용 
  1. @Value("#{db['db.driverclassname']}")  
  2. private String defaultString;  


jsp 에서 사용 
  1. <spring:eval expression="@db['db.username']" />  


출처: http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/expressions.html
http://stackoverflow.com/questions/12977484/null-pointer-when-calling-pre-instantiated-bean-from-spring-container-with-jsf
http://devkkaok.tistory.com/90
http://whiteship.tistory.com/2201
http://tazz009.tistory.com/507

2013년 8월 25일 일요일

fieldSetMapper 사용 - 스프링 배치

플랫 파일을 읽고 쓸 때 자신이 만든 클래스에 매핑시켜 읽어 들이면 편하다.
이떄 BeanWrapperFieldSetMapper를 사용하면 편리하다.

<bean id="myDataReader"
  class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
  <property name="resource" value="file:/home/output/data/#{jobParameters['myfolder']}.txt"/>
  <property name="lineMapper">
  <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer">
<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="names" value="number,dataTime,data1,data2,data3"/>
<property name="delimiter">
<util:constant static-field="org.springframework.batch.item.file.transform.DelimitedLineTokenizer.DELIMITER_TAB"/>
<!-- 탭으로 구분 -->
</property>
</bean>
</property>
<property name="fieldSetMapper">
<bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
<property name="targetType"
value="com.my.data.myDao"/>
    <!-- myDao는 파란색글씨와 똑같은 이름의 변수들을 갖고 있고 setter와 getter도 갖고있다-->
    <!-- filedSetMapper를 만들어서 사용해도 관계없다 -->
    <!--bean class="com.my.data.ReportFieldSetMapper" /-->
</bean>
</property>
  </bean>
  </property>
  </bean>
  <bean id="myDataWriter"
  class="org.springframework.batch.item.database.JdbcBatchItemWriter" scope="step">
  <property name="assertUpdates" value="true"/>
  <property name="dataSource" ref="dataSource"/>
  <property name="itemSqlParameterSourceProvider">
<bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
</property>
  <property name="sql"
  value="INSERT INTO MY_DATA_TB (MY_ID,DATA_TM,DATA_1,DATA_2,DATA_3)
  VALUES (:number,:dataTime,:data1,:data2,:data3)">
  </property>
  </bean>



참조 :http://blog.naver.com/yesql?Redirect=Log&logNo=70173668117
http://static.springsource.org/spring-batch/reference/html/readersAndWriters.html