소프트웨어 개발/Scala - Functional

Spark 개발세팅 환경 연구 - SBT 외 스켈레톤 프로젝트 생성 및 의존성 추가

늘근이 2017. 1. 10. 23:34

Spark를 개발하기 위해서는 내동 Spark-Shell을 켜놓고 콘솔작업만을 할수는 없다. 혹자는, 스파크는 쉘을 통해, 그리고 같은 코드를 바로 스칼라로 개발하면서 시제품과 실제 프로덕션 레벨과의 차이가 좁아진다고는 하지만 어쨌든간에 제대로된 개발 환경을 구동시키는 것은 쉬운일은 아닌것으로 보인다. 

일단은 장인은 도구탓을 하지 않는다지만, 본인은 장인이라기 보다는 생선에 가깝기 때문에 아래의 사이트를 참조해서,

http://spark.apache.org/developer-tools.html

intelliJ에 스칼라 플러그인을 깔고, 그 후일을 도모한다. 설명에 따르면 아래와 같다.

  • Download IntelliJ and install the Scala plug-in for IntelliJ.
  • Go to File -> Import Project, locate the spark source directory, and select “Maven Project”.
  • In the Import wizard, it’s fine to leave settings at their default. However it is usually useful to enable “Import Maven projects automatically”, since changes to the project structure will automatically update the IntelliJ project.
  • As documented in Building Spark, some build configurations require specific profiles to be enabled. The same profiles that are enabled with -P[profile name] above may be enabled on the Profiles screen in the Import wizard. For example, if developing for Hadoop 2.4 with YARN support, enable profiles yarn and hadoop-2.4. These selections can be changed later by accessing the “Maven Projects” tool window from the View menu, and expanding the Profiles section.

스칼라 플러그인은 쉽게 링크로 깔 수 있고, 실제로 다른것들은 쉽게 구할수가있다. 


1) SBT설치

Maven과 같은 빌드툴인데, 스칼라에서 주로 쓰이는 빌드 툴로써, Simple Build Tool이라는 이름을 가지고있다. 다만, 아무리 간단해도 뭔가 적긴 적어야 빌드가 된다.

http://dl.bintray.com/sbt/native-packages/sbt/0.13.2/sbt-0.13.2.zip

에서 다운로드 받는데, 다시한번 최신버전인지는 확인한다.

맥인경우는 homebrew에서도 깔수있다.

$ brew install sbt

맥주모양이 날 자극해서 자몽맥주를 먹고왔다.

sbt는 다음과같은 디렉터리 구조를 가지고있다. 


 

src/
  main/
    resources/
       <files to include in main jar here>
    scala/
       <main Scala sources>
    java/
       <main Java sources>
  test/
    resources
       <files to include in test jar here>
    scala/
       <test Scala sources>
    java/
       <test Java sources>



다만 참조사이트 2에서는 다음과 같은 스켈레톤 공장을 두개를 깔아주길 원하는데, 이미 철이 지났음에도 불구하고 일단은 하란대로 한번 깔아본다. 

conscript - http://www.foundweekends.org/conscript/

giter8 - https://github.com/foundweekends/giter8

깔아봤는데 별거 없다. 그냥 간단한 프로젝트를 깃허브등에서부터 만들어즌다.

basic.zip

다만, sbt 사이트에서도 공식적으로 g8을 쓰고있으니, 깔아둔다. 몇가지 프로젝트에 대한 설문조사 후 그에 관한 정보를 가지고 스파토이를 하나 만들어준다.

http://www.scala-sbt.org/0.13/docs/sbt-new-and-Templates.html

sbt안에서는 tasks, run, console등을 사용가능하다.

의존성등은 build.sbt 나 프로젝트 안에 build.scala 에서 작성할수있다.

이제 인텔리제이에서 SBT로 작성된 프로젝트 폴더를 열면 ( 임포트, 다운로드 소스 옵션 체크 ) 알아서 인식하고 굴러간다. 

sbt안의 의존성 설정에는 다음과 같이 라이브러리들이 예쁘게 정리가 되어있다. 여기에 spark관련 의존성을 추가해주면 알아서 인텔리제이는 우리를 위해 세팅을 해줄것이며, 잘 안돌아가면 sbt로 가서 compile하면된다. 아래와 같은 식으로 하면 되는데, 밑에껀 잘 안돌아갈수 있는데, 스칼라 버전을 잘 살펴본다. 2.11.7에서는 돌아가는것을 확인했다.

libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core_2.10" % "1.0.0"
)

위와같이 자동완성을 확인할수 있으면 성공이다.


참고사이트

1) SBT설치가이드 http://www.scala-sbt.org/0.13.2/docs/Getting-Started/Setup.html

2) 환경가이드 https://constructiveproof.com/blog/2014/05/a-basic-scala-application-development-setup/

참조프로그램.

conscript - http://www.foundweekends.org/conscript/

giter8 - https://github.com/foundweekends/giter8