Code Monkey home page Code Monkey logo

service-fabric-java-quickstart's Introduction

page_type description languages products
sample
How to deploy your first Java application to Service Fabric using the Eclipse IDE on a Linux developer machine.
java
azure
azure-service-fabric

Service Fabric Java Quickstart

Azure Service Fabric is a distributed systems platform for deploying and managing microservices and containers.

This quickstart shows how to deploy your first Java application to Service Fabric using the Eclipse IDE on a Linux developer machine. When you're finished, you have a voting application with a Java web front end that saves voting results in a stateful back-end service in the cluster.

In this quickstart, you learn how to:

  • Use Eclipse as a tool for your Service Fabric Java applications
  • Deploy the application to your local cluster
  • Deploy the application to a cluster in Azure
  • Scale-out the application across multiple nodes

Prerequisites

To complete this quickstart:

  1. Install Service Fabric SDK & Service Fabric Command Line Interface (CLI). Service Fabric version 6.1 or higher must be used.
  2. Install Git
  3. Install Eclipse
  4. Set up Java Environment, making sure to follow the optional steps to install the Eclipse plug-in

Download the sample

In a command window, run the following command to clone the sample app repository to your local machine.

git clone https://github.com/Azure-Samples/service-fabric-java-quickstart.git

Contents

This repository contains the Voting folder which contain the Service Fabric application source code for this quickstart. The AzureCluster folder contains assets that is used as part of the more in-depth Service Fabric Java tutorial. This quickstart is a sample on how to use service remoting to communicate betweens services. The Java Getting Started repository contains a sample on how to communicate between services using HTTP protocols.

Run the application locally

  1. Start your local cluster by running the following command:

    sudo /opt/microsoft/sdk/servicefabric/common/clustersetup/devclustersetup.sh

    The startup of the local cluster takes some time. To confirm that the cluster is fully up, access the Service Fabric Explorer at http://localhost:19080. The five healthy nodes indicate the local cluster is up and running.

  2. Open Eclipse.

  3. Click File -> Open Projects from File System...

  4. Click Directory and choose the Voting directory from the service-fabric-java-quickstart folder you cloned from Github. Click Finish.

  5. You now have the Voting project in the Package Explorer for Eclipse.

  6. Right click on the project and select Publish Application... under the Service Fabric dropdown. Choose PublishProfiles/Local.json as the Target Profile and click Publish.

  7. Open your favorite web browser and access the application by accessing http://localhost:8080.

You can now add a set of voting options, and start taking votes. The application runs and stores all data in your Service Fabric cluster, without the need for a separate database.

Deploy the application to Azure

Set up your Azure Service Fabric Cluster

To deploy the application to a cluster in Azure, create your own cluster.

Party clusters are free, limited-time Service Fabric clusters hosted on Azure. They are run by the Service Fabric team where anyone can deploy applications and learn about the platform. To get access to a Party Cluster, follow the instructions.

In order to perform management operations on the secure party cluster, you can use Service Fabric Explorer, CLI, or Powershell. To use Service Fabric Explorer, you will need to download the PFX file from the Party Cluster website and import the certificate into your certificate store (Windows or Mac) or into the browser itself (Ubuntu). There is no password for the self-signed certificates from the party cluster.

To perform management operations with Powershell or CLI, you will need the PFX (Powershell) or PEM (CLI). To convert the PFX to a PEM file, please run the following command:

openssl pkcs12 -in party-cluster-1277863181-client-cert.pfx -out party-cluster-1277863181-client-cert.pem -nodes -passin pass:

For information about creating your own cluster, see Create a Service Fabric cluster on Azure.

Add certificate information to your application

Certificate thumbprint needs to be added to your application because it is using Service Fabric programming models.

  1. You will need the thumbprint of your certificate in the Voting/VotingApplication/ApplicationManiest.xml file when running on a secure cluster. Run the following command to extract the thumbprint of the certificate.

    openssl x509 -in [CERTIFICATE_FILE] -fingerprint -noout
  2. In the Voting/VotingApplication/ApplicationManiest.xml, add the following snippet under the ApplicationManifest tag. The X509FindValue should be the thumbprint from the previous step (no semicolons).

    <Certificates>
        <SecretsCertificate X509FindType="FindByThumbprint" X509FindValue="0A00AA0AAAA0AAA00A000000A0AA00A0AAAA00" />
    </Certificates>   

Deploy the application using Eclipse

Now that the application and your cluster are ready, you can deploy it to the cluster directly from Eclipse.

  1. Import the project into eclipse by following the steps mentioned below:

    • Import the project using "Import Projects form File System or Archive" wizard.
    • Build the project form the Service Fabric context menu.
    • Perform "Refresh Gradle Project" from Gradle context menu.
    • Configure your workspace/project ignore Forbidden reference errors.
  2. Open the Cloud.json file under the PublishProfiles directory and fill in the ConnectionIPOrURL and ConnectionPort fields appropriately. An example is provided:

    {
         "ClusterConnectionParameters": 
         {
            "ConnectionIPOrURL": "lnxxug0tlqm5.westus.cloudapp.azure.com",
            "ConnectionPort": "19080",
            "ClientKey": "[path_to_your_pem_file_on_local_machine]",
            "ClientCert": "[path_to_your_pem_file_on_local_machine]"
         }
    }
  3. Right click on the project and select Publish Application... under the Service Fabric dropdown. Choose PublishProfiles/Cloud.json as the Target Profile and click Publish.

  4. Open your favorite web browser and access the application by accessing http://<ConnectionIPOrURL>:8080.

Scale applications and services in a cluster

Services can be scaled across a cluster to accommodate for a change in the load on the services. You scale a service by changing the number of instances running in the cluster. You have multiple ways of scaling your services, you can use scripts or commands from Service Fabric CLI (sfctl). In this example,we are using Service Fabric Explorer.

Service Fabric Explorer runs in all Service Fabric clusters and can be accessed from a browser, by browsing to the clusters HTTP management port (19080), for example, http://lnxxug0tlqm5.westus.cloudapp.azure.com:19080.

To scale the web front-end service, do the following steps:

  1. Open Service Fabric Explorer in your cluster - for example, https://lnxxug0tlqm5.westus.cloudapp.azure.com:19080.

  2. Click on the ellipsis (three dots) next to the fabric:/Voting/VotingWeb node in the treeview and choose Scale Service.

    You can now choose to scale the number of instances of the web front-end service.

  3. Change the number to 2 and click Scale Service.

  4. Click on the fabric:/Voting/VotingWeb node in the tree-view and expand the partition node (represented by a GUID).

    You can now see that the service has two instances, and in the tree view you see which nodes the instances run on.

By this simple management task, we doubled the resources available for our front-end service to process user load. It's important to understand that you do not need multiple instances of a service to have it run reliably. If a service fails, Service Fabric makes sure a new service instance runs in the cluster.

Next steps

In this quickstart, you learned how to:

  • Use Eclipse as a tool for your Service Fabric Java applications
  • Deploy Java applications to your local cluster
  • Deploy Java applications to a cluster in Azure
  • Scale-out the application across multiple nodes

service-fabric-java-quickstart's People

Contributors

erikadoyle avatar rapatchi avatar suhuruli avatar supernova-eng avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

service-fabric-java-quickstart's Issues

While running this code in Eclipse+Windows not workign

HI, I am using eclipse and windows Os. i clone this project and trying to run in my local SF cluster and its gives me below error. even my gradle is installled and configured properly.

Running command:gradle -b build.gradle jar copyDeps
java.io.IOException: Cannot run program "gradle": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at customplugin.utility.DeploymentUtility.executeCommand(DeploymentUtility.java:69)
at customplugin.utility.DeploymentUtility.build(DeploymentUtility.java:190)
at customplugin.utility.DeploymentUtility.build(DeploymentUtility.java:153)
at servicefabric.commands.worker.BuildWorker.runWorker(BuildWorker.java:26)
at servicefabric.commands.worker.WorkerThread.run(WorkerThread.java:27)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 10 more
java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:398)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:471)
at customplugin.utility.DeploymentUtility.invokeWorkerThread(DeploymentUtility.java:370)
at servicefabric.commands.handler.BuildHandler.execute(BuildHandler.java:27)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:291)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:93)
at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:318)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:252)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:161)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:494)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:487)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:204)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:433)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem.handleWidgetSelection(AbstractContributionItem.java:446)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem.lambda$2(AbstractContributionItem.java:472)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4118)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3931)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3534)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1170)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1059)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:667)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:597)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:592)
at org.eclipse.equinox.launcher.Main.run(Main.java:1498)
Caused by: java.lang.NullPointerException
at customplugin.utility.DeploymentUtility.build(DeploymentUtility.java:191)
at customplugin.utility.DeploymentUtility.build(DeploymentUtility.java:153)
at servicefabric.commands.worker.BuildWorker.runWorker(BuildWorker.java:26)
at servicefabric.commands.worker.WorkerThread.run(WorkerThread.java:27)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)

Azure Party Clusters Were Discontinued

The documentation at https://github.com/Azure-Samples/service-fabric-java-quickstart

says:
Party clusters are free, limited-time Service Fabric clusters hosted on Azure. They are run by the Service Fabric team where anyone can deploy applications and learn about the platform. To get access to a Party Cluster, follow the instructions.

See Discontinuing Party Clusters
https://techcommunity.microsoft.com/t5/azure-service-fabric/discontinuing-party-clusters/ba-p/792040

[Action Needed] This repo is inactive

This GitHub repository has been identified as a candidate for archival

This repository has had no activity in more than [x amount of time]. Long periods of inactivity present security and code hygiene risks. Archiving will not prevent users from viewing or forking the code. A banner will appear on the repository alerting users that the repository is archived.

Please see https://aka.ms/sunsetting-faq to learn more about this process.

Action

✍️

❗**If this repository is still actively maintained, please simply close this issue. Closing an issue on a repository is considered activity and the repository will not be archived.🔒

If you take no action, this repository is still inactive 30 days from today it will be automatically archived..

Need more help? 🖐️

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.