repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
twak/campskeleton
src/org/twak/camp/ui/Marker.java
// Path: src/org/twak/camp/Tag.java // public class Tag // { // static Rainbow rainbow; // public Color color; // public String name; // String colorName; // // public Tag() // { // this ("unnamed"); // } // // public Tag (String name) // { // color = Rainbow.next( Tag.class ); // colorName = Rainbow.lastAsString( Tag.class ); // this.name = name; // } // // public static Comparator<Tag> nameComparator = new Comparator<Tag> () // { // public int compare( Tag o1, Tag o2 ) // { // return String.CASE_INSENSITIVE_ORDER.compare(o1.name, o2.name); // } // }; // // @Override // public String toString() // { // return name +"("+colorName+")"; // } // }
import java.util.HashMap; import java.util.Map; import javax.vecmath.Point2d; import org.twak.camp.Tag;
package org.twak.camp.ui; /** * marks the locatino of a feature on a Bar * @author twak */ public class Marker extends Point2d { @Deprecated
// Path: src/org/twak/camp/Tag.java // public class Tag // { // static Rainbow rainbow; // public Color color; // public String name; // String colorName; // // public Tag() // { // this ("unnamed"); // } // // public Tag (String name) // { // color = Rainbow.next( Tag.class ); // colorName = Rainbow.lastAsString( Tag.class ); // this.name = name; // } // // public static Comparator<Tag> nameComparator = new Comparator<Tag> () // { // public int compare( Tag o1, Tag o2 ) // { // return String.CASE_INSENSITIVE_ORDER.compare(o1.name, o2.name); // } // }; // // @Override // public String toString() // { // return name +"("+colorName+")"; // } // } // Path: src/org/twak/camp/ui/Marker.java import java.util.HashMap; import java.util.Map; import javax.vecmath.Point2d; import org.twak.camp.Tag; package org.twak.camp.ui; /** * marks the locatino of a feature on a Bar * @author twak */ public class Marker extends Point2d { @Deprecated
public Tag feature;
twak/campskeleton
src/org/twak/camp/Machine.java
// Path: src/org/twak/camp/ui/DirectionHeightEvent.java // public class DirectionHeightEvent implements HeightEvent // { // protected double height; // // newAngle is the angle that this edge will turn towards at the above height // // length is the distance until the next event (only used for horizontal directions) // public double newAngle; // Machine machine; // public Set<Tag> profileFeatures = new HashSet(); // // public DirectionHeightEvent( Machine machine, double angle ) // { // this( machine, 0, angle ); // } // // public double getAngle() // { // return newAngle; // } // // public DirectionHeightEvent( Machine machine, double height, double angle ) // { // super(); // this.machine = machine; // this.height = height; // this.newAngle = angle; // } // // public double getHeight() // { // return height; // } // // public boolean process( Skeleton skel ) // { // // System.out.println("machine "+machine.toString()+" at "+height+" setting angle "+newAngle ); // // // set the new angle // machine.currentAngle = newAngle; // // SkeletonCapUpdate update = new SkeletonCapUpdate(skel); // // // add in the output edges for the outgoing face: // LoopL<Corner> cap = update.getCap(height); // DebugDevice.dump( "cap", cap ); // // CornerClone cc = new CornerClone(cap); // // // preserve corner information for assigning parents, later // DHash<Corner,Corner> nOCorner = cc.nOCorner.shallowDupe(); // // for ( Corner c : cc.output.eIterator() ) // { // // corners are untouched if neither attached edge has this machine // if ( c.nextL.machine == machine || c.prevL.machine == machine ) // nOCorner.removeA( c ); // // // segments are untouched if they don't contain this machine // if ( c.nextL.machine == machine ) // { // // copy over profile features // // yes, it looks like we add features to an edge we later disable, but it is still referenced in the entire loop and gets used for edge properties. // c.nextL.profileFeatures = profileFeatures; // // cc.nOSegments.removeA( c ); // } // } // // update.update( cc.output, cc.nOSegments, nOCorner); // // /** // * Must now update the parent field in output for the new edges, so that // * we know where a face came from // */ // for ( Corner c : skel.liveCorners ) // { // if ( c.nextL.machine == machine ) // { // Corner old = update.getOldBaseLookup().get( cc.nOCorner.get( c )); // skel.output.setParent (c.nextL.start, old.nextL.start); // } // } // // DebugDevice.dump( "post height "+height, skel); // // machine.findNextHeight( skel ); // return true; // } // }
import java.awt.Color; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import org.twak.camp.ui.DirectionHeightEvent;
package org.twak.camp; /** * A machine controls the angle of it's set of edges over time (height...) * * superclass of all machines * * idea is to add all directions before adding edges. When you add the first edge * * instead of just adding all height changes to the main event queue, this * machine only adds the next one. Reason here is that we might want to change * our minds as we build upwards. * * @author twak */ public class Machine { public Color color; // color used in the ui // a machine will only ever have one pending event in the skeleton.qu, others are stored here public List<HeightEvent> events = new ArrayList(); String description = "unnamed machine"; public double currentAngle = Math.PI/4; // when a edge is added this is the angle it is given public transient HeightEvent heightEvent; public transient int currentDirection = -1; protected Set<Edge> seenEdges = new LinkedHashSet(); // for pretty output static Color[] rainbow = new Color[] { Color.red, Color.green, Color.blue, Color.magenta }; static String[] rainbowStrings = new String[] {"red", "green", "blue", "magenta" }; static int rainbowIndex = 0; public Machine() { this (Math.PI/4); } public Machine( double initial ) { color = rainbow[ rainbowIndex % rainbowStrings.length ]; description = rainbowStrings[ rainbowIndex % rainbowStrings.length ]; rainbowIndex++;
// Path: src/org/twak/camp/ui/DirectionHeightEvent.java // public class DirectionHeightEvent implements HeightEvent // { // protected double height; // // newAngle is the angle that this edge will turn towards at the above height // // length is the distance until the next event (only used for horizontal directions) // public double newAngle; // Machine machine; // public Set<Tag> profileFeatures = new HashSet(); // // public DirectionHeightEvent( Machine machine, double angle ) // { // this( machine, 0, angle ); // } // // public double getAngle() // { // return newAngle; // } // // public DirectionHeightEvent( Machine machine, double height, double angle ) // { // super(); // this.machine = machine; // this.height = height; // this.newAngle = angle; // } // // public double getHeight() // { // return height; // } // // public boolean process( Skeleton skel ) // { // // System.out.println("machine "+machine.toString()+" at "+height+" setting angle "+newAngle ); // // // set the new angle // machine.currentAngle = newAngle; // // SkeletonCapUpdate update = new SkeletonCapUpdate(skel); // // // add in the output edges for the outgoing face: // LoopL<Corner> cap = update.getCap(height); // DebugDevice.dump( "cap", cap ); // // CornerClone cc = new CornerClone(cap); // // // preserve corner information for assigning parents, later // DHash<Corner,Corner> nOCorner = cc.nOCorner.shallowDupe(); // // for ( Corner c : cc.output.eIterator() ) // { // // corners are untouched if neither attached edge has this machine // if ( c.nextL.machine == machine || c.prevL.machine == machine ) // nOCorner.removeA( c ); // // // segments are untouched if they don't contain this machine // if ( c.nextL.machine == machine ) // { // // copy over profile features // // yes, it looks like we add features to an edge we later disable, but it is still referenced in the entire loop and gets used for edge properties. // c.nextL.profileFeatures = profileFeatures; // // cc.nOSegments.removeA( c ); // } // } // // update.update( cc.output, cc.nOSegments, nOCorner); // // /** // * Must now update the parent field in output for the new edges, so that // * we know where a face came from // */ // for ( Corner c : skel.liveCorners ) // { // if ( c.nextL.machine == machine ) // { // Corner old = update.getOldBaseLookup().get( cc.nOCorner.get( c )); // skel.output.setParent (c.nextL.start, old.nextL.start); // } // } // // DebugDevice.dump( "post height "+height, skel); // // machine.findNextHeight( skel ); // return true; // } // } // Path: src/org/twak/camp/Machine.java import java.awt.Color; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import org.twak.camp.ui.DirectionHeightEvent; package org.twak.camp; /** * A machine controls the angle of it's set of edges over time (height...) * * superclass of all machines * * idea is to add all directions before adding edges. When you add the first edge * * instead of just adding all height changes to the main event queue, this * machine only adds the next one. Reason here is that we might want to change * our minds as we build upwards. * * @author twak */ public class Machine { public Color color; // color used in the ui // a machine will only ever have one pending event in the skeleton.qu, others are stored here public List<HeightEvent> events = new ArrayList(); String description = "unnamed machine"; public double currentAngle = Math.PI/4; // when a edge is added this is the angle it is given public transient HeightEvent heightEvent; public transient int currentDirection = -1; protected Set<Edge> seenEdges = new LinkedHashSet(); // for pretty output static Color[] rainbow = new Color[] { Color.red, Color.green, Color.blue, Color.magenta }; static String[] rainbowStrings = new String[] {"red", "green", "blue", "magenta" }; static int rainbowIndex = 0; public Machine() { this (Math.PI/4); } public Machine( double initial ) { color = rainbow[ rainbowIndex % rainbowStrings.length ]; description = rainbowStrings[ rainbowIndex % rainbowStrings.length ]; rainbowIndex++;
addHeightEvent( new DirectionHeightEvent( this, initial ) );
twak/campskeleton
src/org/twak/camp/SkeletonCapUpdate.java
// Path: src/org/twak/camp/debug/DebugDevice.java // public class DebugDevice // { // // global debug switch // public static boolean debug; // change in reset(), below // public static DebugDevice instance = new DebugDevice(); // // public static void reset() { // debug = false; // instance.toDisplay.clear(); // instance.push(); // } // // static class Status // { // LoopL<Corner> corners; // Output output; // String name; // public Status (String name, LoopL<Corner> corners, Output output) // { // this.name = name; // this.corners = corners; // // // for (Corner c: corners.eIterator()) { // // c.x += Math.random() * 1 - 0.5; // // c.y += Math.random() * 1 - 0.5; // // } // // this.output = output; // } // // @Override // public String toString() { // return name; // } // } // // List<Status> toDisplay = new ArrayList(); // JFrame window = null; // private JDebugDevice jDD; // // public static void dump ( String name, Skeleton skel ) // { // if (!debug) // return; // // instance.toDisplay.add(new Status ( skel.name+":"+name, Corner.dupeNewAll(skel.findLoopLive()), skel.output.dupeEdgesOnly() )); // push(); // } // // public static void dump ( String name, LoopL<Corner> corners ) // { // if (!debug) // return; // // instance.toDisplay.add(new Status ( name, Corner.dupeNewAll(corners), null )); // push(); // } // // public static void dumpPoints ( String name, LoopL<Point3d> points ) // { // if (!debug) // return; // // LoopL<Corner> loopl = new LoopL(); // // Cache<Point3d, Corner> cCache = new Cache<Point3d, Corner>() // { // @Override // public Corner create( Point3d i ) // { // return new Corner( i.x, i.y, i.y ); // } // }; // // for ( Loop<Point3d> lc : points ) // { // Loop<Corner> loop = new Loop(); // loopl.add( loop ); // for ( Loopable<Point3d> loopable : lc.loopableIterator() ) // { // Corner me = cCache.get( loopable.get()); // Corner yu = cCache.get( loopable.get()); // loop.append( me ); // me.nextC = yu; // yu.prevC = me; // me.nextL = new Edge (me, yu); // yu.prevL = me.nextL; // } // } // // instance.toDisplay.add(new Status ( name, loopl, null )); // push(); // } // // // public static void push() // { // if (!debug) // return; // instance.push_(); // } // // private void push_() // { // SwingUtilities.invokeLater(new Runnable() { // // public void run() { // if (window == null) { // window = new JFrame(this.getClass().getSimpleName()); // window.setSize(800, 800); // window.setVisible(true); // window.setContentPane(jDD = new JDebugDevice(DebugDevice.this)); // // window.addWindowListener(new WindowAdapter() { // // @Override // public void windowClosing(WindowEvent e) { // DebugDevice.instance.window = null; // } // }); // // } // jDD.pingChanged(); // } // }); // } // }
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import org.twak.camp.debug.DebugDevice; import org.twak.utils.collections.DHash; import org.twak.utils.collections.LoopL; import org.twak.utils.collections.SetCorrespondence; import org.twak.utils.geom.Ray3d;
if (trailing != null) // polarity needs fixing up? first section sometimes capped, sometimes not. { // because the cap (base) is at height 0, we elevate it here. skel.output.addOutputSideTo( true, trailing.corner, s.corner, baseE ); trailing = null; // every other segment } else trailing = s; // every other segment } } /** * Pointers may have been removed by previous/next edges, or some edges may have been removed entirely */ // this is broken - where do we remove other corners that might reference htis edge? Iterator<Edge> eit = skel.liveEdges.iterator(); while ( eit.hasNext() ) { Edge e = eit.next(); if ( e.currentCorners.size() == 0 ) { eit.remove(); skel.liveCorners.remove( e.start ); skel.liveCorners.remove( e.end ); } } skel.refindAllFaceEventsLater();
// Path: src/org/twak/camp/debug/DebugDevice.java // public class DebugDevice // { // // global debug switch // public static boolean debug; // change in reset(), below // public static DebugDevice instance = new DebugDevice(); // // public static void reset() { // debug = false; // instance.toDisplay.clear(); // instance.push(); // } // // static class Status // { // LoopL<Corner> corners; // Output output; // String name; // public Status (String name, LoopL<Corner> corners, Output output) // { // this.name = name; // this.corners = corners; // // // for (Corner c: corners.eIterator()) { // // c.x += Math.random() * 1 - 0.5; // // c.y += Math.random() * 1 - 0.5; // // } // // this.output = output; // } // // @Override // public String toString() { // return name; // } // } // // List<Status> toDisplay = new ArrayList(); // JFrame window = null; // private JDebugDevice jDD; // // public static void dump ( String name, Skeleton skel ) // { // if (!debug) // return; // // instance.toDisplay.add(new Status ( skel.name+":"+name, Corner.dupeNewAll(skel.findLoopLive()), skel.output.dupeEdgesOnly() )); // push(); // } // // public static void dump ( String name, LoopL<Corner> corners ) // { // if (!debug) // return; // // instance.toDisplay.add(new Status ( name, Corner.dupeNewAll(corners), null )); // push(); // } // // public static void dumpPoints ( String name, LoopL<Point3d> points ) // { // if (!debug) // return; // // LoopL<Corner> loopl = new LoopL(); // // Cache<Point3d, Corner> cCache = new Cache<Point3d, Corner>() // { // @Override // public Corner create( Point3d i ) // { // return new Corner( i.x, i.y, i.y ); // } // }; // // for ( Loop<Point3d> lc : points ) // { // Loop<Corner> loop = new Loop(); // loopl.add( loop ); // for ( Loopable<Point3d> loopable : lc.loopableIterator() ) // { // Corner me = cCache.get( loopable.get()); // Corner yu = cCache.get( loopable.get()); // loop.append( me ); // me.nextC = yu; // yu.prevC = me; // me.nextL = new Edge (me, yu); // yu.prevL = me.nextL; // } // } // // instance.toDisplay.add(new Status ( name, loopl, null )); // push(); // } // // // public static void push() // { // if (!debug) // return; // instance.push_(); // } // // private void push_() // { // SwingUtilities.invokeLater(new Runnable() { // // public void run() { // if (window == null) { // window = new JFrame(this.getClass().getSimpleName()); // window.setSize(800, 800); // window.setVisible(true); // window.setContentPane(jDD = new JDebugDevice(DebugDevice.this)); // // window.addWindowListener(new WindowAdapter() { // // @Override // public void windowClosing(WindowEvent e) { // DebugDevice.instance.window = null; // } // }); // // } // jDD.pingChanged(); // } // }); // } // } // Path: src/org/twak/camp/SkeletonCapUpdate.java import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import org.twak.camp.debug.DebugDevice; import org.twak.utils.collections.DHash; import org.twak.utils.collections.LoopL; import org.twak.utils.collections.SetCorrespondence; import org.twak.utils.geom.Ray3d; if (trailing != null) // polarity needs fixing up? first section sometimes capped, sometimes not. { // because the cap (base) is at height 0, we elevate it here. skel.output.addOutputSideTo( true, trailing.corner, s.corner, baseE ); trailing = null; // every other segment } else trailing = s; // every other segment } } /** * Pointers may have been removed by previous/next edges, or some edges may have been removed entirely */ // this is broken - where do we remove other corners that might reference htis edge? Iterator<Edge> eit = skel.liveEdges.iterator(); while ( eit.hasNext() ) { Edge e = eit.next(); if ( e.currentCorners.size() == 0 ) { eit.remove(); skel.liveCorners.remove( e.start ); skel.liveCorners.remove( e.end ); } } skel.refindAllFaceEventsLater();
DebugDevice.dump("post cap update", skel);
twak/campskeleton
src/org/twak/camp/Output.java
// Path: src/org/twak/camp/Output.java // public class Face // { // // first is outside, others are holes // public LoopL<Point3d> points = null; // // public Set<Tag> plan = new HashSet<>(), profile = new HashSet<>(); // // // bottom edges // public Set<SharedEdge> definingSE = new LinkedHashSet<>(); // // defining edges of child (top) edges // public Set<SharedEdge> topSE = new LinkedHashSet<>(); // // // face below us in the skeleton - can be traced back to an originator // public Face parent; // // public GraphMap<Point3d> results = new GraphMap<>(); // // // a typical edge that defines the plane normal // public Edge edge; // // // subset of results who are horizontal edges and whose nextL are edge, or similar. // public Set<Corner> definingCorners = new LinkedHashSet<>(); // // public LoopL<SharedEdge> edges = new LoopL<>(); // // public LoopL<Point3d> getLoopL() // { // return points; // } // // public int pointCount() // { // return points.count(); // } // // is a defining edges of the above (child) edges // public boolean isTop (SharedEdge edge) // { // return topSE.contains( edge ); // } // // is a defining edge // public boolean isBottom(SharedEdge edge) // { // return definingSE.contains( edge ); // } // // isn't a top or bottom edges // public boolean isSide (SharedEdge edge) // { // return !( isTop( edge ) || isBottom( edge ) ); // } // // /** // * When caculating an offset, we can assume that all edges add a face at every interval // * this returns the number of faces below this face. // * @return // */ // public int getParentCount() // { // int count = -1; // Face f = this; // while (f != null) // { // count++; // f = f.parent; // } // return count; // } // // private void findSharedEdges() // { // edges = new LoopL<>(); // for (Loop <Point3d> ptLoop : points) // { // Loop<SharedEdge> loop = new Loop<>(); // edges.add (loop); // // start and end points of SharedEdges **aren't** shared // for (Loopable<Point3d> loopable : ptLoop.loopableIterator()) // { // SharedEdge e = createEdge( loopable.get(), loopable.getNext().get() ); // // e.setLeft (loopable.get(), loop.append( e ), this ); // } // } // } // }
import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.vecmath.Point3d; import javax.vecmath.Tuple3d; import javax.vecmath.Vector3d; import org.twak.camp.Output.Face; import org.twak.utils.Cache; import org.twak.utils.IdentityLookup; import org.twak.utils.Triple; import org.twak.utils.collections.ConsecutiveTriples; import org.twak.utils.collections.Loop; import org.twak.utils.collections.LoopL; import org.twak.utils.collections.Loopable; import org.twak.utils.geom.AngleAccumulator; import org.twak.utils.geom.GraphMap;
package org.twak.camp; /** * @author twak */ public class Output { // marker for horizontal input edges (other edges can also be horizontal...) public static Tag isCreatedHorizontal = new Tag ("horizontal");
// Path: src/org/twak/camp/Output.java // public class Face // { // // first is outside, others are holes // public LoopL<Point3d> points = null; // // public Set<Tag> plan = new HashSet<>(), profile = new HashSet<>(); // // // bottom edges // public Set<SharedEdge> definingSE = new LinkedHashSet<>(); // // defining edges of child (top) edges // public Set<SharedEdge> topSE = new LinkedHashSet<>(); // // // face below us in the skeleton - can be traced back to an originator // public Face parent; // // public GraphMap<Point3d> results = new GraphMap<>(); // // // a typical edge that defines the plane normal // public Edge edge; // // // subset of results who are horizontal edges and whose nextL are edge, or similar. // public Set<Corner> definingCorners = new LinkedHashSet<>(); // // public LoopL<SharedEdge> edges = new LoopL<>(); // // public LoopL<Point3d> getLoopL() // { // return points; // } // // public int pointCount() // { // return points.count(); // } // // is a defining edges of the above (child) edges // public boolean isTop (SharedEdge edge) // { // return topSE.contains( edge ); // } // // is a defining edge // public boolean isBottom(SharedEdge edge) // { // return definingSE.contains( edge ); // } // // isn't a top or bottom edges // public boolean isSide (SharedEdge edge) // { // return !( isTop( edge ) || isBottom( edge ) ); // } // // /** // * When caculating an offset, we can assume that all edges add a face at every interval // * this returns the number of faces below this face. // * @return // */ // public int getParentCount() // { // int count = -1; // Face f = this; // while (f != null) // { // count++; // f = f.parent; // } // return count; // } // // private void findSharedEdges() // { // edges = new LoopL<>(); // for (Loop <Point3d> ptLoop : points) // { // Loop<SharedEdge> loop = new Loop<>(); // edges.add (loop); // // start and end points of SharedEdges **aren't** shared // for (Loopable<Point3d> loopable : ptLoop.loopableIterator()) // { // SharedEdge e = createEdge( loopable.get(), loopable.getNext().get() ); // // e.setLeft (loopable.get(), loop.append( e ), this ); // } // } // } // } // Path: src/org/twak/camp/Output.java import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.vecmath.Point3d; import javax.vecmath.Tuple3d; import javax.vecmath.Vector3d; import org.twak.camp.Output.Face; import org.twak.utils.Cache; import org.twak.utils.IdentityLookup; import org.twak.utils.Triple; import org.twak.utils.collections.ConsecutiveTriples; import org.twak.utils.collections.Loop; import org.twak.utils.collections.LoopL; import org.twak.utils.collections.Loopable; import org.twak.utils.geom.AngleAccumulator; import org.twak.utils.geom.GraphMap; package org.twak.camp; /** * @author twak */ public class Output { // marker for horizontal input edges (other edges can also be horizontal...) public static Tag isCreatedHorizontal = new Tag ("horizontal");
public Map<Corner, Face> faces = new LinkedHashMap<>(); // the faces represented by each edge
nicoulaj/checksum-maven-plugin
src/main/java/net/nicoulaj/maven/plugins/checksum/execution/AbstractExecution.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/ExecutionTarget.java // public interface ExecutionTarget // { // /** // * Initialize the target. // * // * <p>Should be called before first call to {@link #write(String, ChecksumFile, String)}.</p> // * // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetInitializationException // * if an error occured while initializing the target. // */ // void init() // throws ExecutionTargetInitializationException; // // /** // * Write the hashcode calculated for the given file and algorithm to the target. // * // * @param digest the digest to write. // * @param file the file for which the digest was calculated. // * @param algorithm the algorithm used to calculate the digest. // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetWriteException if an error occured while writing to the target. // */ // void write( String digest, ChecksumFile file, String algorithm ) // throws ExecutionTargetWriteException; // // /** // * Close the target. // * // * <p>Should be called after last call to {@link #write(String, ChecksumFile, String)}.</p> // * // * @param subPath part of relative path to exclude from file path // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetCloseException if an error occured while closing the target. // */ // void close(String subPath) // throws ExecutionTargetCloseException; // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // }
import net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import java.util.LinkedList; import java.util.List;
/* * checksum-maven-plugin - http://checksum-maven-plugin.nicoulaj.net * Copyright © 2010-2021 checksum-maven-plugin contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.nicoulaj.maven.plugins.checksum.execution; /** * Base class for {@link net.nicoulaj.maven.plugins.checksum.execution.Execution} implementations. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @see net.nicoulaj.maven.plugins.checksum.execution.Execution * @since 1.0 * @version $Id: $Id */ public abstract class AbstractExecution implements Execution { /** * The list of files used for the execution. */
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/ExecutionTarget.java // public interface ExecutionTarget // { // /** // * Initialize the target. // * // * <p>Should be called before first call to {@link #write(String, ChecksumFile, String)}.</p> // * // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetInitializationException // * if an error occured while initializing the target. // */ // void init() // throws ExecutionTargetInitializationException; // // /** // * Write the hashcode calculated for the given file and algorithm to the target. // * // * @param digest the digest to write. // * @param file the file for which the digest was calculated. // * @param algorithm the algorithm used to calculate the digest. // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetWriteException if an error occured while writing to the target. // */ // void write( String digest, ChecksumFile file, String algorithm ) // throws ExecutionTargetWriteException; // // /** // * Close the target. // * // * <p>Should be called after last call to {@link #write(String, ChecksumFile, String)}.</p> // * // * @param subPath part of relative path to exclude from file path // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetCloseException if an error occured while closing the target. // */ // void close(String subPath) // throws ExecutionTargetCloseException; // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // } // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/AbstractExecution.java import net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import java.util.LinkedList; import java.util.List; /* * checksum-maven-plugin - http://checksum-maven-plugin.nicoulaj.net * Copyright © 2010-2021 checksum-maven-plugin contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.nicoulaj.maven.plugins.checksum.execution; /** * Base class for {@link net.nicoulaj.maven.plugins.checksum.execution.Execution} implementations. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @see net.nicoulaj.maven.plugins.checksum.execution.Execution * @since 1.0 * @version $Id: $Id */ public abstract class AbstractExecution implements Execution { /** * The list of files used for the execution. */
protected List<ChecksumFile> files;
nicoulaj/checksum-maven-plugin
src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/ExecutionTarget.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // }
import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile;
/*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} is an output target for calculated digests. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @since 1.0 * @version $Id: $Id */ public interface ExecutionTarget { /** * Initialize the target. * * <p>Should be called before first call to {@link #write(String, ChecksumFile, String)}.</p> * * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetInitializationException * if an error occured while initializing the target. */ void init() throws ExecutionTargetInitializationException; /** * Write the hashcode calculated for the given file and algorithm to the target. * * @param digest the digest to write. * @param file the file for which the digest was calculated. * @param algorithm the algorithm used to calculate the digest. * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetWriteException if an error occured while writing to the target. */
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // } // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/ExecutionTarget.java import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; /*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} is an output target for calculated digests. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @since 1.0 * @version $Id: $Id */ public interface ExecutionTarget { /** * Initialize the target. * * <p>Should be called before first call to {@link #write(String, ChecksumFile, String)}.</p> * * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetInitializationException * if an error occured while initializing the target. */ void init() throws ExecutionTargetInitializationException; /** * Write the hashcode calculated for the given file and algorithm to the target. * * @param digest the digest to write. * @param file the file for which the digest was calculated. * @param algorithm the algorithm used to calculate the digest. * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetWriteException if an error occured while writing to the target. */
void write( String digest, ChecksumFile file, String algorithm )
nicoulaj/checksum-maven-plugin
src/test/java/net/nicoulaj/maven/plugins/checksum/test/unit/digest/ChecksumFactoryTest.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/digest/DigesterFactory.java // public class DigesterFactory // { // /** // * The instance of {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory}. // */ // private static DigesterFactory instance; // // /** // * The map (algorithm, digester). // */ // protected Map<String, FileDigester> digesters = new HashMap<>( Constants.SUPPORTED_ALGORITHMS.length ); // // /** // * Build a new {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory}. // * // * @see #getInstance() // */ // private DigesterFactory() // { // } // // /** // * Get the instance of {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory}. // * // * @return the only instance of {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory}. // */ // public static synchronized DigesterFactory getInstance() // { // if ( instance == null ) // { // instance = new DigesterFactory(); // } // return instance; // } // // /** // * Get an instance of {@link net.nicoulaj.maven.plugins.checksum.digest.FileDigester} for the given checksum algorithm. // * // * @param algorithm the target checksum algorithm. // * @return an instance of {@link net.nicoulaj.maven.plugins.checksum.digest.FileDigester}. // * @throws java.security.NoSuchAlgorithmException if the checksum algorithm is not supported or invalid. // * @see FileDigester // */ // public synchronized FileDigester getFileDigester( String algorithm ) // throws NoSuchAlgorithmException // { // FileDigester digester = digesters.get( algorithm ); // // if ( digester == null ) // { // // Algorithms with custom digesters // if ( CRC32FileDigester.ALGORITHM.equals( algorithm ) ) // { // digester = new CRC32FileDigester(); // } // // else if ( CksumFileDigester.ALGORITHM.equals( algorithm ) ) // { // digester = new CksumFileDigester(); // } // // // Default case: try to use Java Security providers. // else // { // // Try with the current providers. // try // { // digester = new MessageDigestFileDigester( algorithm ); // } // catch ( NoSuchAlgorithmException e ) // { // // If the algorithm is not supported by default providers, try with Bouncy Castle. // if ( Security.getProvider( BouncyCastleProvider.PROVIDER_NAME ) == null ) // { // Security.addProvider( new BouncyCastleProvider() ); // digester = new MessageDigestFileDigester( algorithm ); // } // // // If Bouncy Castle was already used, fail. // else // { // throw e; // } // } // } // // digesters.put( algorithm, digester ); // } // // return digester; // } // }
import net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import java.security.NoSuchAlgorithmException;
/* * checksum-maven-plugin - http://checksum-maven-plugin.nicoulaj.net * Copyright © 2010-2021 checksum-maven-plugin contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.nicoulaj.maven.plugins.checksum.test.unit.digest; /** * Miscellaneous tests for the {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory} class. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @see net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory * @since 1.0 * @version $Id: $Id */ public class ChecksumFactoryTest { /** * Rule used to specify per-test expected exceptions. */ @Rule public ExpectedException exception = ExpectedException.none(); /** * Assert a {@link java.security.NoSuchAlgorithmException} is thrown when trying get the {@link * net.nicoulaj.maven.plugins.checksum.digest.FileDigester} for an unknown algorithm. * * @throws java.security.NoSuchAlgorithmException * should never happen. * @since 1.11 */ @Test public void testNoSuchAlgorithmExceptionThrownOnInvalidAlgorithm() throws NoSuchAlgorithmException { exception.expect( NoSuchAlgorithmException.class );
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/digest/DigesterFactory.java // public class DigesterFactory // { // /** // * The instance of {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory}. // */ // private static DigesterFactory instance; // // /** // * The map (algorithm, digester). // */ // protected Map<String, FileDigester> digesters = new HashMap<>( Constants.SUPPORTED_ALGORITHMS.length ); // // /** // * Build a new {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory}. // * // * @see #getInstance() // */ // private DigesterFactory() // { // } // // /** // * Get the instance of {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory}. // * // * @return the only instance of {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory}. // */ // public static synchronized DigesterFactory getInstance() // { // if ( instance == null ) // { // instance = new DigesterFactory(); // } // return instance; // } // // /** // * Get an instance of {@link net.nicoulaj.maven.plugins.checksum.digest.FileDigester} for the given checksum algorithm. // * // * @param algorithm the target checksum algorithm. // * @return an instance of {@link net.nicoulaj.maven.plugins.checksum.digest.FileDigester}. // * @throws java.security.NoSuchAlgorithmException if the checksum algorithm is not supported or invalid. // * @see FileDigester // */ // public synchronized FileDigester getFileDigester( String algorithm ) // throws NoSuchAlgorithmException // { // FileDigester digester = digesters.get( algorithm ); // // if ( digester == null ) // { // // Algorithms with custom digesters // if ( CRC32FileDigester.ALGORITHM.equals( algorithm ) ) // { // digester = new CRC32FileDigester(); // } // // else if ( CksumFileDigester.ALGORITHM.equals( algorithm ) ) // { // digester = new CksumFileDigester(); // } // // // Default case: try to use Java Security providers. // else // { // // Try with the current providers. // try // { // digester = new MessageDigestFileDigester( algorithm ); // } // catch ( NoSuchAlgorithmException e ) // { // // If the algorithm is not supported by default providers, try with Bouncy Castle. // if ( Security.getProvider( BouncyCastleProvider.PROVIDER_NAME ) == null ) // { // Security.addProvider( new BouncyCastleProvider() ); // digester = new MessageDigestFileDigester( algorithm ); // } // // // If Bouncy Castle was already used, fail. // else // { // throw e; // } // } // } // // digesters.put( algorithm, digester ); // } // // return digester; // } // } // Path: src/test/java/net/nicoulaj/maven/plugins/checksum/test/unit/digest/ChecksumFactoryTest.java import net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import java.security.NoSuchAlgorithmException; /* * checksum-maven-plugin - http://checksum-maven-plugin.nicoulaj.net * Copyright © 2010-2021 checksum-maven-plugin contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.nicoulaj.maven.plugins.checksum.test.unit.digest; /** * Miscellaneous tests for the {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory} class. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @see net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory * @since 1.0 * @version $Id: $Id */ public class ChecksumFactoryTest { /** * Rule used to specify per-test expected exceptions. */ @Rule public ExpectedException exception = ExpectedException.none(); /** * Assert a {@link java.security.NoSuchAlgorithmException} is thrown when trying get the {@link * net.nicoulaj.maven.plugins.checksum.digest.FileDigester} for an unknown algorithm. * * @throws java.security.NoSuchAlgorithmException * should never happen. * @since 1.11 */ @Test public void testNoSuchAlgorithmExceptionThrownOnInvalidAlgorithm() throws NoSuchAlgorithmException { exception.expect( NoSuchAlgorithmException.class );
DigesterFactory.getInstance().getFileDigester( "SHA-666" );
nicoulaj/checksum-maven-plugin
src/main/java/net/nicoulaj/maven/plugins/checksum/execution/Execution.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/ExecutionTarget.java // public interface ExecutionTarget // { // /** // * Initialize the target. // * // * <p>Should be called before first call to {@link #write(String, ChecksumFile, String)}.</p> // * // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetInitializationException // * if an error occured while initializing the target. // */ // void init() // throws ExecutionTargetInitializationException; // // /** // * Write the hashcode calculated for the given file and algorithm to the target. // * // * @param digest the digest to write. // * @param file the file for which the digest was calculated. // * @param algorithm the algorithm used to calculate the digest. // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetWriteException if an error occured while writing to the target. // */ // void write( String digest, ChecksumFile file, String algorithm ) // throws ExecutionTargetWriteException; // // /** // * Close the target. // * // * <p>Should be called after last call to {@link #write(String, ChecksumFile, String)}.</p> // * // * @param subPath part of relative path to exclude from file path // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetCloseException if an error occured while closing the target. // */ // void close(String subPath) // throws ExecutionTargetCloseException; // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // }
import net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import java.util.List;
/* * checksum-maven-plugin - http://checksum-maven-plugin.nicoulaj.net * Copyright © 2010-2021 checksum-maven-plugin contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.nicoulaj.maven.plugins.checksum.execution; /** * Effective execution of plugin goals used {@link org.apache.maven.plugin.Mojo} implementations. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @see net.nicoulaj.maven.plugins.checksum.mojo * @since 1.0 * @version $Id: $Id */ public interface Execution { /** * Get the list of files to be processed by the execution. * * @return the files configured for this execution. */
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/ExecutionTarget.java // public interface ExecutionTarget // { // /** // * Initialize the target. // * // * <p>Should be called before first call to {@link #write(String, ChecksumFile, String)}.</p> // * // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetInitializationException // * if an error occured while initializing the target. // */ // void init() // throws ExecutionTargetInitializationException; // // /** // * Write the hashcode calculated for the given file and algorithm to the target. // * // * @param digest the digest to write. // * @param file the file for which the digest was calculated. // * @param algorithm the algorithm used to calculate the digest. // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetWriteException if an error occured while writing to the target. // */ // void write( String digest, ChecksumFile file, String algorithm ) // throws ExecutionTargetWriteException; // // /** // * Close the target. // * // * <p>Should be called after last call to {@link #write(String, ChecksumFile, String)}.</p> // * // * @param subPath part of relative path to exclude from file path // * @throws net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTargetCloseException if an error occured while closing the target. // */ // void close(String subPath) // throws ExecutionTargetCloseException; // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // } // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/Execution.java import net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import java.util.List; /* * checksum-maven-plugin - http://checksum-maven-plugin.nicoulaj.net * Copyright © 2010-2021 checksum-maven-plugin contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.nicoulaj.maven.plugins.checksum.execution; /** * Effective execution of plugin goals used {@link org.apache.maven.plugin.Mojo} implementations. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @see net.nicoulaj.maven.plugins.checksum.mojo * @since 1.0 * @version $Id: $Id */ public interface Execution { /** * Get the list of files to be processed by the execution. * * @return the files configured for this execution. */
List<ChecksumFile> getFiles();
nicoulaj/checksum-maven-plugin
src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/MavenLogTarget.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // }
import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import org.apache.maven.plugin.logging.Log;
/*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to a Maven {@link org.apache.maven.plugin.logging.Log}. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @see org.apache.maven.plugin.logging.Log * @since 1.0 * @version $Id: $Id */ public class MavenLogTarget implements ExecutionTarget { /** * The Maven {@link org.apache.maven.plugin.logging.Log}. */ protected Log logger; /** * Build an new instance of {@link net.nicoulaj.maven.plugins.checksum.execution.target.MavenLogTarget}. * * @param logger the Maven {@link org.apache.maven.plugin.logging.Log} to use. */ public MavenLogTarget( Log logger ) { this.logger = logger; } /** * {@inheritDoc} */ public void init() { // Nothing to do } /** {@inheritDoc} */
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // } // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/MavenLogTarget.java import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import org.apache.maven.plugin.logging.Log; /*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to a Maven {@link org.apache.maven.plugin.logging.Log}. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @see org.apache.maven.plugin.logging.Log * @since 1.0 * @version $Id: $Id */ public class MavenLogTarget implements ExecutionTarget { /** * The Maven {@link org.apache.maven.plugin.logging.Log}. */ protected Log logger; /** * Build an new instance of {@link net.nicoulaj.maven.plugins.checksum.execution.target.MavenLogTarget}. * * @param logger the Maven {@link org.apache.maven.plugin.logging.Log} to use. */ public MavenLogTarget( Log logger ) { this.logger = logger; } /** * {@inheritDoc} */ public void init() { // Nothing to do } /** {@inheritDoc} */
public void write( String digest, ChecksumFile file, String algorithm )
nicoulaj/checksum-maven-plugin
src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/XmlSummaryFileTarget.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/artifacts/ArtifactListener.java // public interface ArtifactListener { // /** // * <p>artifactCreated.</p> // * // * @param artifact a {@link java.io.File} object // * @param checksumType a {@link java.lang.String} object // * @param artifactExtension a {@link java.lang.String} object // * @param artifactClassifier a {@link java.lang.String} object // */ // void artifactCreated(File artifact, String checksumType, String artifactExtension, String artifactClassifier); // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // }
import java.util.HashMap; import java.util.Map; import net.nicoulaj.maven.plugins.checksum.artifacts.ArtifactListener; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import org.apache.maven.shared.utils.StringUtils; import org.apache.maven.shared.utils.xml.PrettyPrintXMLWriter; import java.io.*; import java.nio.file.Files; import java.util.Arrays; import java.util.Comparator;
/*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to an XML file. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @since 1.0 * @version $Id: $Id */ public class XmlSummaryFileTarget implements ExecutionTarget { /** * The number of spaces used to indent the output file. */ public static final int XML_INDENTATION_SIZE = 2; /** * Encoding to use for generated files. */ protected final String encoding; /** * The association file =&gt; (algorithm,hashcode). */
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/artifacts/ArtifactListener.java // public interface ArtifactListener { // /** // * <p>artifactCreated.</p> // * // * @param artifact a {@link java.io.File} object // * @param checksumType a {@link java.lang.String} object // * @param artifactExtension a {@link java.lang.String} object // * @param artifactClassifier a {@link java.lang.String} object // */ // void artifactCreated(File artifact, String checksumType, String artifactExtension, String artifactClassifier); // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // } // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/XmlSummaryFileTarget.java import java.util.HashMap; import java.util.Map; import net.nicoulaj.maven.plugins.checksum.artifacts.ArtifactListener; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import org.apache.maven.shared.utils.StringUtils; import org.apache.maven.shared.utils.xml.PrettyPrintXMLWriter; import java.io.*; import java.nio.file.Files; import java.util.Arrays; import java.util.Comparator; /*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to an XML file. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @since 1.0 * @version $Id: $Id */ public class XmlSummaryFileTarget implements ExecutionTarget { /** * The number of spaces used to indent the output file. */ public static final int XML_INDENTATION_SIZE = 2; /** * Encoding to use for generated files. */ protected final String encoding; /** * The association file =&gt; (algorithm,hashcode). */
protected Map<ChecksumFile, Map<String, String>> filesHashcodes;
nicoulaj/checksum-maven-plugin
src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/XmlSummaryFileTarget.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/artifacts/ArtifactListener.java // public interface ArtifactListener { // /** // * <p>artifactCreated.</p> // * // * @param artifact a {@link java.io.File} object // * @param checksumType a {@link java.lang.String} object // * @param artifactExtension a {@link java.lang.String} object // * @param artifactClassifier a {@link java.lang.String} object // */ // void artifactCreated(File artifact, String checksumType, String artifactExtension, String artifactClassifier); // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // }
import java.util.HashMap; import java.util.Map; import net.nicoulaj.maven.plugins.checksum.artifacts.ArtifactListener; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import org.apache.maven.shared.utils.StringUtils; import org.apache.maven.shared.utils.xml.PrettyPrintXMLWriter; import java.io.*; import java.nio.file.Files; import java.util.Arrays; import java.util.Comparator;
/*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to an XML file. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @since 1.0 * @version $Id: $Id */ public class XmlSummaryFileTarget implements ExecutionTarget { /** * The number of spaces used to indent the output file. */ public static final int XML_INDENTATION_SIZE = 2; /** * Encoding to use for generated files. */ protected final String encoding; /** * The association file =&gt; (algorithm,hashcode). */ protected Map<ChecksumFile, Map<String, String>> filesHashcodes; /** * The target file where the summary is written. */ protected final File summaryFile; /** * List of listeners which are notified every time a XML file is created. * * @since 1.3 */
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/artifacts/ArtifactListener.java // public interface ArtifactListener { // /** // * <p>artifactCreated.</p> // * // * @param artifact a {@link java.io.File} object // * @param checksumType a {@link java.lang.String} object // * @param artifactExtension a {@link java.lang.String} object // * @param artifactClassifier a {@link java.lang.String} object // */ // void artifactCreated(File artifact, String checksumType, String artifactExtension, String artifactClassifier); // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // } // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/XmlSummaryFileTarget.java import java.util.HashMap; import java.util.Map; import net.nicoulaj.maven.plugins.checksum.artifacts.ArtifactListener; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import org.apache.maven.shared.utils.StringUtils; import org.apache.maven.shared.utils.xml.PrettyPrintXMLWriter; import java.io.*; import java.nio.file.Files; import java.util.Arrays; import java.util.Comparator; /*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to an XML file. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @since 1.0 * @version $Id: $Id */ public class XmlSummaryFileTarget implements ExecutionTarget { /** * The number of spaces used to indent the output file. */ public static final int XML_INDENTATION_SIZE = 2; /** * Encoding to use for generated files. */ protected final String encoding; /** * The association file =&gt; (algorithm,hashcode). */ protected Map<ChecksumFile, Map<String, String>> filesHashcodes; /** * The target file where the summary is written. */ protected final File summaryFile; /** * List of listeners which are notified every time a XML file is created. * * @since 1.3 */
protected final Iterable<? extends ArtifactListener> artifactListeners;
nicoulaj/checksum-maven-plugin
src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/ShasumSummaryFileTarget.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/artifacts/ArtifactListener.java // public interface ArtifactListener { // /** // * <p>artifactCreated.</p> // * // * @param artifact a {@link java.io.File} object // * @param checksumType a {@link java.lang.String} object // * @param artifactExtension a {@link java.lang.String} object // * @param artifactClassifier a {@link java.lang.String} object // */ // void artifactCreated(File artifact, String checksumType, String artifactExtension, String artifactClassifier); // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // }
import net.nicoulaj.maven.plugins.checksum.artifacts.ArtifactListener; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.*;
/*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to a {@code shasum} file * compatible with "{@code shasum -b -a <algo> <files> > sha.sum}". For * compatibility with {@code shasum} only SHA-1, SHA-224, SHA-256, SHA-384, * SHA-512, SHA-512224 and SHA-512256 are supported. Only one algorithm may be * used at a time. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @author Mike Duigou * @since 1.3 * @version $Id: $Id */ public class ShasumSummaryFileTarget implements ExecutionTarget { /** * The line separator character. */ public static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); /** * The shasum field separator (and file type binary identifier) */ public static final String SHASUM_FIELD_SEPARATOR = " *"; /** * The shasum binary character. */ public static final String SHASUM_BINARY_FILE = "*"; /** * The association file =&gt; (algorithm,hashcode). */
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/artifacts/ArtifactListener.java // public interface ArtifactListener { // /** // * <p>artifactCreated.</p> // * // * @param artifact a {@link java.io.File} object // * @param checksumType a {@link java.lang.String} object // * @param artifactExtension a {@link java.lang.String} object // * @param artifactClassifier a {@link java.lang.String} object // */ // void artifactCreated(File artifact, String checksumType, String artifactExtension, String artifactClassifier); // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // } // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/ShasumSummaryFileTarget.java import net.nicoulaj.maven.plugins.checksum.artifacts.ArtifactListener; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.*; /*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to a {@code shasum} file * compatible with "{@code shasum -b -a <algo> <files> > sha.sum}". For * compatibility with {@code shasum} only SHA-1, SHA-224, SHA-256, SHA-384, * SHA-512, SHA-512224 and SHA-512256 are supported. Only one algorithm may be * used at a time. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @author Mike Duigou * @since 1.3 * @version $Id: $Id */ public class ShasumSummaryFileTarget implements ExecutionTarget { /** * The line separator character. */ public static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); /** * The shasum field separator (and file type binary identifier) */ public static final String SHASUM_FIELD_SEPARATOR = " *"; /** * The shasum binary character. */ public static final String SHASUM_BINARY_FILE = "*"; /** * The association file =&gt; (algorithm,hashcode). */
protected Map<ChecksumFile, Map<String, String>> filesHashcodes;
nicoulaj/checksum-maven-plugin
src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/CsvSummaryFileTarget.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/artifacts/ArtifactListener.java // public interface ArtifactListener { // /** // * <p>artifactCreated.</p> // * // * @param artifact a {@link java.io.File} object // * @param checksumType a {@link java.lang.String} object // * @param artifactExtension a {@link java.lang.String} object // * @param artifactClassifier a {@link java.lang.String} object // */ // void artifactCreated(File artifact, String checksumType, String artifactExtension, String artifactClassifier); // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // }
import net.nicoulaj.maven.plugins.checksum.artifacts.ArtifactListener; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.*;
/*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to a CSV file. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @since 1.0 * @version $Id: $Id */ public class CsvSummaryFileTarget implements ExecutionTarget { /** * The line separator character. */ public static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); /** * The CSV column separator character. */ public static final String CSV_COLUMN_SEPARATOR = ","; /** * The CSV comment marker character. */ public static final String CSV_COMMENT_MARKER = "#"; /** * Encoding to use for generated files. */ protected final String encoding; /** * The association file =&gt; (algorithm,hashcode). */
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/artifacts/ArtifactListener.java // public interface ArtifactListener { // /** // * <p>artifactCreated.</p> // * // * @param artifact a {@link java.io.File} object // * @param checksumType a {@link java.lang.String} object // * @param artifactExtension a {@link java.lang.String} object // * @param artifactClassifier a {@link java.lang.String} object // */ // void artifactCreated(File artifact, String checksumType, String artifactExtension, String artifactClassifier); // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // } // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/CsvSummaryFileTarget.java import net.nicoulaj.maven.plugins.checksum.artifacts.ArtifactListener; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.*; /*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to a CSV file. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @since 1.0 * @version $Id: $Id */ public class CsvSummaryFileTarget implements ExecutionTarget { /** * The line separator character. */ public static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); /** * The CSV column separator character. */ public static final String CSV_COLUMN_SEPARATOR = ","; /** * The CSV comment marker character. */ public static final String CSV_COMMENT_MARKER = "#"; /** * Encoding to use for generated files. */ protected final String encoding; /** * The association file =&gt; (algorithm,hashcode). */
protected Map<ChecksumFile, Map<String, String>> filesHashcodes;
nicoulaj/checksum-maven-plugin
src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/CsvSummaryFileTarget.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/artifacts/ArtifactListener.java // public interface ArtifactListener { // /** // * <p>artifactCreated.</p> // * // * @param artifact a {@link java.io.File} object // * @param checksumType a {@link java.lang.String} object // * @param artifactExtension a {@link java.lang.String} object // * @param artifactClassifier a {@link java.lang.String} object // */ // void artifactCreated(File artifact, String checksumType, String artifactExtension, String artifactClassifier); // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // }
import net.nicoulaj.maven.plugins.checksum.artifacts.ArtifactListener; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.*;
/*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to a CSV file. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @since 1.0 * @version $Id: $Id */ public class CsvSummaryFileTarget implements ExecutionTarget { /** * The line separator character. */ public static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); /** * The CSV column separator character. */ public static final String CSV_COLUMN_SEPARATOR = ","; /** * The CSV comment marker character. */ public static final String CSV_COMMENT_MARKER = "#"; /** * Encoding to use for generated files. */ protected final String encoding; /** * The association file =&gt; (algorithm,hashcode). */ protected Map<ChecksumFile, Map<String, String>> filesHashcodes; /** * The set of algorithms encountered. */ protected SortedSet<String> algorithms; /** * The target file where the summary is written. */ protected final File summaryFile; /** * List of listeners which are notified every time a CSV file is created. * * @since 1.3 */
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/artifacts/ArtifactListener.java // public interface ArtifactListener { // /** // * <p>artifactCreated.</p> // * // * @param artifact a {@link java.io.File} object // * @param checksumType a {@link java.lang.String} object // * @param artifactExtension a {@link java.lang.String} object // * @param artifactClassifier a {@link java.lang.String} object // */ // void artifactCreated(File artifact, String checksumType, String artifactExtension, String artifactClassifier); // } // // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/mojo/ChecksumFile.java // public class ChecksumFile // { // protected final String basePath; // // protected final File file; // // protected final String extension; // // protected final String classifier; // // /** // * <p>Constructor for ChecksumFile.</p> // * // * @param basePath a {@link java.lang.String} object // * @param file a {@link java.io.File} object // * @param extension a {@link java.lang.String} object // * @param classifier a {@link java.lang.String} object // */ // public ChecksumFile(String basePath, File file, String extension, String classifier) // { // this.basePath = basePath; // this.file = file; // this.extension = extension; // this.classifier = classifier; // } // // /** // * <p>Getter for the field <code>basePath</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getBasePath() // { // return basePath; // } // // /** // * <p>Getter for the field <code>file</code>.</p> // * // * @return a {@link java.io.File} object // */ // public File getFile() // { // return file; // } // // /** // * <p>Getter for the field <code>extension</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getExtension() // { // return extension; // } // // /** // * <p>Getter for the field <code>classifier</code>.</p> // * // * @return a {@link java.lang.String} object // */ // public String getClassifier() // { // return classifier; // } // // /** // * <p>getRelativePath.</p> // * // * @param file a {@link net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile} object // * @param subPath a {@link java.lang.String} object // * @return a {@link java.lang.String} object // */ // public String getRelativePath(ChecksumFile file, String subPath) // { // String filePath = file.getFile().getName(); // // if ( subPath != null ) { // if ( file.getBasePath() != null && !file.getBasePath().isEmpty() ) // { // String basePath = file.getBasePath(); // // if ( !basePath.endsWith( System.getProperty("file.separator") ) ) // basePath = basePath + System.getProperty("file.separator"); // // filePath = file.getFile().getPath().replace(basePath, ""); // // if ( !subPath.isEmpty() ) // { // if ( !subPath.endsWith( System.getProperty("file.separator") ) ) // subPath = subPath + System.getProperty("file.separator"); // // filePath = filePath.replace(subPath, ""); // } // } // } // // return filePath; // } // } // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/execution/target/CsvSummaryFileTarget.java import net.nicoulaj.maven.plugins.checksum.artifacts.ArtifactListener; import net.nicoulaj.maven.plugins.checksum.mojo.ChecksumFile; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.*; /*- * ==================================================================== * checksum-maven-plugin * ==================================================================== * Copyright (C) 2010 - 2016 Julien Nicoulaud <[email protected]> * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ==================================================================== */ package net.nicoulaj.maven.plugins.checksum.execution.target; /** * An {@link net.nicoulaj.maven.plugins.checksum.execution.target.ExecutionTarget} that writes digests to a CSV file. * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @since 1.0 * @version $Id: $Id */ public class CsvSummaryFileTarget implements ExecutionTarget { /** * The line separator character. */ public static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); /** * The CSV column separator character. */ public static final String CSV_COLUMN_SEPARATOR = ","; /** * The CSV comment marker character. */ public static final String CSV_COMMENT_MARKER = "#"; /** * Encoding to use for generated files. */ protected final String encoding; /** * The association file =&gt; (algorithm,hashcode). */ protected Map<ChecksumFile, Map<String, String>> filesHashcodes; /** * The set of algorithms encountered. */ protected SortedSet<String> algorithms; /** * The target file where the summary is written. */ protected final File summaryFile; /** * List of listeners which are notified every time a CSV file is created. * * @since 1.3 */
protected final Iterable<? extends ArtifactListener> artifactListeners;
nicoulaj/checksum-maven-plugin
src/main/java/net/nicoulaj/maven/plugins/checksum/digest/DigesterFactory.java
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/Constants.java // public class Constants // { // /** // * The CRC/checksum digest algorithms supported by checksum-maven-plugin. // */ // public static final String[] SUPPORTED_ALGORITHMS = { // "Cksum", // "CRC32", // "BLAKE2B-160", // "BLAKE2B-256", // "BLAKE2B-384", // "BLAKE2B-512", // "GOST3411", // "GOST3411-2012-256", // "GOST3411-2012-512", // "KECCAK-224", // "KECCAK-256", // "KECCAK-288", // "KECCAK-384", // "KECCAK-512", // "MD2", // "MD4", // "MD5", // "RIPEMD128", // "RIPEMD160", // "RIPEMD256", // "RIPEMD320", // "SHA", // "SHA-1", // "SHA-224", // "SHA-256", // "SHA3-224", // "SHA3-256", // "SHA3-384", // "SHA3-512", // "SHA-384", // "SHA-512", // "SHA-512/224", // "SHA-512/256", // "SKEIN-1024-1024", // "SKEIN-1024-384", // "SKEIN-1024-512", // "SKEIN-256-128", // "SKEIN-256-160", // "SKEIN-256-224", // "SKEIN-256-256", // "SKEIN-512-128", // "SKEIN-512-160", // "SKEIN-512-224", // "SKEIN-512-256", // "SKEIN-512-384", // "SKEIN-512-512", // "SM3", // "TIGER", // "WHIRLPOOL" // }; // // /** // * The algorithms used by default for a mojo execution. // */ // public static final String[] DEFAULT_EXECUTION_ALGORITHMS = { "MD5", "SHA-1" }; // // /** // * The file encoding used by default. // */ // public static final String DEFAULT_ENCODING = "UTF-8"; // }
import net.nicoulaj.maven.plugins.checksum.Constants; import org.bouncycastle.jce.provider.BouncyCastleProvider; import java.security.NoSuchAlgorithmException; import java.security.Security; import java.util.HashMap; import java.util.Map;
/* * checksum-maven-plugin - http://checksum-maven-plugin.nicoulaj.net * Copyright © 2010-2021 checksum-maven-plugin contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.nicoulaj.maven.plugins.checksum.digest; /** * Singleton class used to get instances of {@link net.nicoulaj.maven.plugins.checksum.digest.FileDigester}. * * <p>Each {@link net.nicoulaj.maven.plugins.checksum.digest.FileDigester} object is a singleton itself.</p> * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @see FileDigester * @since 1.0 * @version $Id: $Id */ public class DigesterFactory { /** * The instance of {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory}. */ private static DigesterFactory instance; /** * The map (algorithm, digester). */
// Path: src/main/java/net/nicoulaj/maven/plugins/checksum/Constants.java // public class Constants // { // /** // * The CRC/checksum digest algorithms supported by checksum-maven-plugin. // */ // public static final String[] SUPPORTED_ALGORITHMS = { // "Cksum", // "CRC32", // "BLAKE2B-160", // "BLAKE2B-256", // "BLAKE2B-384", // "BLAKE2B-512", // "GOST3411", // "GOST3411-2012-256", // "GOST3411-2012-512", // "KECCAK-224", // "KECCAK-256", // "KECCAK-288", // "KECCAK-384", // "KECCAK-512", // "MD2", // "MD4", // "MD5", // "RIPEMD128", // "RIPEMD160", // "RIPEMD256", // "RIPEMD320", // "SHA", // "SHA-1", // "SHA-224", // "SHA-256", // "SHA3-224", // "SHA3-256", // "SHA3-384", // "SHA3-512", // "SHA-384", // "SHA-512", // "SHA-512/224", // "SHA-512/256", // "SKEIN-1024-1024", // "SKEIN-1024-384", // "SKEIN-1024-512", // "SKEIN-256-128", // "SKEIN-256-160", // "SKEIN-256-224", // "SKEIN-256-256", // "SKEIN-512-128", // "SKEIN-512-160", // "SKEIN-512-224", // "SKEIN-512-256", // "SKEIN-512-384", // "SKEIN-512-512", // "SM3", // "TIGER", // "WHIRLPOOL" // }; // // /** // * The algorithms used by default for a mojo execution. // */ // public static final String[] DEFAULT_EXECUTION_ALGORITHMS = { "MD5", "SHA-1" }; // // /** // * The file encoding used by default. // */ // public static final String DEFAULT_ENCODING = "UTF-8"; // } // Path: src/main/java/net/nicoulaj/maven/plugins/checksum/digest/DigesterFactory.java import net.nicoulaj.maven.plugins.checksum.Constants; import org.bouncycastle.jce.provider.BouncyCastleProvider; import java.security.NoSuchAlgorithmException; import java.security.Security; import java.util.HashMap; import java.util.Map; /* * checksum-maven-plugin - http://checksum-maven-plugin.nicoulaj.net * Copyright © 2010-2021 checksum-maven-plugin contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.nicoulaj.maven.plugins.checksum.digest; /** * Singleton class used to get instances of {@link net.nicoulaj.maven.plugins.checksum.digest.FileDigester}. * * <p>Each {@link net.nicoulaj.maven.plugins.checksum.digest.FileDigester} object is a singleton itself.</p> * * @author <a href="mailto:[email protected]">Julien Nicoulaud</a> * @see FileDigester * @since 1.0 * @version $Id: $Id */ public class DigesterFactory { /** * The instance of {@link net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory}. */ private static DigesterFactory instance; /** * The map (algorithm, digester). */
protected Map<String, FileDigester> digesters = new HashMap<>( Constants.SUPPORTED_ALGORITHMS.length );
kaklakariada/fritzbox-java-api
src/main/java/com/github/kaklakariada/fritzbox/EnergyStatisticsService.java
// Path: src/main/java/com/github/kaklakariada/fritzbox/http/QueryParameters.java // public class QueryParameters { // // private final Map<String, String> parameters; // // private QueryParameters(Map<String, String> parameters) { // this.parameters = parameters; // } // // public static Builder builder() { // return new Builder(); // } // // public Map<String, String> getParameters() { // return parameters; // } // // public Builder newBuilder() { // return new Builder(new HashMap<>(this.parameters)); // } // // public static class Builder { // private final Map<String, String> parameters; // // private Builder() { // this(new HashMap<String, String>()); // } // // public Builder(Map<String, String> parameters) { // this.parameters = parameters; // } // // public Builder add(String name, String value) { // parameters.put(name, value); // return this; // } // // public QueryParameters build() { // return new QueryParameters(parameters); // } // } // }
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.github.kaklakariada.fritzbox.http.QueryParameters;
/** * A Java API for managing FritzBox HomeAutomation * Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.github.kaklakariada.fritzbox; /** * This class retrieves energy statistics. */ public class EnergyStatisticsService { private static final Logger LOG = LoggerFactory.getLogger(EnergyStatisticsService.class); private static final String QUERY_PATH = "/net/home_auto_query.lua"; public enum EnergyStatsTimeRange { TEN_MINUTES("EnergyStats_10"), // ONE_HOUR("EnergyStats_hour"), // ONE_DAY("EnergyStats_24h"), // ONE_WEEK("EnergyStats_week"), // ONE_MONTH("EnergyStats_month"), // ONE_YEAR("EnergyStats_year"); private final String command; private EnergyStatsTimeRange(String command) { this.command = command; } } private final FritzBoxSession session; public EnergyStatisticsService(FritzBoxSession session) { this.session = session; } public String getEnergyStatistics(String deviceId, EnergyStatsTimeRange timeRange) { return executeDeviceCommand(deviceId, timeRange.command); } private String executeDeviceCommand(String deviceId, String command) {
// Path: src/main/java/com/github/kaklakariada/fritzbox/http/QueryParameters.java // public class QueryParameters { // // private final Map<String, String> parameters; // // private QueryParameters(Map<String, String> parameters) { // this.parameters = parameters; // } // // public static Builder builder() { // return new Builder(); // } // // public Map<String, String> getParameters() { // return parameters; // } // // public Builder newBuilder() { // return new Builder(new HashMap<>(this.parameters)); // } // // public static class Builder { // private final Map<String, String> parameters; // // private Builder() { // this(new HashMap<String, String>()); // } // // public Builder(Map<String, String> parameters) { // this.parameters = parameters; // } // // public Builder add(String name, String value) { // parameters.put(name, value); // return this; // } // // public QueryParameters build() { // return new QueryParameters(parameters); // } // } // } // Path: src/main/java/com/github/kaklakariada/fritzbox/EnergyStatisticsService.java import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.github.kaklakariada.fritzbox.http.QueryParameters; /** * A Java API for managing FritzBox HomeAutomation * Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.github.kaklakariada.fritzbox; /** * This class retrieves energy statistics. */ public class EnergyStatisticsService { private static final Logger LOG = LoggerFactory.getLogger(EnergyStatisticsService.class); private static final String QUERY_PATH = "/net/home_auto_query.lua"; public enum EnergyStatsTimeRange { TEN_MINUTES("EnergyStats_10"), // ONE_HOUR("EnergyStats_hour"), // ONE_DAY("EnergyStats_24h"), // ONE_WEEK("EnergyStats_week"), // ONE_MONTH("EnergyStats_month"), // ONE_YEAR("EnergyStats_year"); private final String command; private EnergyStatsTimeRange(String command) { this.command = command; } } private final FritzBoxSession session; public EnergyStatisticsService(FritzBoxSession session) { this.session = session; } public String getEnergyStatistics(String deviceId, EnergyStatsTimeRange timeRange) { return executeDeviceCommand(deviceId, timeRange.command); } private String executeDeviceCommand(String deviceId, String command) {
final QueryParameters parameters = QueryParameters.builder().add("command", command).add("id", deviceId)
kaklakariada/fritzbox-java-api
src/main/java/com/github/kaklakariada/fritzbox/http/HttpTemplate.java
// Path: src/main/java/com/github/kaklakariada/fritzbox/FritzBoxException.java // public class FritzBoxException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public FritzBoxException(String message, Throwable cause) { // super(message, cause); // } // // public FritzBoxException(String message) { // super(message); // } // } // // Path: src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java // public class Deserializer { // private static final Logger LOG = LoggerFactory.getLogger(Deserializer.class); // // private final Serializer xmlSerializer; // // public Deserializer() { // this(new Persister()); // } // // Deserializer(Serializer xmlSerializer) { // this.xmlSerializer = xmlSerializer; // } // // public <T> T parse(String data, Class<T> resultType) { // if (resultType == String.class) { // return resultType.cast(data); // } // if (resultType == Boolean.class) { // return resultType.cast("1".equals(data)); // } // if (resultType == Integer.class) { // if (data.isEmpty() || "inval".equals(data)) { // return null; // } // return resultType.cast(Integer.parseInt(data)); // } // try { // final T object = xmlSerializer.read(resultType, data); // LOG.trace("Parsed response: {}", object); // return object; // } catch (final Exception e) { // throw new DeserializerException("Error parsing response body '" + data + "'", e); // } // } // }
import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import java.io.IOException; import java.util.Map.Entry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.github.kaklakariada.fritzbox.FritzBoxException; import com.github.kaklakariada.fritzbox.mapping.Deserializer; import okhttp3.HttpUrl; import okhttp3.HttpUrl.Builder; import okhttp3.MediaType; import okhttp3.OkHttpClient;
/** * A Java API for managing FritzBox HomeAutomation * Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.github.kaklakariada.fritzbox.http; /** * This class allows executing http requests against a server. Responses are converted using the given * {@link Deserializer}. */ public class HttpTemplate { private static final Logger LOG = LoggerFactory.getLogger(HttpTemplate.class); private final OkHttpClient httpClient; private final HttpUrl baseUrl;
// Path: src/main/java/com/github/kaklakariada/fritzbox/FritzBoxException.java // public class FritzBoxException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public FritzBoxException(String message, Throwable cause) { // super(message, cause); // } // // public FritzBoxException(String message) { // super(message); // } // } // // Path: src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java // public class Deserializer { // private static final Logger LOG = LoggerFactory.getLogger(Deserializer.class); // // private final Serializer xmlSerializer; // // public Deserializer() { // this(new Persister()); // } // // Deserializer(Serializer xmlSerializer) { // this.xmlSerializer = xmlSerializer; // } // // public <T> T parse(String data, Class<T> resultType) { // if (resultType == String.class) { // return resultType.cast(data); // } // if (resultType == Boolean.class) { // return resultType.cast("1".equals(data)); // } // if (resultType == Integer.class) { // if (data.isEmpty() || "inval".equals(data)) { // return null; // } // return resultType.cast(Integer.parseInt(data)); // } // try { // final T object = xmlSerializer.read(resultType, data); // LOG.trace("Parsed response: {}", object); // return object; // } catch (final Exception e) { // throw new DeserializerException("Error parsing response body '" + data + "'", e); // } // } // } // Path: src/main/java/com/github/kaklakariada/fritzbox/http/HttpTemplate.java import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import java.io.IOException; import java.util.Map.Entry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.github.kaklakariada.fritzbox.FritzBoxException; import com.github.kaklakariada.fritzbox.mapping.Deserializer; import okhttp3.HttpUrl; import okhttp3.HttpUrl.Builder; import okhttp3.MediaType; import okhttp3.OkHttpClient; /** * A Java API for managing FritzBox HomeAutomation * Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.github.kaklakariada.fritzbox.http; /** * This class allows executing http requests against a server. Responses are converted using the given * {@link Deserializer}. */ public class HttpTemplate { private static final Logger LOG = LoggerFactory.getLogger(HttpTemplate.class); private final OkHttpClient httpClient; private final HttpUrl baseUrl;
private final Deserializer deserializer;
kaklakariada/fritzbox-java-api
src/main/java/com/github/kaklakariada/fritzbox/http/HttpTemplate.java
// Path: src/main/java/com/github/kaklakariada/fritzbox/FritzBoxException.java // public class FritzBoxException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public FritzBoxException(String message, Throwable cause) { // super(message, cause); // } // // public FritzBoxException(String message) { // super(message); // } // } // // Path: src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java // public class Deserializer { // private static final Logger LOG = LoggerFactory.getLogger(Deserializer.class); // // private final Serializer xmlSerializer; // // public Deserializer() { // this(new Persister()); // } // // Deserializer(Serializer xmlSerializer) { // this.xmlSerializer = xmlSerializer; // } // // public <T> T parse(String data, Class<T> resultType) { // if (resultType == String.class) { // return resultType.cast(data); // } // if (resultType == Boolean.class) { // return resultType.cast("1".equals(data)); // } // if (resultType == Integer.class) { // if (data.isEmpty() || "inval".equals(data)) { // return null; // } // return resultType.cast(Integer.parseInt(data)); // } // try { // final T object = xmlSerializer.read(resultType, data); // LOG.trace("Parsed response: {}", object); // return object; // } catch (final Exception e) { // throw new DeserializerException("Error parsing response body '" + data + "'", e); // } // } // }
import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import java.io.IOException; import java.util.Map.Entry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.github.kaklakariada.fritzbox.FritzBoxException; import com.github.kaklakariada.fritzbox.mapping.Deserializer; import okhttp3.HttpUrl; import okhttp3.HttpUrl.Builder; import okhttp3.MediaType; import okhttp3.OkHttpClient;
public <T> T get(String path, Class<T> resultType) { return get(path, QueryParameters.builder().build(), resultType); } public <T> T get(String path, QueryParameters parameters, Class<T> resultType) { final HttpUrl url = createUrl(path, parameters); return get(resultType, url); } public <T> T post(String path, QueryParameters parameters, Class<T> resultType) { final HttpUrl url = createUrl(path, parameters); return post(resultType, url); } private <T> T get(Class<T> resultType, HttpUrl url) { final Request request = new Request.Builder().url(url).get().build(); final Response response = execute(request); return parse(response, resultType); } private <T> T post(Class<T> resultType, HttpUrl url) { final MediaType mediaType = MediaType.parse("application/xml"); final RequestBody emptyBody = RequestBody.create(new byte[0], mediaType); final Request request = new Request.Builder().url(url).post(emptyBody).build(); final Response response = execute(request); return parse(response, resultType); } private <T> T parse(final Response response, Class<T> resultType) { if (!response.isSuccessful()) {
// Path: src/main/java/com/github/kaklakariada/fritzbox/FritzBoxException.java // public class FritzBoxException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public FritzBoxException(String message, Throwable cause) { // super(message, cause); // } // // public FritzBoxException(String message) { // super(message); // } // } // // Path: src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java // public class Deserializer { // private static final Logger LOG = LoggerFactory.getLogger(Deserializer.class); // // private final Serializer xmlSerializer; // // public Deserializer() { // this(new Persister()); // } // // Deserializer(Serializer xmlSerializer) { // this.xmlSerializer = xmlSerializer; // } // // public <T> T parse(String data, Class<T> resultType) { // if (resultType == String.class) { // return resultType.cast(data); // } // if (resultType == Boolean.class) { // return resultType.cast("1".equals(data)); // } // if (resultType == Integer.class) { // if (data.isEmpty() || "inval".equals(data)) { // return null; // } // return resultType.cast(Integer.parseInt(data)); // } // try { // final T object = xmlSerializer.read(resultType, data); // LOG.trace("Parsed response: {}", object); // return object; // } catch (final Exception e) { // throw new DeserializerException("Error parsing response body '" + data + "'", e); // } // } // } // Path: src/main/java/com/github/kaklakariada/fritzbox/http/HttpTemplate.java import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import java.io.IOException; import java.util.Map.Entry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.github.kaklakariada.fritzbox.FritzBoxException; import com.github.kaklakariada.fritzbox.mapping.Deserializer; import okhttp3.HttpUrl; import okhttp3.HttpUrl.Builder; import okhttp3.MediaType; import okhttp3.OkHttpClient; public <T> T get(String path, Class<T> resultType) { return get(path, QueryParameters.builder().build(), resultType); } public <T> T get(String path, QueryParameters parameters, Class<T> resultType) { final HttpUrl url = createUrl(path, parameters); return get(resultType, url); } public <T> T post(String path, QueryParameters parameters, Class<T> resultType) { final HttpUrl url = createUrl(path, parameters); return post(resultType, url); } private <T> T get(Class<T> resultType, HttpUrl url) { final Request request = new Request.Builder().url(url).get().build(); final Response response = execute(request); return parse(response, resultType); } private <T> T post(Class<T> resultType, HttpUrl url) { final MediaType mediaType = MediaType.parse("application/xml"); final RequestBody emptyBody = RequestBody.create(new byte[0], mediaType); final Request request = new Request.Builder().url(url).post(emptyBody).build(); final Response response = execute(request); return parse(response, resultType); } private <T> T parse(final Response response, Class<T> resultType) { if (!response.isSuccessful()) {
throw new FritzBoxException("Request failed: " + response);
kaklakariada/fritzbox-java-api
src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/Statistics.java
// Path: src/main/java/com/github/kaklakariada/fritzbox/helper/StringHelper.java // public class StringHelper { // // private StringHelper(){ // // Not instantiable // } // // /** // * <p>Note that the method does not allow for a leading sign, either positive or negative.</p> // * // * <pre> // * StringUtils.isIntegerNumber(null) = false // * StringHelper.isIntegerNumber("")) = false // * StringHelper.isIntegerNumber(" ") = false // * StringHelper.isIntegerNumber(" 1 ") = true // * StringHelper.isIntegerNumber("123") = true // * StringUtils.isIntegerNumber("\u0967\u0968\u0969") = true // * StringHelper.isIntegerNumber("1.1") = false // * StringHelper.isIntegerNumber("1.1D") = false // * </pre> // * // * // * @param cs the String to check, may be null // * @return {@code true} if only contains digits or is enclosed by blanks, and is non-null // */ // public static boolean isIntegerNumber(final String cs) { // if (isEmpty(cs) || !isNumeric(cs.trim())) { // return false; // } // try { // Integer.parseInt(cs.trim()); // } catch (NumberFormatException nfe) { // return false; // } // return true; // } // // /** // * <h4>Code copied 'as is' from apache-commons-lang3, class StringUtils.isNumeric()</h4> // * // * <p>Checks if the CharSequence contains only Unicode digits. // * A decimal point is not a Unicode digit and returns false.</p> // * // * <p>{@code null} will return {@code false}. // * An empty CharSequence (length()=0) will return {@code false}.</p> // * // * <p>Note that the method does not allow for a leading sign, either positive or negative. // * Also, if a String passes the numeric test, it may still generate a NumberFormatException // * when parsed by Integer.parseInt or Long.parseLong, e.g. if the value is outside the range // * for int or long respectively.</p> // * // * <pre> // * StringUtils.isNumeric(null) = false // * StringUtils.isNumeric("") = false // * StringUtils.isNumeric(" ") = false // * StringUtils.isNumeric("123") = true // * StringUtils.isNumeric("\u0967\u0968\u0969") = true // * StringUtils.isNumeric("12 3") = false // * StringUtils.isNumeric("ab2c") = false // * StringUtils.isNumeric("12-3") = false // * StringUtils.isNumeric("12.3") = false // * StringUtils.isNumeric("-123") = false // * StringUtils.isNumeric("+123") = false // * </pre> // * // * @param cs the CharSequence to check, may be null // * @return {@code true} if only contains digits, and is non-null // */ // public static boolean isNumeric(final CharSequence cs) { // if (isEmpty(cs)) { // return false; // } // final int sz = cs.length(); // for (int i = 0; i < sz; i++) { // if (!Character.isDigit(cs.charAt(i))) { // return false; // } // } // return true; // } // // // /** // * <h4>Code copied 'as is' from apache-commons-lang3, class StringUtils.isEmpty()</h4> // * // * <p>Checks if a CharSequence is empty ("") or null.</p> // * // * <pre> // * StringUtils.isEmpty(null) = true // * StringUtils.isEmpty("") = true // * StringUtils.isEmpty(" ") = false // * StringUtils.isEmpty("bob") = false // * StringUtils.isEmpty(" bob ") = false // * </pre> // * // * // * @param cs the CharSequence to check, may be null // * @return {@code true} if the CharSequence is empty or null // */ // public static boolean isEmpty(final CharSequence cs) { // return cs == null || cs.length() == 0; // } // }
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import org.simpleframework.xml.Attribute; import org.simpleframework.xml.Root; import org.simpleframework.xml.Text; import com.github.kaklakariada.fritzbox.helper.StringHelper;
} return Arrays.asList(getCsvValues().split(",")) .stream() .map(aValue -> Optional.ofNullable(computeValue(aValue))) .collect(Collectors.toList()); } /** * Provide the measurement unit to be used with the statistics. * <p> * Consists of: * <ul> * <li>measurment unit [V, W, Wh, %]</li> * <li>precision as double to multiply with the gathered Integer</li> * </ul> * Sample: The Voltage is measured in 'V' (Volt) and has a precision of '0.001'. The number 237123 provided by the * statistics must be multiplied by the precision which gives us 237.123 V. * * @return */ public MeasurementUnit getMeasurementUnit() { return measurementUnit; } public void setMeasurementUnit(final MeasurementUnit measurementUnit) { this.measurementUnit = measurementUnit; } protected Number computeValue(String aValue) { Number numberValue = null;
// Path: src/main/java/com/github/kaklakariada/fritzbox/helper/StringHelper.java // public class StringHelper { // // private StringHelper(){ // // Not instantiable // } // // /** // * <p>Note that the method does not allow for a leading sign, either positive or negative.</p> // * // * <pre> // * StringUtils.isIntegerNumber(null) = false // * StringHelper.isIntegerNumber("")) = false // * StringHelper.isIntegerNumber(" ") = false // * StringHelper.isIntegerNumber(" 1 ") = true // * StringHelper.isIntegerNumber("123") = true // * StringUtils.isIntegerNumber("\u0967\u0968\u0969") = true // * StringHelper.isIntegerNumber("1.1") = false // * StringHelper.isIntegerNumber("1.1D") = false // * </pre> // * // * // * @param cs the String to check, may be null // * @return {@code true} if only contains digits or is enclosed by blanks, and is non-null // */ // public static boolean isIntegerNumber(final String cs) { // if (isEmpty(cs) || !isNumeric(cs.trim())) { // return false; // } // try { // Integer.parseInt(cs.trim()); // } catch (NumberFormatException nfe) { // return false; // } // return true; // } // // /** // * <h4>Code copied 'as is' from apache-commons-lang3, class StringUtils.isNumeric()</h4> // * // * <p>Checks if the CharSequence contains only Unicode digits. // * A decimal point is not a Unicode digit and returns false.</p> // * // * <p>{@code null} will return {@code false}. // * An empty CharSequence (length()=0) will return {@code false}.</p> // * // * <p>Note that the method does not allow for a leading sign, either positive or negative. // * Also, if a String passes the numeric test, it may still generate a NumberFormatException // * when parsed by Integer.parseInt or Long.parseLong, e.g. if the value is outside the range // * for int or long respectively.</p> // * // * <pre> // * StringUtils.isNumeric(null) = false // * StringUtils.isNumeric("") = false // * StringUtils.isNumeric(" ") = false // * StringUtils.isNumeric("123") = true // * StringUtils.isNumeric("\u0967\u0968\u0969") = true // * StringUtils.isNumeric("12 3") = false // * StringUtils.isNumeric("ab2c") = false // * StringUtils.isNumeric("12-3") = false // * StringUtils.isNumeric("12.3") = false // * StringUtils.isNumeric("-123") = false // * StringUtils.isNumeric("+123") = false // * </pre> // * // * @param cs the CharSequence to check, may be null // * @return {@code true} if only contains digits, and is non-null // */ // public static boolean isNumeric(final CharSequence cs) { // if (isEmpty(cs)) { // return false; // } // final int sz = cs.length(); // for (int i = 0; i < sz; i++) { // if (!Character.isDigit(cs.charAt(i))) { // return false; // } // } // return true; // } // // // /** // * <h4>Code copied 'as is' from apache-commons-lang3, class StringUtils.isEmpty()</h4> // * // * <p>Checks if a CharSequence is empty ("") or null.</p> // * // * <pre> // * StringUtils.isEmpty(null) = true // * StringUtils.isEmpty("") = true // * StringUtils.isEmpty(" ") = false // * StringUtils.isEmpty("bob") = false // * StringUtils.isEmpty(" bob ") = false // * </pre> // * // * // * @param cs the CharSequence to check, may be null // * @return {@code true} if the CharSequence is empty or null // */ // public static boolean isEmpty(final CharSequence cs) { // return cs == null || cs.length() == 0; // } // } // Path: src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/Statistics.java import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import org.simpleframework.xml.Attribute; import org.simpleframework.xml.Root; import org.simpleframework.xml.Text; import com.github.kaklakariada.fritzbox.helper.StringHelper; } return Arrays.asList(getCsvValues().split(",")) .stream() .map(aValue -> Optional.ofNullable(computeValue(aValue))) .collect(Collectors.toList()); } /** * Provide the measurement unit to be used with the statistics. * <p> * Consists of: * <ul> * <li>measurment unit [V, W, Wh, %]</li> * <li>precision as double to multiply with the gathered Integer</li> * </ul> * Sample: The Voltage is measured in 'V' (Volt) and has a precision of '0.001'. The number 237123 provided by the * statistics must be multiplied by the precision which gives us 237.123 V. * * @return */ public MeasurementUnit getMeasurementUnit() { return measurementUnit; } public void setMeasurementUnit(final MeasurementUnit measurementUnit) { this.measurementUnit = measurementUnit; } protected Number computeValue(String aValue) { Number numberValue = null;
if (StringHelper.isIntegerNumber(aValue)) {
kaklakariada/fritzbox-java-api
src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/MeasurementUnit.java
// Path: src/main/java/com/github/kaklakariada/fritzbox/MissingClassException.java // public class MissingClassException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public MissingClassException(String message, Throwable cause) { // super(message, cause); // } // // public MissingClassException(String message) { // super(message); // } // }
import com.github.kaklakariada.fritzbox.MissingClassException;
/** * A Java API for managing FritzBox HomeAutomation * Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.github.kaklakariada.fritzbox.model.homeautomation; /** * provide the measurement unit to be used with the statistics.<p> * Consists of: * <ul> * <li>measurment unit [V, W, Wh, %]</li> * <li>precision as double to multiply with the gathered Integerv * </ul> * Sample: The Voltage is measured in 'V' (Volt) and has a precision of '0.001'. The number 237123 provided * by the statistics must be multiplied by the precision which gives us 237.123 V. * * @author Ulrich Schmidt(Gombers) * */ public enum MeasurementUnit { TEMPERATURE("C", 0.1, Temperature.class), VOLTAGE("V", 0.001, Voltage.class), POWER("W", 0.01, Power.class), ENERGY("Wh", 1, Energy.class), HUMIDITY("%", 1, Humidity.class); private final String unit; private final Number precision; private final Class<?> mapper; MeasurementUnit(String unit, Number precision, Class<?> mapper) { this.unit = unit; this.precision = precision; this.mapper = mapper; } public String getUnit() { return unit; } public Number getPrescision() { return precision; } public Class<?> getMapper() { return mapper; } public static MeasurementUnit getMatchingMeasurementUnit(Class<?> caller) { for (MeasurementUnit iterator : MeasurementUnit.values()) { if (caller.isAssignableFrom(iterator.getMapper())) { return iterator; } }
// Path: src/main/java/com/github/kaklakariada/fritzbox/MissingClassException.java // public class MissingClassException extends RuntimeException { // // private static final long serialVersionUID = 1L; // // public MissingClassException(String message, Throwable cause) { // super(message, cause); // } // // public MissingClassException(String message) { // super(message); // } // } // Path: src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/MeasurementUnit.java import com.github.kaklakariada.fritzbox.MissingClassException; /** * A Java API for managing FritzBox HomeAutomation * Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.github.kaklakariada.fritzbox.model.homeautomation; /** * provide the measurement unit to be used with the statistics.<p> * Consists of: * <ul> * <li>measurment unit [V, W, Wh, %]</li> * <li>precision as double to multiply with the gathered Integerv * </ul> * Sample: The Voltage is measured in 'V' (Volt) and has a precision of '0.001'. The number 237123 provided * by the statistics must be multiplied by the precision which gives us 237.123 V. * * @author Ulrich Schmidt(Gombers) * */ public enum MeasurementUnit { TEMPERATURE("C", 0.1, Temperature.class), VOLTAGE("V", 0.001, Voltage.class), POWER("W", 0.01, Power.class), ENERGY("Wh", 1, Energy.class), HUMIDITY("%", 1, Humidity.class); private final String unit; private final Number precision; private final Class<?> mapper; MeasurementUnit(String unit, Number precision, Class<?> mapper) { this.unit = unit; this.precision = precision; this.mapper = mapper; } public String getUnit() { return unit; } public Number getPrescision() { return precision; } public Class<?> getMapper() { return mapper; } public static MeasurementUnit getMatchingMeasurementUnit(Class<?> caller) { for (MeasurementUnit iterator : MeasurementUnit.values()) { if (caller.isAssignableFrom(iterator.getMapper())) { return iterator; } }
throw new MissingClassException(String.format("Could not detect enum of type 'MeasurementUnit' associated to class '%s'", caller.toString()));
kaklakariada/fritzbox-java-api
src/main/java/com/github/kaklakariada/fritzbox/LoginFailedException.java
// Path: src/main/java/com/github/kaklakariada/fritzbox/model/SessionInfo.java // @Root(name = "SessionInfo") // public class SessionInfo { // // @Element(name = "SID") // private String sid; // // @Element(name = "Challenge") // private String challenge; // // @Element(name = "BlockTime") // private String blockTime; // // @ElementList(name = "Rights", inline = false, required = false) // private List<UserRight> rights; // // @ElementList(name = "Users", inline = false, required = false) // private List<User> users; // // public String getSid() { // return sid; // } // // public String getChallenge() { // return challenge; // } // // public String getBlockTime() { // return blockTime; // } // // public List<UserRight> getRights() { // return rights; // } // // public List<User> getUsers() { // return users; // } // // @Override // public String toString() { // return "SessionInfo [sid=" + sid + ", challenge=" + challenge + ", blockTime=" + blockTime + ", rights=" // + rights + "]"; // } // }
import com.github.kaklakariada.fritzbox.model.SessionInfo;
/** * A Java API for managing FritzBox HomeAutomation * Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.github.kaklakariada.fritzbox; public class LoginFailedException extends FritzBoxException { private static final long serialVersionUID = 1L;
// Path: src/main/java/com/github/kaklakariada/fritzbox/model/SessionInfo.java // @Root(name = "SessionInfo") // public class SessionInfo { // // @Element(name = "SID") // private String sid; // // @Element(name = "Challenge") // private String challenge; // // @Element(name = "BlockTime") // private String blockTime; // // @ElementList(name = "Rights", inline = false, required = false) // private List<UserRight> rights; // // @ElementList(name = "Users", inline = false, required = false) // private List<User> users; // // public String getSid() { // return sid; // } // // public String getChallenge() { // return challenge; // } // // public String getBlockTime() { // return blockTime; // } // // public List<UserRight> getRights() { // return rights; // } // // public List<User> getUsers() { // return users; // } // // @Override // public String toString() { // return "SessionInfo [sid=" + sid + ", challenge=" + challenge + ", blockTime=" + blockTime + ", rights=" // + rights + "]"; // } // } // Path: src/main/java/com/github/kaklakariada/fritzbox/LoginFailedException.java import com.github.kaklakariada.fritzbox.model.SessionInfo; /** * A Java API for managing FritzBox HomeAutomation * Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.github.kaklakariada.fritzbox; public class LoginFailedException extends FritzBoxException { private static final long serialVersionUID = 1L;
public LoginFailedException(SessionInfo session) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // }
import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import org.springframework.cloud.client.ServiceInstance;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Application service to interact with an {@link ApplicationInstance application instance}. * * @author Tim Ysewyn * @author Steve De Zitter */ public class ApplicationInstanceService { private final ApplicationInstanceRepository repository; public ApplicationInstanceService(ApplicationInstanceRepository repository) { this.repository = repository; } public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) { return this.getById(serviceInstance.getInstanceId()) .map(ApplicationInstance::getId); } public Optional<ApplicationInstance> getById(String id) { return Optional.ofNullable(this.repository.getById(id)); } public List<ApplicationInstance> getApplicationInstances() { return this.repository.getAll(); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import org.springframework.cloud.client.ServiceInstance; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Application service to interact with an {@link ApplicationInstance application instance}. * * @author Tim Ysewyn * @author Steve De Zitter */ public class ApplicationInstanceService { private final ApplicationInstanceRepository repository; public ApplicationInstanceService(ApplicationInstanceRepository repository) { this.repository = repository; } public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) { return this.getById(serviceInstance.getInstanceId()) .map(ApplicationInstance::getId); } public Optional<ApplicationInstance> getById(String id) { return Optional.ofNullable(this.repository.getById(id)); } public List<ApplicationInstance> getApplicationInstances() { return this.repository.getAll(); }
public String createApplicationInstance(CreateApplicationInstance command) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // }
import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import org.springframework.cloud.client.ServiceInstance;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Application service to interact with an {@link ApplicationInstance application instance}. * * @author Tim Ysewyn * @author Steve De Zitter */ public class ApplicationInstanceService { private final ApplicationInstanceRepository repository; public ApplicationInstanceService(ApplicationInstanceRepository repository) { this.repository = repository; } public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) { return this.getById(serviceInstance.getInstanceId()) .map(ApplicationInstance::getId); } public Optional<ApplicationInstance> getById(String id) { return Optional.ofNullable(this.repository.getById(id)); } public List<ApplicationInstance> getApplicationInstances() { return this.repository.getAll(); } public String createApplicationInstance(CreateApplicationInstance command) { final ServiceInstance serviceInstance = command.getServiceInstance(); ApplicationInstance applicationInstance = ApplicationInstance.Builder .forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId()) .baseUri(serviceInstance.getUri()) .build(); return this.repository.save(applicationInstance).getId(); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import org.springframework.cloud.client.ServiceInstance; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Application service to interact with an {@link ApplicationInstance application instance}. * * @author Tim Ysewyn * @author Steve De Zitter */ public class ApplicationInstanceService { private final ApplicationInstanceRepository repository; public ApplicationInstanceService(ApplicationInstanceRepository repository) { this.repository = repository; } public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) { return this.getById(serviceInstance.getInstanceId()) .map(ApplicationInstance::getId); } public Optional<ApplicationInstance> getById(String id) { return Optional.ofNullable(this.repository.getById(id)); } public List<ApplicationInstance> getApplicationInstances() { return this.repository.getAll(); } public String createApplicationInstance(CreateApplicationInstance command) { final ServiceInstance serviceInstance = command.getServiceInstance(); ApplicationInstance applicationInstance = ApplicationInstance.Builder .forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId()) .baseUri(serviceInstance.getUri()) .build(); return this.repository.save(applicationInstance).getId(); }
public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // }
import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import org.springframework.cloud.client.ServiceInstance;
public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) { return this.getById(serviceInstance.getInstanceId()) .map(ApplicationInstance::getId); } public Optional<ApplicationInstance> getById(String id) { return Optional.ofNullable(this.repository.getById(id)); } public List<ApplicationInstance> getApplicationInstances() { return this.repository.getAll(); } public String createApplicationInstance(CreateApplicationInstance command) { final ServiceInstance serviceInstance = command.getServiceInstance(); ApplicationInstance applicationInstance = ApplicationInstance.Builder .forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId()) .baseUri(serviceInstance.getUri()) .build(); return this.repository.save(applicationInstance).getId(); } public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) { this.getById(command.getId()) .ifPresent(applicationInstance -> { applicationInstance.updateHealthStatus(command.getHealthStatus()); this.repository.save(applicationInstance); }); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import org.springframework.cloud.client.ServiceInstance; public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) { return this.getById(serviceInstance.getInstanceId()) .map(ApplicationInstance::getId); } public Optional<ApplicationInstance> getById(String id) { return Optional.ofNullable(this.repository.getById(id)); } public List<ApplicationInstance> getApplicationInstances() { return this.repository.getAll(); } public String createApplicationInstance(CreateApplicationInstance command) { final ServiceInstance serviceInstance = command.getServiceInstance(); ApplicationInstance applicationInstance = ApplicationInstance.Builder .forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId()) .baseUri(serviceInstance.getUri()) .build(); return this.repository.save(applicationInstance).getId(); } public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) { this.getById(command.getId()) .ifPresent(applicationInstance -> { applicationInstance.updateHealthStatus(command.getHealthStatus()); this.repository.save(applicationInstance); }); }
public void updateActuatorEndpoints(final UpdateActuatorEndpoints command) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // }
import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import org.springframework.cloud.client.ServiceInstance;
public List<ApplicationInstance> getApplicationInstances() { return this.repository.getAll(); } public String createApplicationInstance(CreateApplicationInstance command) { final ServiceInstance serviceInstance = command.getServiceInstance(); ApplicationInstance applicationInstance = ApplicationInstance.Builder .forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId()) .baseUri(serviceInstance.getUri()) .build(); return this.repository.save(applicationInstance).getId(); } public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) { this.getById(command.getId()) .ifPresent(applicationInstance -> { applicationInstance.updateHealthStatus(command.getHealthStatus()); this.repository.save(applicationInstance); }); } public void updateActuatorEndpoints(final UpdateActuatorEndpoints command) { this.getById(command.getId()) .ifPresent(applicationInstance -> { applicationInstance.updateActuatorEndpoints(command.getActuatorEndpoints()); this.repository.save(applicationInstance); }); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import org.springframework.cloud.client.ServiceInstance; public List<ApplicationInstance> getApplicationInstances() { return this.repository.getAll(); } public String createApplicationInstance(CreateApplicationInstance command) { final ServiceInstance serviceInstance = command.getServiceInstance(); ApplicationInstance applicationInstance = ApplicationInstance.Builder .forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId()) .baseUri(serviceInstance.getUri()) .build(); return this.repository.save(applicationInstance).getId(); } public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) { this.getById(command.getId()) .ifPresent(applicationInstance -> { applicationInstance.updateHealthStatus(command.getHealthStatus()); this.repository.save(applicationInstance); }); } public void updateActuatorEndpoints(final UpdateActuatorEndpoints command) { this.getById(command.getId()) .ifPresent(applicationInstance -> { applicationInstance.updateActuatorEndpoints(command.getActuatorEndpoints()); this.repository.save(applicationInstance); }); }
public void deleteApplicationInstance(final DeleteApplicationInstance command) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // }
import java.net.URI; import java.util.List; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.ServiceInstance; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ @RunWith(MockitoJUnitRunner.class) public class ApplicationInstanceServiceTests { @Mock private ServiceInstance serviceInstance; @Mock private ApplicationInstanceRepository repository; @InjectMocks private ApplicationInstanceService service; @Captor private ArgumentCaptor<ApplicationInstance> applicationInstanceArgumentCaptor; @Test public void shouldRetrieveApplicationInstanceFromRepository() { when(this.serviceInstance.getInstanceId()).thenReturn("a-1"); when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); Optional<String> applicationInstanceId = this.service.getApplicationInstanceIdForServiceInstance(this.serviceInstance); verify(this.repository).getById("a-1"); assertThat(applicationInstanceId).isNotEmpty(); assertThat(applicationInstanceId).get().isEqualTo("a-1"); } @Test public void shouldCreateApplicationInstanceWithoutActuatorEndpointsAndSaveInRepository() { when(this.serviceInstance.getInstanceId()).thenReturn("a-1"); when(this.serviceInstance.getUri()).thenReturn(URI.create("http://localhost:8080")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0));
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java import java.net.URI; import java.util.List; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.ServiceInstance; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ @RunWith(MockitoJUnitRunner.class) public class ApplicationInstanceServiceTests { @Mock private ServiceInstance serviceInstance; @Mock private ApplicationInstanceRepository repository; @InjectMocks private ApplicationInstanceService service; @Captor private ArgumentCaptor<ApplicationInstance> applicationInstanceArgumentCaptor; @Test public void shouldRetrieveApplicationInstanceFromRepository() { when(this.serviceInstance.getInstanceId()).thenReturn("a-1"); when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); Optional<String> applicationInstanceId = this.service.getApplicationInstanceIdForServiceInstance(this.serviceInstance); verify(this.repository).getById("a-1"); assertThat(applicationInstanceId).isNotEmpty(); assertThat(applicationInstanceId).get().isEqualTo("a-1"); } @Test public void shouldCreateApplicationInstanceWithoutActuatorEndpointsAndSaveInRepository() { when(this.serviceInstance.getInstanceId()).thenReturn("a-1"); when(this.serviceInstance.getUri()).thenReturn(URI.create("http://localhost:8080")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0));
CreateApplicationInstance command = new CreateApplicationInstance(this.serviceInstance);
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // }
import java.net.URI; import java.util.List; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.ServiceInstance; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when;
.thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0)); CreateApplicationInstance command = new CreateApplicationInstance(this.serviceInstance); String applicationInstanceId = this.service.createApplicationInstance(command); assertThat(applicationInstanceId).isEqualTo("a-1"); await().untilAsserted(() -> { verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstance).isNotNull(); }); } @Test public void shouldRetrieveAllApplicationInstancesFromRepository() { when(this.repository.getAll()).thenReturn(singletonList(ApplicationInstanceMother.instance("a-1", "a"))); List<ApplicationInstance> applicationInstances = this.service.getApplicationInstances(); verify(this.repository).getAll(); assertThat(applicationInstances).isNotEmpty(); } @Test public void shouldUpdateTheHealthOfAnApplicationInstance() { when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0));
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java import java.net.URI; import java.util.List; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.ServiceInstance; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0)); CreateApplicationInstance command = new CreateApplicationInstance(this.serviceInstance); String applicationInstanceId = this.service.createApplicationInstance(command); assertThat(applicationInstanceId).isEqualTo("a-1"); await().untilAsserted(() -> { verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstance).isNotNull(); }); } @Test public void shouldRetrieveAllApplicationInstancesFromRepository() { when(this.repository.getAll()).thenReturn(singletonList(ApplicationInstanceMother.instance("a-1", "a"))); List<ApplicationInstance> applicationInstances = this.service.getApplicationInstances(); verify(this.repository).getAll(); assertThat(applicationInstances).isNotEmpty(); } @Test public void shouldUpdateTheHealthOfAnApplicationInstance() { when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0));
UpdateApplicationInstanceHealth command = new UpdateApplicationInstanceHealth("a-1", Status.UP);
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // }
import java.net.URI; import java.util.List; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.ServiceInstance; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when;
public void shouldRetrieveAllApplicationInstancesFromRepository() { when(this.repository.getAll()).thenReturn(singletonList(ApplicationInstanceMother.instance("a-1", "a"))); List<ApplicationInstance> applicationInstances = this.service.getApplicationInstances(); verify(this.repository).getAll(); assertThat(applicationInstances).isNotEmpty(); } @Test public void shouldUpdateTheHealthOfAnApplicationInstance() { when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0)); UpdateApplicationInstanceHealth command = new UpdateApplicationInstanceHealth("a-1", Status.UP); this.service.updateApplicationInstanceHealth(command); verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstance.getId()).isEqualTo("a-1"); } @Test public void shouldUpdateTheActuatorEndpointsOfAnApplicationInstance() { when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0)); Links links = new Links(new Link("http://localhost:8080/actuator/health", "health"));
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java import java.net.URI; import java.util.List; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.ServiceInstance; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; public void shouldRetrieveAllApplicationInstancesFromRepository() { when(this.repository.getAll()).thenReturn(singletonList(ApplicationInstanceMother.instance("a-1", "a"))); List<ApplicationInstance> applicationInstances = this.service.getApplicationInstances(); verify(this.repository).getAll(); assertThat(applicationInstances).isNotEmpty(); } @Test public void shouldUpdateTheHealthOfAnApplicationInstance() { when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0)); UpdateApplicationInstanceHealth command = new UpdateApplicationInstanceHealth("a-1", Status.UP); this.service.updateApplicationInstanceHealth(command); verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstance.getId()).isEqualTo("a-1"); } @Test public void shouldUpdateTheActuatorEndpointsOfAnApplicationInstance() { when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0)); Links links = new Links(new Link("http://localhost:8080/actuator/health", "health"));
UpdateActuatorEndpoints command = new UpdateActuatorEndpoints("a-1", links);
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // }
import java.net.URI; import java.util.List; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.ServiceInstance; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when;
verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstance.getId()).isEqualTo("a-1"); } @Test public void shouldUpdateTheActuatorEndpointsOfAnApplicationInstance() { when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0)); Links links = new Links(new Link("http://localhost:8080/actuator/health", "health")); UpdateActuatorEndpoints command = new UpdateActuatorEndpoints("a-1", links); this.service.updateActuatorEndpoints(command); verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstance.getId()).isEqualTo("a-1"); assertThat(applicationInstance.getActuatorEndpoints()).hasSize(1); assertThat(applicationInstance.getActuatorEndpoint("health")).get().isInstanceOfSatisfying(Link.class, link -> assertThat(link.getHref()).isEqualTo("http://localhost:8080/actuator/health")); } @Test public void shouldDeleteApplicationInstanceAndSaveInRepository() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); applicationInstance.markChangesAsCommitted(); when(this.repository.getById("a-1")).thenReturn(applicationInstance);
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java import java.net.URI; import java.util.List; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.ServiceInstance; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstance.getId()).isEqualTo("a-1"); } @Test public void shouldUpdateTheActuatorEndpointsOfAnApplicationInstance() { when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0)); Links links = new Links(new Link("http://localhost:8080/actuator/health", "health")); UpdateActuatorEndpoints command = new UpdateActuatorEndpoints("a-1", links); this.service.updateActuatorEndpoints(command); verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstance.getId()).isEqualTo("a-1"); assertThat(applicationInstance.getActuatorEndpoints()).hasSize(1); assertThat(applicationInstance.getActuatorEndpoint("health")).get().isInstanceOfSatisfying(Link.class, link -> assertThat(link.getHref()).isEqualTo("http://localhost:8080/actuator/health")); } @Test public void shouldDeleteApplicationInstanceAndSaveInRepository() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); applicationInstance.markChangesAsCommitted(); when(this.repository.getById("a-1")).thenReturn(applicationInstance);
DeleteApplicationInstance command = new DeleteApplicationInstance("a-1");
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // }
import java.net.URI; import java.util.List; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.ServiceInstance; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when;
when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0)); Links links = new Links(new Link("http://localhost:8080/actuator/health", "health")); UpdateActuatorEndpoints command = new UpdateActuatorEndpoints("a-1", links); this.service.updateActuatorEndpoints(command); verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstance.getId()).isEqualTo("a-1"); assertThat(applicationInstance.getActuatorEndpoints()).hasSize(1); assertThat(applicationInstance.getActuatorEndpoint("health")).get().isInstanceOfSatisfying(Link.class, link -> assertThat(link.getHref()).isEqualTo("http://localhost:8080/actuator/health")); } @Test public void shouldDeleteApplicationInstanceAndSaveInRepository() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); applicationInstance.markChangesAsCommitted(); when(this.repository.getById("a-1")).thenReturn(applicationInstance); DeleteApplicationInstance command = new DeleteApplicationInstance("a-1"); this.service.deleteApplicationInstance(command); verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstanceToBeSaved = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstanceToBeSaved.getId()).isEqualTo("a-1"); assertThat(applicationInstanceToBeSaved.getUncommittedChanges()).hasSize(1); assertThat(applicationInstanceToBeSaved.getUncommittedChanges().get(0))
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceServiceTests.java import java.net.URI; import java.util.List; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import org.springframework.boot.actuate.health.Status; import org.springframework.cloud.client.ServiceInstance; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a")); when(this.repository.save(any(ApplicationInstance.class))) .thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0)); Links links = new Links(new Link("http://localhost:8080/actuator/health", "health")); UpdateActuatorEndpoints command = new UpdateActuatorEndpoints("a-1", links); this.service.updateActuatorEndpoints(command); verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstance.getId()).isEqualTo("a-1"); assertThat(applicationInstance.getActuatorEndpoints()).hasSize(1); assertThat(applicationInstance.getActuatorEndpoint("health")).get().isInstanceOfSatisfying(Link.class, link -> assertThat(link.getHref()).isEqualTo("http://localhost:8080/actuator/health")); } @Test public void shouldDeleteApplicationInstanceAndSaveInRepository() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); applicationInstance.markChangesAsCommitted(); when(this.repository.getById("a-1")).thenReturn(applicationInstance); DeleteApplicationInstance command = new DeleteApplicationInstance("a-1"); this.service.deleteApplicationInstance(command); verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture()); ApplicationInstance applicationInstanceToBeSaved = this.applicationInstanceArgumentCaptor.getValue(); assertThat(applicationInstanceToBeSaved.getId()).isEqualTo("a-1"); assertThat(applicationInstanceToBeSaved.getUncommittedChanges()).hasSize(1); assertThat(applicationInstanceToBeSaved.getUncommittedChanges().get(0))
.isInstanceOf(ApplicationInstanceDeleted.class);
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/security/SecurityConfigurationTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/configuration/CommonConfiguration.java // @Configuration // public class CommonConfiguration { // // @Bean("machine-to-machine-web-client") // public WebClient m2mWebClient(List<MachineToMachineWebClientConfigurer> configurers) { // WebClient.Builder builder = WebClient.builder() // .apply(this::applyWebClientResponseExceptionFilter); // configurers.forEach(builder::apply); // return builder.build(); // } // // private void applyWebClientResponseExceptionFilter(WebClient.Builder builder) { // builder.filter(ExchangeFilterFunctions.statusError(HttpStatus::isError, // WebClientResponseExceptionCreator::createResponseException)); // } // // }
import org.junit.Test; import be.ordina.msdashboard.configuration.CommonConfiguration; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository; import static org.assertj.core.api.Assertions.assertThat;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.security; /** * @author Tim Ysewyn */ public class SecurityConfigurationTests { private static final String BASIC_PREFIX = "ms-dashboard.security.basic.client"; private static final String REGISTRATION_PREFIX = "spring.security.oauth2.client.registration.ms-dashboard"; private static final String PROVIDER_PREFIX = "spring.security.oauth2.client.provider"; private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of( SecurityConfiguration.class,
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/configuration/CommonConfiguration.java // @Configuration // public class CommonConfiguration { // // @Bean("machine-to-machine-web-client") // public WebClient m2mWebClient(List<MachineToMachineWebClientConfigurer> configurers) { // WebClient.Builder builder = WebClient.builder() // .apply(this::applyWebClientResponseExceptionFilter); // configurers.forEach(builder::apply); // return builder.build(); // } // // private void applyWebClientResponseExceptionFilter(WebClient.Builder builder) { // builder.filter(ExchangeFilterFunctions.statusError(HttpStatus::isError, // WebClientResponseExceptionCreator::createResponseException)); // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/security/SecurityConfigurationTests.java import org.junit.Test; import be.ordina.msdashboard.configuration.CommonConfiguration; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository; import static org.assertj.core.api.Assertions.assertThat; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.security; /** * @author Tim Ysewyn */ public class SecurityConfigurationTests { private static final String BASIC_PREFIX = "ms-dashboard.security.basic.client"; private static final String REGISTRATION_PREFIX = "spring.security.oauth2.client.registration.ms-dashboard"; private static final String PROVIDER_PREFIX = "spring.security.oauth2.client.provider"; private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of( SecurityConfiguration.class,
CommonConfiguration.class));
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/security/SecurityConfiguration.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/configuration/MachineToMachineWebClientConfigurer.java // @FunctionalInterface // public interface MachineToMachineWebClientConfigurer extends Consumer<WebClient.Builder> { // // // No additional methods // // }
import org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository; import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository; import org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction; import org.springframework.security.oauth2.client.web.server.UnAuthenticatedServerOAuth2AuthorizedClientRepository; import org.springframework.web.reactive.function.client.ExchangeFilterFunctions; import java.util.ArrayList; import java.util.List; import be.ordina.msdashboard.configuration.MachineToMachineWebClientConfigurer; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.security.oauth2.client.ClientsConfiguredCondition; import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties; import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.security.oauth2.client.registration.ClientRegistration;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.security; /** * Class that contains all security related configuration. * * @author Tim Ysewyn */ @Configuration @EnableConfigurationProperties({ BasicClientSecurityProperties.class, OAuth2ClientProperties.class }) public class SecurityConfiguration { private static final String CLIENT_NAME = "ms-dashboard-m2m"; @Bean("ms-dashboard-m2m-basic-filter") @Conditional(BasicClientSecurityConfigured.class)
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/configuration/MachineToMachineWebClientConfigurer.java // @FunctionalInterface // public interface MachineToMachineWebClientConfigurer extends Consumer<WebClient.Builder> { // // // No additional methods // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/security/SecurityConfiguration.java import org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository; import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository; import org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction; import org.springframework.security.oauth2.client.web.server.UnAuthenticatedServerOAuth2AuthorizedClientRepository; import org.springframework.web.reactive.function.client.ExchangeFilterFunctions; import java.util.ArrayList; import java.util.List; import be.ordina.msdashboard.configuration.MachineToMachineWebClientConfigurer; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.security.oauth2.client.ClientsConfiguredCondition; import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties; import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.security.oauth2.client.registration.ClientRegistration; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.security; /** * Class that contains all security related configuration. * * @author Tim Ysewyn */ @Configuration @EnableConfigurationProperties({ BasicClientSecurityProperties.class, OAuth2ClientProperties.class }) public class SecurityConfiguration { private static final String CLIENT_NAME = "ms-dashboard-m2m"; @Bean("ms-dashboard-m2m-basic-filter") @Conditional(BasicClientSecurityConfigured.class)
MachineToMachineWebClientConfigurer basicFilter(BasicClientSecurityProperties properties) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/eventstore/InMemoryEventStoreConfiguration.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceRepository.java // public interface ApplicationInstanceRepository { // // List<ApplicationInstance> getAll(); // // ApplicationInstance getById(String id); // // ApplicationInstance save(ApplicationInstance applicationInstance); // // }
import be.ordina.msdashboard.applicationinstance.ApplicationInstanceRepository; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.eventstore; /** * Auto-configuration for the in-memory event store. * * @author Tim Ysewyn */ @Configuration public class InMemoryEventStoreConfiguration { @Bean @ConditionalOnMissingBean
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceRepository.java // public interface ApplicationInstanceRepository { // // List<ApplicationInstance> getAll(); // // ApplicationInstance getById(String id); // // ApplicationInstance save(ApplicationInstance applicationInstance); // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/eventstore/InMemoryEventStoreConfiguration.java import be.ordina.msdashboard.applicationinstance.ApplicationInstanceRepository; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.eventstore; /** * Auto-configuration for the in-memory event store. * * @author Tim Ysewyn */ @Configuration public class InMemoryEventStoreConfiguration { @Bean @ConditionalOnMissingBean
public ApplicationInstanceRepository applicationInstanceRepository(ApplicationEventPublisher publisher) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcher.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.reactive.function.client.WebClient; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Watcher that will check an application instance its health endpoint. * * @author Dieter Hubau * @author Tim Ysewyn */ public class ApplicationInstanceHealthWatcher { private static final Logger logger = LoggerFactory.getLogger(ApplicationInstanceHealthWatcher.class); private final WebClient webClient; private final ApplicationInstanceService applicationInstanceService; private final ApplicationEventPublisher publisher; ApplicationInstanceHealthWatcher(ApplicationInstanceService applicationInstanceService, WebClient webClient, ApplicationEventPublisher publisher) { this.applicationInstanceService = applicationInstanceService; this.webClient = webClient; this.publisher = publisher; }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcher.java import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.reactive.function.client.WebClient; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Watcher that will check an application instance its health endpoint. * * @author Dieter Hubau * @author Tim Ysewyn */ public class ApplicationInstanceHealthWatcher { private static final Logger logger = LoggerFactory.getLogger(ApplicationInstanceHealthWatcher.class); private final WebClient webClient; private final ApplicationInstanceService applicationInstanceService; private final ApplicationEventPublisher publisher; ApplicationInstanceHealthWatcher(ApplicationInstanceService applicationInstanceService, WebClient webClient, ApplicationEventPublisher publisher) { this.applicationInstanceService = applicationInstanceService; this.webClient = webClient; this.publisher = publisher; }
@EventListener({ ActuatorEndpointsUpdated.class })
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcher.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.reactive.function.client.WebClient; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health;
this.webClient = webClient; this.publisher = publisher; } @EventListener({ ActuatorEndpointsUpdated.class }) public void retrieveHealthData(ActuatorEndpointsUpdated event) { ApplicationInstance applicationInstance = event.getApplicationInstance(); if (applicationInstance.hasActuatorEndpointFor("health")) { retrieveHealthData(applicationInstance); } } @Scheduled(fixedRateString = "${applicationinstance.healthwatcher.rate:10000}") public void retrieveHealthDataForAllApplicationInstances() { logger.debug("Retrieving [HEALTH] data for all application instances"); this.applicationInstanceService.getApplicationInstances() .parallelStream() .filter(instance -> instance.getState() != ApplicationInstance.State.DELETED) .filter(instance -> instance.hasActuatorEndpointFor("health")) .forEach(this::retrieveHealthData); } private void retrieveHealthData(ApplicationInstance instance) { instance.getActuatorEndpoint("health").ifPresent(link -> { logger.debug("Retrieving [HEALTH] data for {}", instance.getId()); this.webClient.get().uri(link.getHref()).retrieve().bodyToMono(HealthWrapper.class) .defaultIfEmpty(new HealthWrapper(Status.UNKNOWN, new HashMap<>())) .map(HealthWrapper::getHealth) .doOnError(exception -> { logger.debug("Could not retrieve health information for [{}]", link.getHref(), exception);
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcher.java import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.reactive.function.client.WebClient; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; this.webClient = webClient; this.publisher = publisher; } @EventListener({ ActuatorEndpointsUpdated.class }) public void retrieveHealthData(ActuatorEndpointsUpdated event) { ApplicationInstance applicationInstance = event.getApplicationInstance(); if (applicationInstance.hasActuatorEndpointFor("health")) { retrieveHealthData(applicationInstance); } } @Scheduled(fixedRateString = "${applicationinstance.healthwatcher.rate:10000}") public void retrieveHealthDataForAllApplicationInstances() { logger.debug("Retrieving [HEALTH] data for all application instances"); this.applicationInstanceService.getApplicationInstances() .parallelStream() .filter(instance -> instance.getState() != ApplicationInstance.State.DELETED) .filter(instance -> instance.hasActuatorEndpointFor("health")) .forEach(this::retrieveHealthData); } private void retrieveHealthData(ApplicationInstance instance) { instance.getActuatorEndpoint("health").ifPresent(link -> { logger.debug("Retrieving [HEALTH] data for {}", instance.getId()); this.webClient.get().uri(link.getHref()).retrieve().bodyToMono(HealthWrapper.class) .defaultIfEmpty(new HealthWrapper(Status.UNKNOWN, new HashMap<>())) .map(HealthWrapper::getHealth) .doOnError(exception -> { logger.debug("Could not retrieve health information for [{}]", link.getHref(), exception);
this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrievalFailed(instance));
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcher.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.reactive.function.client.WebClient; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health;
@EventListener({ ActuatorEndpointsUpdated.class }) public void retrieveHealthData(ActuatorEndpointsUpdated event) { ApplicationInstance applicationInstance = event.getApplicationInstance(); if (applicationInstance.hasActuatorEndpointFor("health")) { retrieveHealthData(applicationInstance); } } @Scheduled(fixedRateString = "${applicationinstance.healthwatcher.rate:10000}") public void retrieveHealthDataForAllApplicationInstances() { logger.debug("Retrieving [HEALTH] data for all application instances"); this.applicationInstanceService.getApplicationInstances() .parallelStream() .filter(instance -> instance.getState() != ApplicationInstance.State.DELETED) .filter(instance -> instance.hasActuatorEndpointFor("health")) .forEach(this::retrieveHealthData); } private void retrieveHealthData(ApplicationInstance instance) { instance.getActuatorEndpoint("health").ifPresent(link -> { logger.debug("Retrieving [HEALTH] data for {}", instance.getId()); this.webClient.get().uri(link.getHref()).retrieve().bodyToMono(HealthWrapper.class) .defaultIfEmpty(new HealthWrapper(Status.UNKNOWN, new HashMap<>())) .map(HealthWrapper::getHealth) .doOnError(exception -> { logger.debug("Could not retrieve health information for [{}]", link.getHref(), exception); this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrievalFailed(instance)); }) .subscribe(healthInfo -> { logger.debug("Retrieved health information for application instance [{}]", instance.getId());
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcher.java import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.reactive.function.client.WebClient; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; @EventListener({ ActuatorEndpointsUpdated.class }) public void retrieveHealthData(ActuatorEndpointsUpdated event) { ApplicationInstance applicationInstance = event.getApplicationInstance(); if (applicationInstance.hasActuatorEndpointFor("health")) { retrieveHealthData(applicationInstance); } } @Scheduled(fixedRateString = "${applicationinstance.healthwatcher.rate:10000}") public void retrieveHealthDataForAllApplicationInstances() { logger.debug("Retrieving [HEALTH] data for all application instances"); this.applicationInstanceService.getApplicationInstances() .parallelStream() .filter(instance -> instance.getState() != ApplicationInstance.State.DELETED) .filter(instance -> instance.hasActuatorEndpointFor("health")) .forEach(this::retrieveHealthData); } private void retrieveHealthData(ApplicationInstance instance) { instance.getActuatorEndpoint("health").ifPresent(link -> { logger.debug("Retrieving [HEALTH] data for {}", instance.getId()); this.webClient.get().uri(link.getHref()).retrieve().bodyToMono(HealthWrapper.class) .defaultIfEmpty(new HealthWrapper(Status.UNKNOWN, new HashMap<>())) .map(HealthWrapper::getHealth) .doOnError(exception -> { logger.debug("Could not retrieve health information for [{}]", link.getHref(), exception); this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrievalFailed(instance)); }) .subscribe(healthInfo -> { logger.debug("Retrieved health information for application instance [{}]", instance.getId());
this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrieved(instance, healthInfo));
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcher.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.reactive.function.client.WebClient; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health;
@Scheduled(fixedRateString = "${applicationinstance.healthwatcher.rate:10000}") public void retrieveHealthDataForAllApplicationInstances() { logger.debug("Retrieving [HEALTH] data for all application instances"); this.applicationInstanceService.getApplicationInstances() .parallelStream() .filter(instance -> instance.getState() != ApplicationInstance.State.DELETED) .filter(instance -> instance.hasActuatorEndpointFor("health")) .forEach(this::retrieveHealthData); } private void retrieveHealthData(ApplicationInstance instance) { instance.getActuatorEndpoint("health").ifPresent(link -> { logger.debug("Retrieving [HEALTH] data for {}", instance.getId()); this.webClient.get().uri(link.getHref()).retrieve().bodyToMono(HealthWrapper.class) .defaultIfEmpty(new HealthWrapper(Status.UNKNOWN, new HashMap<>())) .map(HealthWrapper::getHealth) .doOnError(exception -> { logger.debug("Could not retrieve health information for [{}]", link.getHref(), exception); this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrievalFailed(instance)); }) .subscribe(healthInfo -> { logger.debug("Retrieved health information for application instance [{}]", instance.getId()); this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrieved(instance, healthInfo)); }); }); } @EventListener({ ApplicationInstanceHealthDataRetrieved.class }) public void updateHealthForApplicationInstance(ApplicationInstanceHealthDataRetrieved event) {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcher.java import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.reactive.function.client.WebClient; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; @Scheduled(fixedRateString = "${applicationinstance.healthwatcher.rate:10000}") public void retrieveHealthDataForAllApplicationInstances() { logger.debug("Retrieving [HEALTH] data for all application instances"); this.applicationInstanceService.getApplicationInstances() .parallelStream() .filter(instance -> instance.getState() != ApplicationInstance.State.DELETED) .filter(instance -> instance.hasActuatorEndpointFor("health")) .forEach(this::retrieveHealthData); } private void retrieveHealthData(ApplicationInstance instance) { instance.getActuatorEndpoint("health").ifPresent(link -> { logger.debug("Retrieving [HEALTH] data for {}", instance.getId()); this.webClient.get().uri(link.getHref()).retrieve().bodyToMono(HealthWrapper.class) .defaultIfEmpty(new HealthWrapper(Status.UNKNOWN, new HashMap<>())) .map(HealthWrapper::getHealth) .doOnError(exception -> { logger.debug("Could not retrieve health information for [{}]", link.getHref(), exception); this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrievalFailed(instance)); }) .subscribe(healthInfo -> { logger.debug("Retrieved health information for application instance [{}]", instance.getId()); this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrieved(instance, healthInfo)); }); }); } @EventListener({ ApplicationInstanceHealthDataRetrieved.class }) public void updateHealthForApplicationInstance(ApplicationInstanceHealthDataRetrieved event) {
UpdateApplicationInstanceHealth command =
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/api/CatalogController.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // }
import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import org.springframework.hateoas.ExposesResourceFor; import org.springframework.hateoas.Resource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.api; /** * Controller that exposes the catalog. * * @author Tim Ysewyn */ @ExposesResourceFor(CatalogResource.class) @RestController @RequestMapping("/catalog") public class CatalogController {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/api/CatalogController.java import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import org.springframework.hateoas.ExposesResourceFor; import org.springframework.hateoas.Resource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.api; /** * Controller that exposes the catalog. * * @author Tim Ysewyn */ @ExposesResourceFor(CatalogResource.class) @RestController @RequestMapping("/catalog") public class CatalogController {
private final CatalogService service;
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/api/CatalogController.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // }
import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import org.springframework.hateoas.ExposesResourceFor; import org.springframework.hateoas.Resource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.api; /** * Controller that exposes the catalog. * * @author Tim Ysewyn */ @ExposesResourceFor(CatalogResource.class) @RestController @RequestMapping("/catalog") public class CatalogController { private final CatalogService service; public CatalogController(CatalogService service) { this.service = service; } @GetMapping public CatalogResource getCatalog() {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/api/CatalogController.java import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import org.springframework.hateoas.ExposesResourceFor; import org.springframework.hateoas.Resource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.api; /** * Controller that exposes the catalog. * * @author Tim Ysewyn */ @ExposesResourceFor(CatalogResource.class) @RestController @RequestMapping("/catalog") public class CatalogController { private final CatalogService service; public CatalogController(CatalogService service) { this.service = service; } @GetMapping public CatalogResource getCatalog() {
Catalog catalog = this.service.getCatalog();
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/eventstore/EventSourcedApplicationInstanceRepository.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceRepository.java // public interface ApplicationInstanceRepository { // // List<ApplicationInstance> getAll(); // // ApplicationInstance getById(String id); // // ApplicationInstance save(ApplicationInstance applicationInstance); // // }
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import be.ordina.msdashboard.applicationinstance.ApplicationInstance; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceRepository; import org.springframework.context.ApplicationEventPublisher;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.eventstore; /** * In-memory event sourced {@link ApplicationInstanceRepository application instance repository}. * * @author Tim Ysewyn */ class EventSourcedApplicationInstanceRepository implements ApplicationInstanceRepository { private final ApplicationEventPublisher applicationEventPublisher;
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceRepository.java // public interface ApplicationInstanceRepository { // // List<ApplicationInstance> getAll(); // // ApplicationInstance getById(String id); // // ApplicationInstance save(ApplicationInstance applicationInstance); // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/eventstore/EventSourcedApplicationInstanceRepository.java import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import be.ordina.msdashboard.applicationinstance.ApplicationInstance; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceRepository; import org.springframework.context.ApplicationEventPublisher; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.eventstore; /** * In-memory event sourced {@link ApplicationInstanceRepository application instance repository}. * * @author Tim Ysewyn */ class EventSourcedApplicationInstanceRepository implements ApplicationInstanceRepository { private final ApplicationEventPublisher applicationEventPublisher;
private final Map<String, ApplicationInstance> applicationInstances = new HashMap<>();
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // }
import be.ordina.msdashboard.applicationinstance.ApplicationInstance; import org.springframework.boot.actuate.health.Health; import org.springframework.context.ApplicationEvent;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance.events; /** * An {@link ApplicationEvent application event} which signals successful retrieval of an instance its health data. * * @author Dieter Hubau */ public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { private Health health;
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java import be.ordina.msdashboard.applicationinstance.ApplicationInstance; import org.springframework.boot.actuate.health.Health; import org.springframework.context.ApplicationEvent; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance.events; /** * An {@link ApplicationEvent application event} which signals successful retrieval of an instance its health data. * * @author Dieter Hubau */ public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { private Health health;
public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/autoconfigure/AutoConfigurationTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcher.java // public class ApplicationInstanceHealthWatcher { // // private static final Logger logger = LoggerFactory.getLogger(ApplicationInstanceHealthWatcher.class); // // private final WebClient webClient; // private final ApplicationInstanceService applicationInstanceService; // private final ApplicationEventPublisher publisher; // // ApplicationInstanceHealthWatcher(ApplicationInstanceService applicationInstanceService, // WebClient webClient, ApplicationEventPublisher publisher) { // this.applicationInstanceService = applicationInstanceService; // this.webClient = webClient; // this.publisher = publisher; // } // // @EventListener({ ActuatorEndpointsUpdated.class }) // public void retrieveHealthData(ActuatorEndpointsUpdated event) { // ApplicationInstance applicationInstance = event.getApplicationInstance(); // if (applicationInstance.hasActuatorEndpointFor("health")) { // retrieveHealthData(applicationInstance); // } // } // // @Scheduled(fixedRateString = "${applicationinstance.healthwatcher.rate:10000}") // public void retrieveHealthDataForAllApplicationInstances() { // logger.debug("Retrieving [HEALTH] data for all application instances"); // this.applicationInstanceService.getApplicationInstances() // .parallelStream() // .filter(instance -> instance.getState() != ApplicationInstance.State.DELETED) // .filter(instance -> instance.hasActuatorEndpointFor("health")) // .forEach(this::retrieveHealthData); // } // // private void retrieveHealthData(ApplicationInstance instance) { // instance.getActuatorEndpoint("health").ifPresent(link -> { // logger.debug("Retrieving [HEALTH] data for {}", instance.getId()); // this.webClient.get().uri(link.getHref()).retrieve().bodyToMono(HealthWrapper.class) // .defaultIfEmpty(new HealthWrapper(Status.UNKNOWN, new HashMap<>())) // .map(HealthWrapper::getHealth) // .doOnError(exception -> { // logger.debug("Could not retrieve health information for [{}]", link.getHref(), exception); // this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrievalFailed(instance)); // }) // .subscribe(healthInfo -> { // logger.debug("Retrieved health information for application instance [{}]", instance.getId()); // this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrieved(instance, healthInfo)); // }); // }); // } // // @EventListener({ ApplicationInstanceHealthDataRetrieved.class }) // public void updateHealthForApplicationInstance(ApplicationInstanceHealthDataRetrieved event) { // UpdateApplicationInstanceHealth command = // new UpdateApplicationInstanceHealth(event.getApplicationInstance().getId(), // event.getHealth().getStatus()); // this.applicationInstanceService.updateApplicationInstanceHealth(command); // } // // /** // * Wrapper for the Health class since it doesn't have correct constructors for // * Jackson. // */ // static class HealthWrapper { // // private Health health; // // @JsonCreator // HealthWrapper(@JsonProperty("status") Status status, @JsonProperty("details") Map<String, Object> details) { // this.health = Health.status(status).withDetails(details == null ? new HashMap<>() : details).build(); // } // // private Health getHealth() { // return this.health; // } // // } // // }
import org.junit.Test; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceHealthWatcher; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClientAutoConfiguration; import static org.assertj.core.api.Assertions.assertThat;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.autoconfigure; /** * @author Tim Ysewyn */ public class AutoConfigurationTests { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of( MicroservicesDashboardServerAutoConfiguration.class, CompositeDiscoveryClientAutoConfiguration.class)); @Test public void shouldLoadContext() { this.contextRunner.run(context -> {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcher.java // public class ApplicationInstanceHealthWatcher { // // private static final Logger logger = LoggerFactory.getLogger(ApplicationInstanceHealthWatcher.class); // // private final WebClient webClient; // private final ApplicationInstanceService applicationInstanceService; // private final ApplicationEventPublisher publisher; // // ApplicationInstanceHealthWatcher(ApplicationInstanceService applicationInstanceService, // WebClient webClient, ApplicationEventPublisher publisher) { // this.applicationInstanceService = applicationInstanceService; // this.webClient = webClient; // this.publisher = publisher; // } // // @EventListener({ ActuatorEndpointsUpdated.class }) // public void retrieveHealthData(ActuatorEndpointsUpdated event) { // ApplicationInstance applicationInstance = event.getApplicationInstance(); // if (applicationInstance.hasActuatorEndpointFor("health")) { // retrieveHealthData(applicationInstance); // } // } // // @Scheduled(fixedRateString = "${applicationinstance.healthwatcher.rate:10000}") // public void retrieveHealthDataForAllApplicationInstances() { // logger.debug("Retrieving [HEALTH] data for all application instances"); // this.applicationInstanceService.getApplicationInstances() // .parallelStream() // .filter(instance -> instance.getState() != ApplicationInstance.State.DELETED) // .filter(instance -> instance.hasActuatorEndpointFor("health")) // .forEach(this::retrieveHealthData); // } // // private void retrieveHealthData(ApplicationInstance instance) { // instance.getActuatorEndpoint("health").ifPresent(link -> { // logger.debug("Retrieving [HEALTH] data for {}", instance.getId()); // this.webClient.get().uri(link.getHref()).retrieve().bodyToMono(HealthWrapper.class) // .defaultIfEmpty(new HealthWrapper(Status.UNKNOWN, new HashMap<>())) // .map(HealthWrapper::getHealth) // .doOnError(exception -> { // logger.debug("Could not retrieve health information for [{}]", link.getHref(), exception); // this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrievalFailed(instance)); // }) // .subscribe(healthInfo -> { // logger.debug("Retrieved health information for application instance [{}]", instance.getId()); // this.publisher.publishEvent(new ApplicationInstanceHealthDataRetrieved(instance, healthInfo)); // }); // }); // } // // @EventListener({ ApplicationInstanceHealthDataRetrieved.class }) // public void updateHealthForApplicationInstance(ApplicationInstanceHealthDataRetrieved event) { // UpdateApplicationInstanceHealth command = // new UpdateApplicationInstanceHealth(event.getApplicationInstance().getId(), // event.getHealth().getStatus()); // this.applicationInstanceService.updateApplicationInstanceHealth(command); // } // // /** // * Wrapper for the Health class since it doesn't have correct constructors for // * Jackson. // */ // static class HealthWrapper { // // private Health health; // // @JsonCreator // HealthWrapper(@JsonProperty("status") Status status, @JsonProperty("details") Map<String, Object> details) { // this.health = Health.status(status).withDetails(details == null ? new HashMap<>() : details).build(); // } // // private Health getHealth() { // return this.health; // } // // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/autoconfigure/AutoConfigurationTests.java import org.junit.Test; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceHealthWatcher; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClientAutoConfiguration; import static org.assertj.core.api.Assertions.assertThat; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.autoconfigure; /** * @author Tim Ysewyn */ public class AutoConfigurationTests { private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of( MicroservicesDashboardServerAutoConfiguration.class, CompositeDiscoveryClientAutoConfiguration.class)); @Test public void shouldLoadContext() { this.contextRunner.run(context -> {
assertThat(context.getBean(ApplicationInstanceHealthWatcher.class)).isNotNull();
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // }
import java.net.URI; import org.junit.Test; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static org.assertj.core.api.Assertions.assertThat;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ public class ApplicationInstanceTests { @Test public void newlyCreatedInstanceShouldHaveOneUncommittedChange() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); assertThat(applicationInstance.getState()).isEqualTo(ApplicationInstance.State.CREATED); assertThat(applicationInstance.getUncommittedChanges()).hasSize(1); } @Test public void instanceShouldHaveNoUncommittedChangesAfterBeingMarkedAsCommitted() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); applicationInstance.markChangesAsCommitted(); assertThat(applicationInstance.getUncommittedChanges()).isEmpty(); } @Test public void newlyCreatedInstanceShouldHaveUnknownHealthStatus() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UNKNOWN); } @Test public void instanceShouldNotUpdateItsHealthStatusAgainIfNotChanged() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); applicationInstance.markChangesAsCommitted(); assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UNKNOWN); applicationInstance.updateHealthStatus(Status.UP); assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UP); assertThat(applicationInstance.getUncommittedChanges()).hasSize(1); assertThat(applicationInstance.getUncommittedChanges().get(0))
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceTests.java import java.net.URI; import org.junit.Test; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static org.assertj.core.api.Assertions.assertThat; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ public class ApplicationInstanceTests { @Test public void newlyCreatedInstanceShouldHaveOneUncommittedChange() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); assertThat(applicationInstance.getState()).isEqualTo(ApplicationInstance.State.CREATED); assertThat(applicationInstance.getUncommittedChanges()).hasSize(1); } @Test public void instanceShouldHaveNoUncommittedChangesAfterBeingMarkedAsCommitted() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); applicationInstance.markChangesAsCommitted(); assertThat(applicationInstance.getUncommittedChanges()).isEmpty(); } @Test public void newlyCreatedInstanceShouldHaveUnknownHealthStatus() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UNKNOWN); } @Test public void instanceShouldNotUpdateItsHealthStatusAgainIfNotChanged() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); applicationInstance.markChangesAsCommitted(); assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UNKNOWN); applicationInstance.updateHealthStatus(Status.UP); assertThat(applicationInstance.getHealthStatus()).isEqualTo(Status.UP); assertThat(applicationInstance.getUncommittedChanges()).hasSize(1); assertThat(applicationInstance.getUncommittedChanges().get(0))
.isInstanceOf(ApplicationInstanceHealthUpdated.class);
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // }
import java.net.URI; import org.junit.Test; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static org.assertj.core.api.Assertions.assertThat;
public void undefinedActuatorEndpointWillReturnEmptyOptional() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a", URI.create("http://localhost:8080"), new Links(new Link("http://localhost:8080/actuator/health", "health"))); assertThat(applicationInstance.hasActuatorEndpointFor("not-defined-endpoint")).isFalse(); assertThat(applicationInstance.getActuatorEndpoint("not-defined-endpoint")).isEmpty(); } @Test public void definedActuatorEndpointWillReturnLink() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a", URI.create("http://localhost:8080"), new Links(new Link("http://localhost:8080/actuator/health", "health"))); assertThat(applicationInstance.hasActuatorEndpointFor("health")).isTrue(); assertThat(applicationInstance.getActuatorEndpoint("health")).isNotEmpty(); assertThat(applicationInstance.getActuatorEndpoint("health")) .get().extracting(Link::getHref).isEqualTo("http://localhost:8080/actuator/health"); } @Test public void canNotBeDeletedMoreThanOnce() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); applicationInstance.markChangesAsCommitted(); applicationInstance.delete(); applicationInstance.delete(); assertThat(applicationInstance.getState()).isEqualTo(ApplicationInstance.State.DELETED); assertThat(applicationInstance.getUncommittedChanges()).hasSize(1);
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceTests.java import java.net.URI; import org.junit.Test; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import static org.assertj.core.api.Assertions.assertThat; public void undefinedActuatorEndpointWillReturnEmptyOptional() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a", URI.create("http://localhost:8080"), new Links(new Link("http://localhost:8080/actuator/health", "health"))); assertThat(applicationInstance.hasActuatorEndpointFor("not-defined-endpoint")).isFalse(); assertThat(applicationInstance.getActuatorEndpoint("not-defined-endpoint")).isEmpty(); } @Test public void definedActuatorEndpointWillReturnLink() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a", URI.create("http://localhost:8080"), new Links(new Link("http://localhost:8080/actuator/health", "health"))); assertThat(applicationInstance.hasActuatorEndpointFor("health")).isTrue(); assertThat(applicationInstance.getActuatorEndpoint("health")).isNotEmpty(); assertThat(applicationInstance.getActuatorEndpoint("health")) .get().extracting(Link::getHref).isEqualTo("http://localhost:8080/actuator/health"); } @Test public void canNotBeDeletedMoreThanOnce() { ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a"); applicationInstance.markChangesAsCommitted(); applicationInstance.delete(); applicationInstance.delete(); assertThat(applicationInstance.getState()).isEqualTo(ApplicationInstance.State.DELETED); assertThat(applicationInstance.getUncommittedChanges()).hasSize(1);
assertThat(applicationInstance.getUncommittedChanges().get(0)).isInstanceOf(ApplicationInstanceDeleted.class);
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/api/ApplicationInstanceControllerTests.java
// Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceMother.java // public final class ApplicationInstanceMother { // // private ApplicationInstanceMother() { // throw new RuntimeException("Not allowed"); // } // // public static ApplicationInstance instance(String id, String application) { // return instance(id, application, URI.create("http://localhost:8080")); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri) { // return ApplicationInstance.Builder.forApplicationWithId(application, id).baseUri(baseUri).build(); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri, Links actuatorEndpoints) { // ApplicationInstance applicationInstance = ApplicationInstance.Builder.forApplicationWithId(application, id) // .baseUri(baseUri) // .build(); // applicationInstance.updateActuatorEndpoints(actuatorEndpoints); // return applicationInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java // public class ApplicationInstanceService { // // private final ApplicationInstanceRepository repository; // // public ApplicationInstanceService(ApplicationInstanceRepository repository) { // this.repository = repository; // } // // public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) { // return this.getById(serviceInstance.getInstanceId()) // .map(ApplicationInstance::getId); // } // // public Optional<ApplicationInstance> getById(String id) { // return Optional.ofNullable(this.repository.getById(id)); // } // // public List<ApplicationInstance> getApplicationInstances() { // return this.repository.getAll(); // } // // public String createApplicationInstance(CreateApplicationInstance command) { // final ServiceInstance serviceInstance = command.getServiceInstance(); // ApplicationInstance applicationInstance = ApplicationInstance.Builder // .forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId()) // .baseUri(serviceInstance.getUri()) // .build(); // return this.repository.save(applicationInstance).getId(); // } // // public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.updateHealthStatus(command.getHealthStatus()); // this.repository.save(applicationInstance); // }); // } // // public void updateActuatorEndpoints(final UpdateActuatorEndpoints command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.updateActuatorEndpoints(command.getActuatorEndpoints()); // this.repository.save(applicationInstance); // }); // } // // public void deleteApplicationInstance(final DeleteApplicationInstance command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.delete(); // this.repository.save(applicationInstance); // }); // } // // }
import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.verifyNoMoreInteractions; import static org.mockito.BDDMockito.when; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceMother; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.api; /** * @author Tim Ysewyn */ @RunWith(MockitoJUnitRunner.class) public class ApplicationInstanceControllerTests { @Mock
// Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceMother.java // public final class ApplicationInstanceMother { // // private ApplicationInstanceMother() { // throw new RuntimeException("Not allowed"); // } // // public static ApplicationInstance instance(String id, String application) { // return instance(id, application, URI.create("http://localhost:8080")); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri) { // return ApplicationInstance.Builder.forApplicationWithId(application, id).baseUri(baseUri).build(); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri, Links actuatorEndpoints) { // ApplicationInstance applicationInstance = ApplicationInstance.Builder.forApplicationWithId(application, id) // .baseUri(baseUri) // .build(); // applicationInstance.updateActuatorEndpoints(actuatorEndpoints); // return applicationInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java // public class ApplicationInstanceService { // // private final ApplicationInstanceRepository repository; // // public ApplicationInstanceService(ApplicationInstanceRepository repository) { // this.repository = repository; // } // // public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) { // return this.getById(serviceInstance.getInstanceId()) // .map(ApplicationInstance::getId); // } // // public Optional<ApplicationInstance> getById(String id) { // return Optional.ofNullable(this.repository.getById(id)); // } // // public List<ApplicationInstance> getApplicationInstances() { // return this.repository.getAll(); // } // // public String createApplicationInstance(CreateApplicationInstance command) { // final ServiceInstance serviceInstance = command.getServiceInstance(); // ApplicationInstance applicationInstance = ApplicationInstance.Builder // .forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId()) // .baseUri(serviceInstance.getUri()) // .build(); // return this.repository.save(applicationInstance).getId(); // } // // public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.updateHealthStatus(command.getHealthStatus()); // this.repository.save(applicationInstance); // }); // } // // public void updateActuatorEndpoints(final UpdateActuatorEndpoints command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.updateActuatorEndpoints(command.getActuatorEndpoints()); // this.repository.save(applicationInstance); // }); // } // // public void deleteApplicationInstance(final DeleteApplicationInstance command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.delete(); // this.repository.save(applicationInstance); // }); // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/api/ApplicationInstanceControllerTests.java import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.verifyNoMoreInteractions; import static org.mockito.BDDMockito.when; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceMother; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.api; /** * @author Tim Ysewyn */ @RunWith(MockitoJUnitRunner.class) public class ApplicationInstanceControllerTests { @Mock
private ApplicationInstanceService service;
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/api/ApplicationInstanceControllerTests.java
// Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceMother.java // public final class ApplicationInstanceMother { // // private ApplicationInstanceMother() { // throw new RuntimeException("Not allowed"); // } // // public static ApplicationInstance instance(String id, String application) { // return instance(id, application, URI.create("http://localhost:8080")); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri) { // return ApplicationInstance.Builder.forApplicationWithId(application, id).baseUri(baseUri).build(); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri, Links actuatorEndpoints) { // ApplicationInstance applicationInstance = ApplicationInstance.Builder.forApplicationWithId(application, id) // .baseUri(baseUri) // .build(); // applicationInstance.updateActuatorEndpoints(actuatorEndpoints); // return applicationInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java // public class ApplicationInstanceService { // // private final ApplicationInstanceRepository repository; // // public ApplicationInstanceService(ApplicationInstanceRepository repository) { // this.repository = repository; // } // // public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) { // return this.getById(serviceInstance.getInstanceId()) // .map(ApplicationInstance::getId); // } // // public Optional<ApplicationInstance> getById(String id) { // return Optional.ofNullable(this.repository.getById(id)); // } // // public List<ApplicationInstance> getApplicationInstances() { // return this.repository.getAll(); // } // // public String createApplicationInstance(CreateApplicationInstance command) { // final ServiceInstance serviceInstance = command.getServiceInstance(); // ApplicationInstance applicationInstance = ApplicationInstance.Builder // .forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId()) // .baseUri(serviceInstance.getUri()) // .build(); // return this.repository.save(applicationInstance).getId(); // } // // public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.updateHealthStatus(command.getHealthStatus()); // this.repository.save(applicationInstance); // }); // } // // public void updateActuatorEndpoints(final UpdateActuatorEndpoints command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.updateActuatorEndpoints(command.getActuatorEndpoints()); // this.repository.save(applicationInstance); // }); // } // // public void deleteApplicationInstance(final DeleteApplicationInstance command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.delete(); // this.repository.save(applicationInstance); // }); // } // // }
import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.verifyNoMoreInteractions; import static org.mockito.BDDMockito.when; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceMother; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.api; /** * @author Tim Ysewyn */ @RunWith(MockitoJUnitRunner.class) public class ApplicationInstanceControllerTests { @Mock private ApplicationInstanceService service; @InjectMocks private ApplicationInstanceController controller; @Test public void shouldReturn404ForUnknownApplicationInstance() { ResponseEntity response = this.controller.getApplicationInstanceById("unknown"); assertThat(response).isNotNull(); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); verify(this.service).getById("unknown"); verifyNoMoreInteractions(this.service); } @Test public void shouldReturn200ForKnownApplicationInstance() { when(this.service.getById("a-1"))
// Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceMother.java // public final class ApplicationInstanceMother { // // private ApplicationInstanceMother() { // throw new RuntimeException("Not allowed"); // } // // public static ApplicationInstance instance(String id, String application) { // return instance(id, application, URI.create("http://localhost:8080")); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri) { // return ApplicationInstance.Builder.forApplicationWithId(application, id).baseUri(baseUri).build(); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri, Links actuatorEndpoints) { // ApplicationInstance applicationInstance = ApplicationInstance.Builder.forApplicationWithId(application, id) // .baseUri(baseUri) // .build(); // applicationInstance.updateActuatorEndpoints(actuatorEndpoints); // return applicationInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceService.java // public class ApplicationInstanceService { // // private final ApplicationInstanceRepository repository; // // public ApplicationInstanceService(ApplicationInstanceRepository repository) { // this.repository = repository; // } // // public Optional<String> getApplicationInstanceIdForServiceInstance(ServiceInstance serviceInstance) { // return this.getById(serviceInstance.getInstanceId()) // .map(ApplicationInstance::getId); // } // // public Optional<ApplicationInstance> getById(String id) { // return Optional.ofNullable(this.repository.getById(id)); // } // // public List<ApplicationInstance> getApplicationInstances() { // return this.repository.getAll(); // } // // public String createApplicationInstance(CreateApplicationInstance command) { // final ServiceInstance serviceInstance = command.getServiceInstance(); // ApplicationInstance applicationInstance = ApplicationInstance.Builder // .forApplicationWithId(serviceInstance.getServiceId(), serviceInstance.getInstanceId()) // .baseUri(serviceInstance.getUri()) // .build(); // return this.repository.save(applicationInstance).getId(); // } // // public void updateApplicationInstanceHealth(final UpdateApplicationInstanceHealth command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.updateHealthStatus(command.getHealthStatus()); // this.repository.save(applicationInstance); // }); // } // // public void updateActuatorEndpoints(final UpdateActuatorEndpoints command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.updateActuatorEndpoints(command.getActuatorEndpoints()); // this.repository.save(applicationInstance); // }); // } // // public void deleteApplicationInstance(final DeleteApplicationInstance command) { // this.getById(command.getId()) // .ifPresent(applicationInstance -> { // applicationInstance.delete(); // this.repository.save(applicationInstance); // }); // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/api/ApplicationInstanceControllerTests.java import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.verifyNoMoreInteractions; import static org.mockito.BDDMockito.when; import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceMother; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.api; /** * @author Tim Ysewyn */ @RunWith(MockitoJUnitRunner.class) public class ApplicationInstanceControllerTests { @Mock private ApplicationInstanceService service; @InjectMocks private ApplicationInstanceController controller; @Test public void shouldReturn404ForUnknownApplicationInstance() { ResponseEntity response = this.controller.getApplicationInstanceById("unknown"); assertThat(response).isNotNull(); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); verify(this.service).getById("unknown"); verifyNoMoreInteractions(this.service); } @Test public void shouldReturn200ForKnownApplicationInstance() { when(this.service.getById("a-1"))
.thenReturn(Optional.of(ApplicationInstanceMother.instance("a-1", "a")));
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogUpdater.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // }
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import org.springframework.context.event.EventListener;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Will update the {@link Catalog catalog} based on events that are happening throughout the system. * * @author Tim Ysewyn */ class CatalogUpdater { private final CatalogService catalogService; CatalogUpdater(CatalogService catalogService) { this.catalogService = catalogService; }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogUpdater.java import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import org.springframework.context.event.EventListener; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Will update the {@link Catalog catalog} based on events that are happening throughout the system. * * @author Tim Ysewyn */ class CatalogUpdater { private final CatalogService catalogService; CatalogUpdater(CatalogService catalogService) { this.catalogService = catalogService; }
@EventListener(ServiceDiscovered.class)
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogUpdater.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // }
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import org.springframework.context.event.EventListener;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Will update the {@link Catalog catalog} based on events that are happening throughout the system. * * @author Tim Ysewyn */ class CatalogUpdater { private final CatalogService catalogService; CatalogUpdater(CatalogService catalogService) { this.catalogService = catalogService; } @EventListener(ServiceDiscovered.class) public void addNewApplicationToCatalog(ServiceDiscovered event) { this.catalogService.addApplicationToCatalog(event.getService()); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogUpdater.java import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import org.springframework.context.event.EventListener; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Will update the {@link Catalog catalog} based on events that are happening throughout the system. * * @author Tim Ysewyn */ class CatalogUpdater { private final CatalogService catalogService; CatalogUpdater(CatalogService catalogService) { this.catalogService = catalogService; } @EventListener(ServiceDiscovered.class) public void addNewApplicationToCatalog(ServiceDiscovered event) { this.catalogService.addApplicationToCatalog(event.getService()); }
@EventListener(ServiceDisappeared.class)
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogUpdater.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // }
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import org.springframework.context.event.EventListener;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Will update the {@link Catalog catalog} based on events that are happening throughout the system. * * @author Tim Ysewyn */ class CatalogUpdater { private final CatalogService catalogService; CatalogUpdater(CatalogService catalogService) { this.catalogService = catalogService; } @EventListener(ServiceDiscovered.class) public void addNewApplicationToCatalog(ServiceDiscovered event) { this.catalogService.addApplicationToCatalog(event.getService()); } @EventListener(ServiceDisappeared.class) public void removeApplicationFromCatalog(ServiceDisappeared event) { this.catalogService.removeApplicationFromCatalog(event.getService()); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogUpdater.java import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import org.springframework.context.event.EventListener; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Will update the {@link Catalog catalog} based on events that are happening throughout the system. * * @author Tim Ysewyn */ class CatalogUpdater { private final CatalogService catalogService; CatalogUpdater(CatalogService catalogService) { this.catalogService = catalogService; } @EventListener(ServiceDiscovered.class) public void addNewApplicationToCatalog(ServiceDiscovered event) { this.catalogService.addApplicationToCatalog(event.getService()); } @EventListener(ServiceDisappeared.class) public void removeApplicationFromCatalog(ServiceDisappeared event) { this.catalogService.removeApplicationFromCatalog(event.getService()); }
@EventListener(ApplicationInstanceCreated.class)
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogUpdater.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // }
import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import org.springframework.context.event.EventListener;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Will update the {@link Catalog catalog} based on events that are happening throughout the system. * * @author Tim Ysewyn */ class CatalogUpdater { private final CatalogService catalogService; CatalogUpdater(CatalogService catalogService) { this.catalogService = catalogService; } @EventListener(ServiceDiscovered.class) public void addNewApplicationToCatalog(ServiceDiscovered event) { this.catalogService.addApplicationToCatalog(event.getService()); } @EventListener(ServiceDisappeared.class) public void removeApplicationFromCatalog(ServiceDisappeared event) { this.catalogService.removeApplicationFromCatalog(event.getService()); } @EventListener(ApplicationInstanceCreated.class) public void addNewApplicationInstanceToCatalog(ApplicationInstanceCreated event) { this.catalogService.addApplicationInstanceToCatalog(event.getApplicationInstance()); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogUpdater.java import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import org.springframework.context.event.EventListener; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Will update the {@link Catalog catalog} based on events that are happening throughout the system. * * @author Tim Ysewyn */ class CatalogUpdater { private final CatalogService catalogService; CatalogUpdater(CatalogService catalogService) { this.catalogService = catalogService; } @EventListener(ServiceDiscovered.class) public void addNewApplicationToCatalog(ServiceDiscovered event) { this.catalogService.addApplicationToCatalog(event.getService()); } @EventListener(ServiceDisappeared.class) public void removeApplicationFromCatalog(ServiceDisappeared event) { this.catalogService.removeApplicationFromCatalog(event.getService()); } @EventListener(ApplicationInstanceCreated.class) public void addNewApplicationInstanceToCatalog(ApplicationInstanceCreated event) { this.catalogService.addApplicationInstanceToCatalog(event.getApplicationInstance()); }
@EventListener(ApplicationInstanceDeleted.class)
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/LandscapeWatcher.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.event.HeartbeatEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import static org.apache.commons.collections4.CollectionUtils.subtract; import java.util.List; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * Watcher that will update the catalog with the latest discovered applications and their instances. * * @author Tim Ysewyn * @author Steve De Zitter */ class LandscapeWatcher { private static final Logger logger = LoggerFactory.getLogger(LandscapeWatcher.class); private final DiscoveryClient discoveryClient;
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/LandscapeWatcher.java import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.event.HeartbeatEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import static org.apache.commons.collections4.CollectionUtils.subtract; import java.util.List; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * Watcher that will update the catalog with the latest discovered applications and their instances. * * @author Tim Ysewyn * @author Steve De Zitter */ class LandscapeWatcher { private static final Logger logger = LoggerFactory.getLogger(LandscapeWatcher.class); private final DiscoveryClient discoveryClient;
private final CatalogService catalogService;
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/LandscapeWatcher.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.event.HeartbeatEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import static org.apache.commons.collections4.CollectionUtils.subtract; import java.util.List; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance;
LandscapeWatcher(DiscoveryClient discoveryClient, CatalogService catalogService, List<ApplicationFilter> applicationFilters, List<ApplicationInstanceFilter> applicationInstanceFilters, ApplicationEventPublisher publisher) { this.discoveryClient = discoveryClient; this.catalogService = catalogService; this.applicationFilters = new ApplicationFilters(applicationFilters); this.applicationInstanceFilters = new ApplicationInstanceFilters(applicationInstanceFilters); this.publisher = publisher; } @EventListener({ HeartbeatEvent.class }) public void discoverLandscape() { logger.debug("Discovering landscape"); List<String> applications = this.discoveryClient.getServices() .stream() .filter(this.applicationFilters) .collect(Collectors.toList()); Catalog catalog = this.catalogService.getCatalog(); dispatchEventForDiscoveredApplications(applications, catalog); dispatchEventForDisappearedApplications(applications, catalog); applications.forEach(this::processApplication); } private void dispatchEventForDiscoveredApplications(List<String> applications, Catalog catalog) { subtract(applications, catalog.getApplications()) .stream()
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/LandscapeWatcher.java import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.event.HeartbeatEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import static org.apache.commons.collections4.CollectionUtils.subtract; import java.util.List; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance; LandscapeWatcher(DiscoveryClient discoveryClient, CatalogService catalogService, List<ApplicationFilter> applicationFilters, List<ApplicationInstanceFilter> applicationInstanceFilters, ApplicationEventPublisher publisher) { this.discoveryClient = discoveryClient; this.catalogService = catalogService; this.applicationFilters = new ApplicationFilters(applicationFilters); this.applicationInstanceFilters = new ApplicationInstanceFilters(applicationInstanceFilters); this.publisher = publisher; } @EventListener({ HeartbeatEvent.class }) public void discoverLandscape() { logger.debug("Discovering landscape"); List<String> applications = this.discoveryClient.getServices() .stream() .filter(this.applicationFilters) .collect(Collectors.toList()); Catalog catalog = this.catalogService.getCatalog(); dispatchEventForDiscoveredApplications(applications, catalog); dispatchEventForDisappearedApplications(applications, catalog); applications.forEach(this::processApplication); } private void dispatchEventForDiscoveredApplications(List<String> applications, Catalog catalog) { subtract(applications, catalog.getApplications()) .stream()
.map(ServiceDiscovered::new)
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/LandscapeWatcher.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.event.HeartbeatEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import static org.apache.commons.collections4.CollectionUtils.subtract; import java.util.List; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance;
this.applicationInstanceFilters = new ApplicationInstanceFilters(applicationInstanceFilters); this.publisher = publisher; } @EventListener({ HeartbeatEvent.class }) public void discoverLandscape() { logger.debug("Discovering landscape"); List<String> applications = this.discoveryClient.getServices() .stream() .filter(this.applicationFilters) .collect(Collectors.toList()); Catalog catalog = this.catalogService.getCatalog(); dispatchEventForDiscoveredApplications(applications, catalog); dispatchEventForDisappearedApplications(applications, catalog); applications.forEach(this::processApplication); } private void dispatchEventForDiscoveredApplications(List<String> applications, Catalog catalog) { subtract(applications, catalog.getApplications()) .stream() .map(ServiceDiscovered::new) .forEach(this.publisher::publishEvent); } private void dispatchEventForDisappearedApplications(List<String> applications, Catalog catalog) { subtract(catalog.getApplications(), applications) .stream()
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/LandscapeWatcher.java import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.event.HeartbeatEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import static org.apache.commons.collections4.CollectionUtils.subtract; import java.util.List; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance; this.applicationInstanceFilters = new ApplicationInstanceFilters(applicationInstanceFilters); this.publisher = publisher; } @EventListener({ HeartbeatEvent.class }) public void discoverLandscape() { logger.debug("Discovering landscape"); List<String> applications = this.discoveryClient.getServices() .stream() .filter(this.applicationFilters) .collect(Collectors.toList()); Catalog catalog = this.catalogService.getCatalog(); dispatchEventForDiscoveredApplications(applications, catalog); dispatchEventForDisappearedApplications(applications, catalog); applications.forEach(this::processApplication); } private void dispatchEventForDiscoveredApplications(List<String> applications, Catalog catalog) { subtract(applications, catalog.getApplications()) .stream() .map(ServiceDiscovered::new) .forEach(this.publisher::publishEvent); } private void dispatchEventForDisappearedApplications(List<String> applications, Catalog catalog) { subtract(catalog.getApplications(), applications) .stream()
.map(ServiceDisappeared::new)
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/LandscapeWatcher.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.event.HeartbeatEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import static org.apache.commons.collections4.CollectionUtils.subtract; import java.util.List; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance;
subtract(applications, catalog.getApplications()) .stream() .map(ServiceDiscovered::new) .forEach(this.publisher::publishEvent); } private void dispatchEventForDisappearedApplications(List<String> applications, Catalog catalog) { subtract(catalog.getApplications(), applications) .stream() .map(ServiceDisappeared::new) .forEach(this.publisher::publishEvent); } private void processApplication(String application) { logger.debug("Processing application {}", application); List<ServiceInstance> instances = this.discoveryClient.getInstances(application) .stream() .filter(this.applicationInstanceFilters) .collect(Collectors.toList()); Catalog catalog = this.catalogService.getCatalog(); List<String> knownInstanceIds = catalog.getApplicationInstancesForApplication(application); dispatchEventForDiscoveredApplicationInstances(instances, knownInstanceIds); dispatchEventForDisappearedApplicationInstances(instances, knownInstanceIds); } private void dispatchEventForDiscoveredApplicationInstances(List<ServiceInstance> discoveredInstances, List<String> knownInstanceIds) { discoveredInstances.stream() .filter(instance -> !knownInstanceIds.contains(instance.getInstanceId()))
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java // public class Catalog { // // private Set<String> applications = new HashSet<>(); // private Map<String, List<String>> applicationInstances = new HashMap<>(); // // Catalog() { // } // // public List<String> getApplications() { // return new ArrayList<>(this.applications); // } // // void addApplication(String application) { // this.applications.add(application); // } // // void removeApplication(String application) { // this.applications.remove(application); // } // // void addApplicationInstance(ApplicationInstance applicationInstance) { // this.addApplication(applicationInstance.getApplication()); // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.add(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // void removeApplicationInstance(ApplicationInstance applicationInstance) { // List<String> instances = this.applicationInstances.getOrDefault(applicationInstance.getApplication(), new ArrayList<>()); // instances.remove(applicationInstance.getId()); // this.applicationInstances.put(applicationInstance.getApplication(), instances); // } // // List<String> getApplicationInstances() { // return this.applicationInstances.values().stream() // .flatMap(List::stream) // .collect(toList()); // } // // public List<String> getApplicationInstancesForApplication(String application) { // return this.applicationInstances.getOrDefault(application, new ArrayList<>()); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/LandscapeWatcher.java import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.event.HeartbeatEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; import static org.apache.commons.collections4.CollectionUtils.subtract; import java.util.List; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.ordina.msdashboard.catalog.Catalog; import be.ordina.msdashboard.catalog.CatalogService; import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance; subtract(applications, catalog.getApplications()) .stream() .map(ServiceDiscovered::new) .forEach(this.publisher::publishEvent); } private void dispatchEventForDisappearedApplications(List<String> applications, Catalog catalog) { subtract(catalog.getApplications(), applications) .stream() .map(ServiceDisappeared::new) .forEach(this.publisher::publishEvent); } private void processApplication(String application) { logger.debug("Processing application {}", application); List<ServiceInstance> instances = this.discoveryClient.getInstances(application) .stream() .filter(this.applicationInstanceFilters) .collect(Collectors.toList()); Catalog catalog = this.catalogService.getCatalog(); List<String> knownInstanceIds = catalog.getApplicationInstancesForApplication(application); dispatchEventForDiscoveredApplicationInstances(instances, knownInstanceIds); dispatchEventForDisappearedApplicationInstances(instances, knownInstanceIds); } private void dispatchEventForDiscoveredApplicationInstances(List<ServiceInstance> discoveredInstances, List<String> knownInstanceIds) { discoveredInstances.stream() .filter(instance -> !knownInstanceIds.contains(instance.getInstanceId()))
.map(ServiceInstanceDiscovered::new)
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // }
import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import be.ordina.msdashboard.applicationinstance.ApplicationInstance; import static java.util.stream.Collectors.toList;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Catalog that keeps track of all known applications and their instances in the environment. * * @author Tim Ysewyn * @author Steve De Zitter */ public class Catalog { private Set<String> applications = new HashSet<>(); private Map<String, List<String>> applicationInstances = new HashMap<>(); Catalog() { } public List<String> getApplications() { return new ArrayList<>(this.applications); } void addApplication(String application) { this.applications.add(application); } void removeApplication(String application) { this.applications.remove(application); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/Catalog.java import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import be.ordina.msdashboard.applicationinstance.ApplicationInstance; import static java.util.stream.Collectors.toList; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Catalog that keeps track of all known applications and their instances in the environment. * * @author Tim Ysewyn * @author Steve De Zitter */ public class Catalog { private Set<String> applications = new HashSet<>(); private Map<String, List<String>> applicationInstances = new HashMap<>(); Catalog() { } public List<String> getApplications() { return new ArrayList<>(this.applications); } void addApplication(String application) { this.applications.add(application); } void removeApplication(String application) { this.applications.remove(application); }
void addApplicationInstance(ApplicationInstance applicationInstance) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceEventMother.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import java.net.URI; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.hateoas.Links;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ public final class ApplicationInstanceEventMother { private ApplicationInstanceEventMother() { }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceEventMother.java import java.net.URI; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.hateoas.Links; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ public final class ApplicationInstanceEventMother { private ApplicationInstanceEventMother() { }
public static ApplicationInstanceCreated applicationInstanceCreated(String id, String application) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceEventMother.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import java.net.URI; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.hateoas.Links;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ public final class ApplicationInstanceEventMother { private ApplicationInstanceEventMother() { } public static ApplicationInstanceCreated applicationInstanceCreated(String id, String application) { return (ApplicationInstanceCreated) ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build() .getUncommittedChanges().get(0); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceEventMother.java import java.net.URI; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.hateoas.Links; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ public final class ApplicationInstanceEventMother { private ApplicationInstanceEventMother() { } public static ApplicationInstanceCreated applicationInstanceCreated(String id, String application) { return (ApplicationInstanceCreated) ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build() .getUncommittedChanges().get(0); }
public static ApplicationInstanceHealthDataRetrieved applicationInstanceHealthDataRetrieved(String id, String application, Health health) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceEventMother.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import java.net.URI; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.hateoas.Links;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ public final class ApplicationInstanceEventMother { private ApplicationInstanceEventMother() { } public static ApplicationInstanceCreated applicationInstanceCreated(String id, String application) { return (ApplicationInstanceCreated) ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build() .getUncommittedChanges().get(0); } public static ApplicationInstanceHealthDataRetrieved applicationInstanceHealthDataRetrieved(String id, String application, Health health) { return new ApplicationInstanceHealthDataRetrieved(ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build().markChangesAsCommitted(), health); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceEventMother.java import java.net.URI; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.hateoas.Links; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ public final class ApplicationInstanceEventMother { private ApplicationInstanceEventMother() { } public static ApplicationInstanceCreated applicationInstanceCreated(String id, String application) { return (ApplicationInstanceCreated) ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build() .getUncommittedChanges().get(0); } public static ApplicationInstanceHealthDataRetrieved applicationInstanceHealthDataRetrieved(String id, String application, Health health) { return new ApplicationInstanceHealthDataRetrieved(ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build().markChangesAsCommitted(), health); }
public static ActuatorEndpointsUpdated actuatorEndpointsUpdated(String id, String application, Links actuatorEndpoints) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceEventMother.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import java.net.URI; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.hateoas.Links;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ public final class ApplicationInstanceEventMother { private ApplicationInstanceEventMother() { } public static ApplicationInstanceCreated applicationInstanceCreated(String id, String application) { return (ApplicationInstanceCreated) ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build() .getUncommittedChanges().get(0); } public static ApplicationInstanceHealthDataRetrieved applicationInstanceHealthDataRetrieved(String id, String application, Health health) { return new ApplicationInstanceHealthDataRetrieved(ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build().markChangesAsCommitted(), health); } public static ActuatorEndpointsUpdated actuatorEndpointsUpdated(String id, String application, Links actuatorEndpoints) { ApplicationInstance applicationInstance = ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build().markChangesAsCommitted(); applicationInstance.updateActuatorEndpoints(actuatorEndpoints); return (ActuatorEndpointsUpdated) applicationInstance .getUncommittedChanges().get(0); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceEventMother.java import java.net.URI; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.hateoas.Links; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * @author Tim Ysewyn */ public final class ApplicationInstanceEventMother { private ApplicationInstanceEventMother() { } public static ApplicationInstanceCreated applicationInstanceCreated(String id, String application) { return (ApplicationInstanceCreated) ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build() .getUncommittedChanges().get(0); } public static ApplicationInstanceHealthDataRetrieved applicationInstanceHealthDataRetrieved(String id, String application, Health health) { return new ApplicationInstanceHealthDataRetrieved(ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build().markChangesAsCommitted(), health); } public static ActuatorEndpointsUpdated actuatorEndpointsUpdated(String id, String application, Links actuatorEndpoints) { ApplicationInstance applicationInstance = ApplicationInstance.Builder .forApplicationWithId(application, id) .baseUri(URI.create("http://localhost:8080")) .build().markChangesAsCommitted(); applicationInstance.updateActuatorEndpoints(actuatorEndpoints); return (ActuatorEndpointsUpdated) applicationInstance .getUncommittedChanges().get(0); }
public static ApplicationInstanceDeleted applicationInstanceDeleted(String id, String application) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; }
@EventListener(ServiceInstanceDiscovered.class)
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; } @EventListener(ServiceInstanceDiscovered.class) public void createNewApplicationInstance(ServiceInstanceDiscovered event) {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; } @EventListener(ServiceInstanceDiscovered.class) public void createNewApplicationInstance(ServiceInstanceDiscovered event) {
CreateApplicationInstance command = new CreateApplicationInstance(event.getServiceInstance());
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; } @EventListener(ServiceInstanceDiscovered.class) public void createNewApplicationInstance(ServiceInstanceDiscovered event) { CreateApplicationInstance command = new CreateApplicationInstance(event.getServiceInstance()); this.applicationInstanceService.createApplicationInstance(command); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; } @EventListener(ServiceInstanceDiscovered.class) public void createNewApplicationInstance(ServiceInstanceDiscovered event) { CreateApplicationInstance command = new CreateApplicationInstance(event.getServiceInstance()); this.applicationInstanceService.createApplicationInstance(command); }
@EventListener(ServiceInstanceDisappeared.class)
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; } @EventListener(ServiceInstanceDiscovered.class) public void createNewApplicationInstance(ServiceInstanceDiscovered event) { CreateApplicationInstance command = new CreateApplicationInstance(event.getServiceInstance()); this.applicationInstanceService.createApplicationInstance(command); } @EventListener(ServiceInstanceDisappeared.class) public void deleteApplicationInstance(ServiceInstanceDisappeared event) {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; } @EventListener(ServiceInstanceDiscovered.class) public void createNewApplicationInstance(ServiceInstanceDiscovered event) { CreateApplicationInstance command = new CreateApplicationInstance(event.getServiceInstance()); this.applicationInstanceService.createApplicationInstance(command); } @EventListener(ServiceInstanceDisappeared.class) public void deleteApplicationInstance(ServiceInstanceDisappeared event) {
DeleteApplicationInstance command = new DeleteApplicationInstance(event.getServiceInstanceId());
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; } @EventListener(ServiceInstanceDiscovered.class) public void createNewApplicationInstance(ServiceInstanceDiscovered event) { CreateApplicationInstance command = new CreateApplicationInstance(event.getServiceInstance()); this.applicationInstanceService.createApplicationInstance(command); } @EventListener(ServiceInstanceDisappeared.class) public void deleteApplicationInstance(ServiceInstanceDisappeared event) { DeleteApplicationInstance command = new DeleteApplicationInstance(event.getServiceInstanceId()); this.applicationInstanceService.deleteApplicationInstance(command); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; } @EventListener(ServiceInstanceDiscovered.class) public void createNewApplicationInstance(ServiceInstanceDiscovered event) { CreateApplicationInstance command = new CreateApplicationInstance(event.getServiceInstance()); this.applicationInstanceService.createApplicationInstance(command); } @EventListener(ServiceInstanceDisappeared.class) public void deleteApplicationInstance(ServiceInstanceDisappeared event) { DeleteApplicationInstance command = new DeleteApplicationInstance(event.getServiceInstanceId()); this.applicationInstanceService.deleteApplicationInstance(command); }
@EventListener(ApplicationInstanceCreated.class)
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; } @EventListener(ServiceInstanceDiscovered.class) public void createNewApplicationInstance(ServiceInstanceDiscovered event) { CreateApplicationInstance command = new CreateApplicationInstance(event.getServiceInstance()); this.applicationInstanceService.createApplicationInstance(command); } @EventListener(ServiceInstanceDisappeared.class) public void deleteApplicationInstance(ServiceInstanceDisappeared event) { DeleteApplicationInstance command = new DeleteApplicationInstance(event.getServiceInstanceId()); this.applicationInstanceService.deleteApplicationInstance(command); } @EventListener(ApplicationInstanceCreated.class) public void discoverActuatorEndpoints(ApplicationInstanceCreated event) { ApplicationInstance applicationInstance = event.getApplicationInstance(); this.actuatorEndpointsDiscovererService.findActuatorEndpoints(applicationInstance) .subscribe(actuatorEndpoints -> {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/CreateApplicationInstance.java // public final class CreateApplicationInstance { // // private final ServiceInstance serviceInstance; // // public CreateApplicationInstance(ServiceInstance serviceInstance) { // Assert.notNull(serviceInstance, "serviceInstance must not be null!"); // this.serviceInstance = serviceInstance; // } // // public ServiceInstance getServiceInstance() { // return this.serviceInstance; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/DeleteApplicationInstance.java // public final class DeleteApplicationInstance { // // private final String id; // // public DeleteApplicationInstance(String id) { // Assert.notNull(id, "id must not be null!"); // this.id = id; // } // // public String getId() { // return this.id; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateActuatorEndpoints.java // public final class UpdateActuatorEndpoints { // // private final String id; // private final Links actuatorEndpoints; // // public UpdateActuatorEndpoints(String id, Links actuatorEndpoints) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(actuatorEndpoints, "actuatorEndpoints must not be null!"); // this.id = id; // this.actuatorEndpoints = actuatorEndpoints; // } // // public String getId() { // return this.id; // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceUpdater.java import be.ordina.msdashboard.applicationinstance.commands.CreateApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.DeleteApplicationInstance; import be.ordina.msdashboard.applicationinstance.commands.UpdateActuatorEndpoints; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.context.event.EventListener; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Will create, update or delete {@link ApplicationInstance applications instances} based on events * that are happening throughout the system. * * @author Tim Ysewyn */ class ApplicationInstanceUpdater { private final ApplicationInstanceService applicationInstanceService; private final ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService; ApplicationInstanceUpdater(ApplicationInstanceService applicationInstanceService, ActuatorEndpointsDiscovererService actuatorEndpointsDiscovererService) { this.applicationInstanceService = applicationInstanceService; this.actuatorEndpointsDiscovererService = actuatorEndpointsDiscovererService; } @EventListener(ServiceInstanceDiscovered.class) public void createNewApplicationInstance(ServiceInstanceDiscovered event) { CreateApplicationInstance command = new CreateApplicationInstance(event.getServiceInstance()); this.applicationInstanceService.createApplicationInstance(command); } @EventListener(ServiceInstanceDisappeared.class) public void deleteApplicationInstance(ServiceInstanceDisappeared event) { DeleteApplicationInstance command = new DeleteApplicationInstance(event.getServiceInstanceId()); this.applicationInstanceService.deleteApplicationInstance(command); } @EventListener(ApplicationInstanceCreated.class) public void discoverActuatorEndpoints(ApplicationInstanceCreated event) { ApplicationInstance applicationInstance = event.getApplicationInstance(); this.actuatorEndpointsDiscovererService.findActuatorEndpoints(applicationInstance) .subscribe(actuatorEndpoints -> {
UpdateActuatorEndpoints command = new UpdateActuatorEndpoints(applicationInstance.getId(),
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcherTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import java.net.URI; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import reactor.core.publisher.Mono; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.times; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Unit tests for the {@link ApplicationInstanceHealthWatcher application instance health watcher}. * * @author Steve De Zitter * @author Tim Ysewyn */ @RunWith(MockitoJUnitRunner.class) public class ApplicationInstanceHealthWatcherTests { @Rule public OutputCapture outputCapture = new OutputCapture(); @Mock private ApplicationInstanceService applicationInstanceService; @Mock private WebClient webClient; @Mock private ApplicationEventPublisher applicationEventPublisher; @Mock private WebClient.RequestHeadersUriSpec requestHeadersUriSpec; @Mock private WebClient.RequestHeadersSpec requestHeadersSpec; @Mock private WebClient.ResponseSpec responseSpec; @Captor private ArgumentCaptor<ApplicationEvent> applicationEventArgumentCaptor; @InjectMocks private ApplicationInstanceHealthWatcher healthWatcher; @Before public void setupMocks() { when(this.webClient.get()).thenReturn(this.requestHeadersUriSpec); when(this.requestHeadersUriSpec.uri("http://localhost:8080/actuator/health")) .thenReturn(this.requestHeadersSpec); when(this.requestHeadersSpec.retrieve()).thenReturn(this.responseSpec); } @Test public void shouldNotRetrieveTheHealthDataAfterActuatorEndpointsHaveBeenUpdatedWithoutHealthLink() {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcherTests.java import java.net.URI; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import reactor.core.publisher.Mono; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.times; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * Unit tests for the {@link ApplicationInstanceHealthWatcher application instance health watcher}. * * @author Steve De Zitter * @author Tim Ysewyn */ @RunWith(MockitoJUnitRunner.class) public class ApplicationInstanceHealthWatcherTests { @Rule public OutputCapture outputCapture = new OutputCapture(); @Mock private ApplicationInstanceService applicationInstanceService; @Mock private WebClient webClient; @Mock private ApplicationEventPublisher applicationEventPublisher; @Mock private WebClient.RequestHeadersUriSpec requestHeadersUriSpec; @Mock private WebClient.RequestHeadersSpec requestHeadersSpec; @Mock private WebClient.ResponseSpec responseSpec; @Captor private ArgumentCaptor<ApplicationEvent> applicationEventArgumentCaptor; @InjectMocks private ApplicationInstanceHealthWatcher healthWatcher; @Before public void setupMocks() { when(this.webClient.get()).thenReturn(this.requestHeadersUriSpec); when(this.requestHeadersUriSpec.uri("http://localhost:8080/actuator/health")) .thenReturn(this.requestHeadersSpec); when(this.requestHeadersSpec.retrieve()).thenReturn(this.responseSpec); } @Test public void shouldNotRetrieveTheHealthDataAfterActuatorEndpointsHaveBeenUpdatedWithoutHealthLink() {
ActuatorEndpointsUpdated event =
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcherTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import java.net.URI; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import reactor.core.publisher.Mono; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.times; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions;
List<ApplicationInstance> applicationInstances = Arrays.asList(firstInstance, secondInstance); when(this.applicationInstanceService.getApplicationInstances()).thenReturn(applicationInstances); when(this.responseSpec.bodyToMono(ApplicationInstanceHealthWatcher.HealthWrapper.class)) .thenReturn(Mono.just(new ApplicationInstanceHealthWatcher.HealthWrapper(Status.UP, new HashMap<>()))); this.healthWatcher.retrieveHealthDataForAllApplicationInstances(); assertHealthInfoRetrievalSucceeded(Collections.singletonList(secondInstance)); } @Test public void shouldOnlyRetrieveHealthDataForInstancesWithAHealthActuatorEndpoint() { ApplicationInstance firstInstance = ApplicationInstanceMother.instance("a-1", "a"); ApplicationInstance secondInstance = ApplicationInstanceMother.instance("a-2", "a", URI.create("http://localhost:8080"), new Links(new Link("http://localhost:8080/actuator/health", "health"))); List<ApplicationInstance> applicationInstances = Arrays.asList(firstInstance, secondInstance); when(this.applicationInstanceService.getApplicationInstances()).thenReturn(applicationInstances); when(this.responseSpec.bodyToMono(ApplicationInstanceHealthWatcher.HealthWrapper.class)) .thenReturn(Mono.just(new ApplicationInstanceHealthWatcher.HealthWrapper(Status.UP, new HashMap<>()))); this.healthWatcher.retrieveHealthDataForAllApplicationInstances(); assertHealthInfoRetrievalSucceeded(Collections.singletonList(secondInstance)); } @Test public void shouldUpdateTheHealthOfAnApplicationInstanceWhenHealthDataRetrieved() {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcherTests.java import java.net.URI; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import reactor.core.publisher.Mono; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.times; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; List<ApplicationInstance> applicationInstances = Arrays.asList(firstInstance, secondInstance); when(this.applicationInstanceService.getApplicationInstances()).thenReturn(applicationInstances); when(this.responseSpec.bodyToMono(ApplicationInstanceHealthWatcher.HealthWrapper.class)) .thenReturn(Mono.just(new ApplicationInstanceHealthWatcher.HealthWrapper(Status.UP, new HashMap<>()))); this.healthWatcher.retrieveHealthDataForAllApplicationInstances(); assertHealthInfoRetrievalSucceeded(Collections.singletonList(secondInstance)); } @Test public void shouldOnlyRetrieveHealthDataForInstancesWithAHealthActuatorEndpoint() { ApplicationInstance firstInstance = ApplicationInstanceMother.instance("a-1", "a"); ApplicationInstance secondInstance = ApplicationInstanceMother.instance("a-2", "a", URI.create("http://localhost:8080"), new Links(new Link("http://localhost:8080/actuator/health", "health"))); List<ApplicationInstance> applicationInstances = Arrays.asList(firstInstance, secondInstance); when(this.applicationInstanceService.getApplicationInstances()).thenReturn(applicationInstances); when(this.responseSpec.bodyToMono(ApplicationInstanceHealthWatcher.HealthWrapper.class)) .thenReturn(Mono.just(new ApplicationInstanceHealthWatcher.HealthWrapper(Status.UP, new HashMap<>()))); this.healthWatcher.retrieveHealthDataForAllApplicationInstances(); assertHealthInfoRetrievalSucceeded(Collections.singletonList(secondInstance)); } @Test public void shouldUpdateTheHealthOfAnApplicationInstanceWhenHealthDataRetrieved() {
ApplicationInstanceHealthDataRetrieved event = ApplicationInstanceEventMother
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcherTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import java.net.URI; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import reactor.core.publisher.Mono; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.times; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions;
this.healthWatcher.retrieveHealthDataForAllApplicationInstances(); assertHealthInfoRetrievalSucceeded(Collections.singletonList(secondInstance)); } @Test public void shouldOnlyRetrieveHealthDataForInstancesWithAHealthActuatorEndpoint() { ApplicationInstance firstInstance = ApplicationInstanceMother.instance("a-1", "a"); ApplicationInstance secondInstance = ApplicationInstanceMother.instance("a-2", "a", URI.create("http://localhost:8080"), new Links(new Link("http://localhost:8080/actuator/health", "health"))); List<ApplicationInstance> applicationInstances = Arrays.asList(firstInstance, secondInstance); when(this.applicationInstanceService.getApplicationInstances()).thenReturn(applicationInstances); when(this.responseSpec.bodyToMono(ApplicationInstanceHealthWatcher.HealthWrapper.class)) .thenReturn(Mono.just(new ApplicationInstanceHealthWatcher.HealthWrapper(Status.UP, new HashMap<>()))); this.healthWatcher.retrieveHealthDataForAllApplicationInstances(); assertHealthInfoRetrievalSucceeded(Collections.singletonList(secondInstance)); } @Test public void shouldUpdateTheHealthOfAnApplicationInstanceWhenHealthDataRetrieved() { ApplicationInstanceHealthDataRetrieved event = ApplicationInstanceEventMother .applicationInstanceHealthDataRetrieved("a-1", "a", Health.up().build()); this.healthWatcher.updateHealthForApplicationInstance(event);
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcherTests.java import java.net.URI; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import reactor.core.publisher.Mono; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.times; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; this.healthWatcher.retrieveHealthDataForAllApplicationInstances(); assertHealthInfoRetrievalSucceeded(Collections.singletonList(secondInstance)); } @Test public void shouldOnlyRetrieveHealthDataForInstancesWithAHealthActuatorEndpoint() { ApplicationInstance firstInstance = ApplicationInstanceMother.instance("a-1", "a"); ApplicationInstance secondInstance = ApplicationInstanceMother.instance("a-2", "a", URI.create("http://localhost:8080"), new Links(new Link("http://localhost:8080/actuator/health", "health"))); List<ApplicationInstance> applicationInstances = Arrays.asList(firstInstance, secondInstance); when(this.applicationInstanceService.getApplicationInstances()).thenReturn(applicationInstances); when(this.responseSpec.bodyToMono(ApplicationInstanceHealthWatcher.HealthWrapper.class)) .thenReturn(Mono.just(new ApplicationInstanceHealthWatcher.HealthWrapper(Status.UP, new HashMap<>()))); this.healthWatcher.retrieveHealthDataForAllApplicationInstances(); assertHealthInfoRetrievalSucceeded(Collections.singletonList(secondInstance)); } @Test public void shouldUpdateTheHealthOfAnApplicationInstanceWhenHealthDataRetrieved() { ApplicationInstanceHealthDataRetrieved event = ApplicationInstanceEventMother .applicationInstanceHealthDataRetrieved("a-1", "a", Health.up().build()); this.healthWatcher.updateHealthForApplicationInstance(event);
ArgumentCaptor<UpdateApplicationInstanceHealth> captor = ArgumentCaptor.forClass(UpdateApplicationInstanceHealth.class);
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcherTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // }
import java.net.URI; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import reactor.core.publisher.Mono; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.times; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions;
UpdateApplicationInstanceHealth command = captor.getValue(); assertThat(command.getId()).isEqualTo("a-1"); assertThat(command.getHealthStatus()).isEqualTo(Status.UP); verifyNoMoreInteractions(this.applicationInstanceService); verifyZeroInteractions(this.applicationEventPublisher); } private void assertHealthInfoRetrievalSucceeded(ApplicationInstance instance) { verify(this.applicationEventPublisher).publishEvent(this.applicationEventArgumentCaptor.capture()); verifyNoMoreInteractions(this.applicationEventPublisher); assertThat(this.outputCapture.toString()) .contains(String.format("Retrieved health information for application instance [%s]", instance.getId())); ApplicationInstanceHealthDataRetrieved healthInfoRetrieved = (ApplicationInstanceHealthDataRetrieved) this.applicationEventArgumentCaptor.getValue(); assertThat(healthInfoRetrieved).isNotNull(); assertThat(healthInfoRetrieved.getHealth()).isNotNull(); assertThat(healthInfoRetrieved.getHealth().getStatus()).isEqualTo(Status.UP); assertThat(healthInfoRetrieved.getHealth().getDetails()).isNotNull(); assertThat(healthInfoRetrieved.getSource()).isEqualTo(instance); } private void assertHealthInfoRetrievalFailed(ApplicationInstance instance, URI actuatorEndpoint) { verify(this.applicationEventPublisher).publishEvent(this.applicationEventArgumentCaptor.capture()); verifyNoMoreInteractions(this.applicationEventPublisher); assertThat(this.outputCapture.toString()).contains( String.format("Could not retrieve health information for [%s]", actuatorEndpoint));
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/commands/UpdateApplicationInstanceHealth.java // public final class UpdateApplicationInstanceHealth { // // private final String id; // private final Status healthStatus; // // public UpdateApplicationInstanceHealth(String id, Status healthStatus) { // Assert.notNull(id, "id must not be null!"); // Assert.notNull(healthStatus, "healthStatus must not be null!"); // // this.id = id; // this.healthStatus = healthStatus; // } // // public String getId() { // return this.id; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrievalFailed.java // public class ApplicationInstanceHealthDataRetrievalFailed extends ApplicationEvent { // // public ApplicationInstanceHealthDataRetrievalFailed(ApplicationInstance instance) { // super(instance); // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthDataRetrieved.java // public class ApplicationInstanceHealthDataRetrieved extends ApplicationEvent { // // private Health health; // // public ApplicationInstanceHealthDataRetrieved(ApplicationInstance instance, Health health) { // super(instance); // this.health = health; // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // public Health getHealth() { // return this.health; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceHealthWatcherTests.java import java.net.URI; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import reactor.core.publisher.Mono; import be.ordina.msdashboard.applicationinstance.commands.UpdateApplicationInstanceHealth; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrievalFailed; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthDataRetrieved; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.web.reactive.function.client.WebClient; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.times; import static org.mockito.BDDMockito.verify; import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; UpdateApplicationInstanceHealth command = captor.getValue(); assertThat(command.getId()).isEqualTo("a-1"); assertThat(command.getHealthStatus()).isEqualTo(Status.UP); verifyNoMoreInteractions(this.applicationInstanceService); verifyZeroInteractions(this.applicationEventPublisher); } private void assertHealthInfoRetrievalSucceeded(ApplicationInstance instance) { verify(this.applicationEventPublisher).publishEvent(this.applicationEventArgumentCaptor.capture()); verifyNoMoreInteractions(this.applicationEventPublisher); assertThat(this.outputCapture.toString()) .contains(String.format("Retrieved health information for application instance [%s]", instance.getId())); ApplicationInstanceHealthDataRetrieved healthInfoRetrieved = (ApplicationInstanceHealthDataRetrieved) this.applicationEventArgumentCaptor.getValue(); assertThat(healthInfoRetrieved).isNotNull(); assertThat(healthInfoRetrieved.getHealth()).isNotNull(); assertThat(healthInfoRetrieved.getHealth().getStatus()).isEqualTo(Status.UP); assertThat(healthInfoRetrieved.getHealth().getDetails()).isNotNull(); assertThat(healthInfoRetrieved.getSource()).isEqualTo(instance); } private void assertHealthInfoRetrievalFailed(ApplicationInstance instance, URI actuatorEndpoint) { verify(this.applicationEventPublisher).publishEvent(this.applicationEventArgumentCaptor.capture()); verifyNoMoreInteractions(this.applicationEventPublisher); assertThat(this.outputCapture.toString()).contains( String.format("Could not retrieve health information for [%s]", actuatorEndpoint));
ApplicationInstanceHealthDataRetrievalFailed healthInfoRetrievalFailed =
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/DiscoveryConfiguration.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // }
import java.util.List; import be.ordina.msdashboard.catalog.CatalogService; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * Configuration for the discovery of the environment. * * @author Tim Ysewyn */ @Configuration public class DiscoveryConfiguration { @Bean
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java // public class CatalogService { // // private final Catalog catalog; // // public CatalogService() { // this.catalog = new Catalog(); // } // // public Catalog getCatalog() { // return this.catalog; // } // // public void addApplicationToCatalog(String application) { // this.catalog.addApplication(application); // } // // public void removeApplicationFromCatalog(String application) { // this.catalog.removeApplication(application); // } // // public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) { // this.catalog.addApplicationInstance(applicationInstance); // } // public void removeApplicationInstanceFromCatalog(ApplicationInstance applicationInstance) { // this.catalog.removeApplicationInstance(applicationInstance); // } // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/DiscoveryConfiguration.java import java.util.List; import be.ordina.msdashboard.catalog.CatalogService; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * Configuration for the discovery of the environment. * * @author Tim Ysewyn */ @Configuration public class DiscoveryConfiguration { @Bean
LandscapeWatcher landscapeWatcher(DiscoveryClient discoveryClient, CatalogService catalogService,
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/catalog/CatalogMother.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // }
import java.util.List; import be.ordina.msdashboard.applicationinstance.ApplicationInstance;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * @author Tim Ysewyn */ public final class CatalogMother { private CatalogMother() { } public static Catalog emptyCatalog() { return new Catalog(); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/catalog/CatalogMother.java import java.util.List; import be.ordina.msdashboard.applicationinstance.ApplicationInstance; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * @author Tim Ysewyn */ public final class CatalogMother { private CatalogMother() { } public static Catalog emptyCatalog() { return new Catalog(); }
public static Catalog catalogWith(List<ApplicationInstance> applicationInstances) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/discovery/ServiceDiscoveryEventMother.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * @author Tim Ysewyn */ public final class ServiceDiscoveryEventMother { private ServiceDiscoveryEventMother() { }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/discovery/ServiceDiscoveryEventMother.java import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * @author Tim Ysewyn */ public final class ServiceDiscoveryEventMother { private ServiceDiscoveryEventMother() { }
public static ServiceDiscovered newServiceDiscovered(String service) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/discovery/ServiceDiscoveryEventMother.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * @author Tim Ysewyn */ public final class ServiceDiscoveryEventMother { private ServiceDiscoveryEventMother() { } public static ServiceDiscovered newServiceDiscovered(String service) { return new ServiceDiscovered(service); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/discovery/ServiceDiscoveryEventMother.java import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * @author Tim Ysewyn */ public final class ServiceDiscoveryEventMother { private ServiceDiscoveryEventMother() { } public static ServiceDiscovered newServiceDiscovered(String service) { return new ServiceDiscovered(service); }
public static ServiceDisappeared serviceDisappeared(String service) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/discovery/ServiceDiscoveryEventMother.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * @author Tim Ysewyn */ public final class ServiceDiscoveryEventMother { private ServiceDiscoveryEventMother() { } public static ServiceDiscovered newServiceDiscovered(String service) { return new ServiceDiscovered(service); } public static ServiceDisappeared serviceDisappeared(String service) { return new ServiceDisappeared(service); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/discovery/ServiceDiscoveryEventMother.java import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * @author Tim Ysewyn */ public final class ServiceDiscoveryEventMother { private ServiceDiscoveryEventMother() { } public static ServiceDiscovered newServiceDiscovered(String service) { return new ServiceDiscovered(service); } public static ServiceDisappeared serviceDisappeared(String service) { return new ServiceDisappeared(service); }
public static ServiceInstanceDiscovered newServiceInstanceDiscovered(ServiceInstance serviceInstance) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/discovery/ServiceDiscoveryEventMother.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // }
import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * @author Tim Ysewyn */ public final class ServiceDiscoveryEventMother { private ServiceDiscoveryEventMother() { } public static ServiceDiscovered newServiceDiscovered(String service) { return new ServiceDiscovered(service); } public static ServiceDisappeared serviceDisappeared(String service) { return new ServiceDisappeared(service); } public static ServiceInstanceDiscovered newServiceInstanceDiscovered(ServiceInstance serviceInstance) { return new ServiceInstanceDiscovered(serviceInstance); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDisappeared.java // public class ServiceDisappeared extends ApplicationEvent { // // public ServiceDisappeared(String service) { // super(service); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceDiscovered.java // public class ServiceDiscovered extends ApplicationEvent { // // public ServiceDiscovered(String application) { // super(application); // } // // public String getService() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDisappeared.java // public class ServiceInstanceDisappeared extends ApplicationEvent { // // public ServiceInstanceDisappeared(String serviceInstanceId) { // super(serviceInstanceId); // } // // public String getServiceInstanceId() { // return (String) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/discovery/events/ServiceInstanceDiscovered.java // public class ServiceInstanceDiscovered extends ApplicationEvent { // // public ServiceInstanceDiscovered(ServiceInstance serviceInstance) { // super(serviceInstance); // } // // public ServiceInstance getServiceInstance() { // return (ServiceInstance) this.source; // } // // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/discovery/ServiceDiscoveryEventMother.java import be.ordina.msdashboard.discovery.events.ServiceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceDiscovered; import be.ordina.msdashboard.discovery.events.ServiceInstanceDisappeared; import be.ordina.msdashboard.discovery.events.ServiceInstanceDiscovered; import org.springframework.cloud.client.ServiceInstance; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.discovery; /** * @author Tim Ysewyn */ public final class ServiceDiscoveryEventMother { private ServiceDiscoveryEventMother() { } public static ServiceDiscovered newServiceDiscovered(String service) { return new ServiceDiscovered(service); } public static ServiceDisappeared serviceDisappeared(String service) { return new ServiceDisappeared(service); } public static ServiceInstanceDiscovered newServiceInstanceDiscovered(ServiceInstance serviceInstance) { return new ServiceInstanceDiscovered(serviceInstance); }
public static ServiceInstanceDisappeared serviceInstanceDisappeared(String instanceId) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/catalog/CatalogServiceTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // } // // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceMother.java // public final class ApplicationInstanceMother { // // private ApplicationInstanceMother() { // throw new RuntimeException("Not allowed"); // } // // public static ApplicationInstance instance(String id, String application) { // return instance(id, application, URI.create("http://localhost:8080")); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri) { // return ApplicationInstance.Builder.forApplicationWithId(application, id).baseUri(baseUri).build(); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri, Links actuatorEndpoints) { // ApplicationInstance applicationInstance = ApplicationInstance.Builder.forApplicationWithId(application, id) // .baseUri(baseUri) // .build(); // applicationInstance.updateActuatorEndpoints(actuatorEndpoints); // return applicationInstance; // } // }
import org.junit.Test; import be.ordina.msdashboard.applicationinstance.ApplicationInstance; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceMother; import static org.assertj.core.api.Assertions.assertThat;
@Test public void shouldAddApplicationToEmptyCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).hasSize(1); assertThat(catalog.getApplications()).contains("a"); } @Test public void shouldNotAddKnownApplicationToCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); catalogService.addApplicationToCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).hasSize(1); assertThat(catalog.getApplications()).contains("a"); } @Test public void shouldRemoveKnownApplicationFromCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); catalogService.removeApplicationFromCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).isEmpty(); } @Test public void shouldAddApplicationAndInstanceToEmptyCatalog() {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // } // // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceMother.java // public final class ApplicationInstanceMother { // // private ApplicationInstanceMother() { // throw new RuntimeException("Not allowed"); // } // // public static ApplicationInstance instance(String id, String application) { // return instance(id, application, URI.create("http://localhost:8080")); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri) { // return ApplicationInstance.Builder.forApplicationWithId(application, id).baseUri(baseUri).build(); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri, Links actuatorEndpoints) { // ApplicationInstance applicationInstance = ApplicationInstance.Builder.forApplicationWithId(application, id) // .baseUri(baseUri) // .build(); // applicationInstance.updateActuatorEndpoints(actuatorEndpoints); // return applicationInstance; // } // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/catalog/CatalogServiceTests.java import org.junit.Test; import be.ordina.msdashboard.applicationinstance.ApplicationInstance; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceMother; import static org.assertj.core.api.Assertions.assertThat; @Test public void shouldAddApplicationToEmptyCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).hasSize(1); assertThat(catalog.getApplications()).contains("a"); } @Test public void shouldNotAddKnownApplicationToCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); catalogService.addApplicationToCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).hasSize(1); assertThat(catalog.getApplications()).contains("a"); } @Test public void shouldRemoveKnownApplicationFromCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); catalogService.removeApplicationFromCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).isEmpty(); } @Test public void shouldAddApplicationAndInstanceToEmptyCatalog() {
ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a");
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/catalog/CatalogServiceTests.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // } // // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceMother.java // public final class ApplicationInstanceMother { // // private ApplicationInstanceMother() { // throw new RuntimeException("Not allowed"); // } // // public static ApplicationInstance instance(String id, String application) { // return instance(id, application, URI.create("http://localhost:8080")); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri) { // return ApplicationInstance.Builder.forApplicationWithId(application, id).baseUri(baseUri).build(); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri, Links actuatorEndpoints) { // ApplicationInstance applicationInstance = ApplicationInstance.Builder.forApplicationWithId(application, id) // .baseUri(baseUri) // .build(); // applicationInstance.updateActuatorEndpoints(actuatorEndpoints); // return applicationInstance; // } // }
import org.junit.Test; import be.ordina.msdashboard.applicationinstance.ApplicationInstance; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceMother; import static org.assertj.core.api.Assertions.assertThat;
@Test public void shouldAddApplicationToEmptyCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).hasSize(1); assertThat(catalog.getApplications()).contains("a"); } @Test public void shouldNotAddKnownApplicationToCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); catalogService.addApplicationToCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).hasSize(1); assertThat(catalog.getApplications()).contains("a"); } @Test public void shouldRemoveKnownApplicationFromCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); catalogService.removeApplicationFromCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).isEmpty(); } @Test public void shouldAddApplicationAndInstanceToEmptyCatalog() {
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // } // // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/applicationinstance/ApplicationInstanceMother.java // public final class ApplicationInstanceMother { // // private ApplicationInstanceMother() { // throw new RuntimeException("Not allowed"); // } // // public static ApplicationInstance instance(String id, String application) { // return instance(id, application, URI.create("http://localhost:8080")); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri) { // return ApplicationInstance.Builder.forApplicationWithId(application, id).baseUri(baseUri).build(); // } // // public static ApplicationInstance instance(String id, String application, URI baseUri, Links actuatorEndpoints) { // ApplicationInstance applicationInstance = ApplicationInstance.Builder.forApplicationWithId(application, id) // .baseUri(baseUri) // .build(); // applicationInstance.updateActuatorEndpoints(actuatorEndpoints); // return applicationInstance; // } // } // Path: microservices-dashboard-server-core/src/test/java/be/ordina/msdashboard/catalog/CatalogServiceTests.java import org.junit.Test; import be.ordina.msdashboard.applicationinstance.ApplicationInstance; import be.ordina.msdashboard.applicationinstance.ApplicationInstanceMother; import static org.assertj.core.api.Assertions.assertThat; @Test public void shouldAddApplicationToEmptyCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).hasSize(1); assertThat(catalog.getApplications()).contains("a"); } @Test public void shouldNotAddKnownApplicationToCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); catalogService.addApplicationToCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).hasSize(1); assertThat(catalog.getApplications()).contains("a"); } @Test public void shouldRemoveKnownApplicationFromCatalog() { CatalogService catalogService = new CatalogService(); catalogService.addApplicationToCatalog("a"); catalogService.removeApplicationFromCatalog("a"); Catalog catalog = catalogService.getCatalog(); assertThat(catalog.getApplications()).isEmpty(); } @Test public void shouldAddApplicationAndInstanceToEmptyCatalog() {
ApplicationInstance applicationInstance = ApplicationInstanceMother.instance("a-1", "a");
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // }
import be.ordina.msdashboard.applicationinstance.ApplicationInstance;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Application service to interact with the catalog. * * @author Tim Ysewyn * @author Steve De Zitter */ public class CatalogService { private final Catalog catalog; public CatalogService() { this.catalog = new Catalog(); } public Catalog getCatalog() { return this.catalog; } public void addApplicationToCatalog(String application) { this.catalog.addApplication(application); } public void removeApplicationFromCatalog(String application) { this.catalog.removeApplication(application); }
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java // public final class ApplicationInstance { // // private List<ApplicationEvent> changes = new ArrayList<>(); // // private final String id; // private final String application; // private final URI baseUri; // private State state; // private Status healthStatus = Status.UNKNOWN; // private Links actuatorEndpoints = new Links(); // // private ApplicationInstance(Builder builder) { // this.id = builder.id; // this.application = builder.application; // this.baseUri = builder.baseUri; // this.state = State.CREATED; // this.changes.add(new ApplicationInstanceCreated(this)); // } // // public String getId() { // return this.id; // } // // public String getApplication() { // return this.application; // } // // public URI getBaseUri() { // return this.baseUri; // } // // public Status getHealthStatus() { // return this.healthStatus; // } // // void updateHealthStatus(Status healthStatus) { // if (!this.healthStatus.equals(healthStatus)) { // this.healthStatus = healthStatus; // this.changes.add(new ApplicationInstanceHealthUpdated(this)); // } // } // // public Links getActuatorEndpoints() { // return this.actuatorEndpoints; // } // // public boolean hasActuatorEndpointFor(String endpoint) { // return this.actuatorEndpoints.hasLink(endpoint); // } // // public Optional<Link> getActuatorEndpoint(String endpoint) { // return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); // } // // void updateActuatorEndpoints(Links actuatorEndpoints) { // if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { // this.actuatorEndpoints = actuatorEndpoints; // this.changes.add(new ActuatorEndpointsUpdated(this)); // } // } // // public void delete() { // if (this.state != State.DELETED) { // this.state = State.DELETED; // this.changes.add(new ApplicationInstanceDeleted(this)); // } // } // // public State getState() { // return this.state; // } // // public List<ApplicationEvent> getUncommittedChanges() { // return this.changes; // } // // public ApplicationInstance markChangesAsCommitted() { // this.changes.clear(); // return this; // } // // /** // * Builder to create a new {@link ApplicationInstance application instance}. // * // * @author Tim Ysewyn // */ // static final class Builder { // // private final String id; // private final String application; // private URI baseUri; // // private Builder(String id, String application) { // this.id = id; // this.application = application; // } // // static Builder forApplicationWithId(String application, String id) { // return new Builder(id, application); // } // // Builder baseUri(URI baseUri) { // this.baseUri = baseUri; // return this; // } // // ApplicationInstance build() { // return new ApplicationInstance(this); // } // // } // // /** // * Indicator of the state of an {@link ApplicationInstance application instance}. // */ // public enum State { // /** // * Indicates that the {@link ApplicationInstance application instance} has been created. // */ // CREATED, // /** // * Indicates that the {@link ApplicationInstance application instance} has been deleted. // */ // DELETED // } // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/catalog/CatalogService.java import be.ordina.msdashboard.applicationinstance.ApplicationInstance; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.catalog; /** * Application service to interact with the catalog. * * @author Tim Ysewyn * @author Steve De Zitter */ public class CatalogService { private final Catalog catalog; public CatalogService() { this.catalog = new Catalog(); } public Catalog getCatalog() { return this.catalog; } public void addApplicationToCatalog(String application) { this.catalog.addApplication(application); } public void removeApplicationFromCatalog(String application) { this.catalog.removeApplication(application); }
public void addApplicationInstanceToCatalog(ApplicationInstance applicationInstance) {
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // }
import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEvent; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links;
/* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * The representation of an application's instance. * * @author Tim Ysewyn * @author Steve De Zitter */ public final class ApplicationInstance { private List<ApplicationEvent> changes = new ArrayList<>(); private final String id; private final String application; private final URI baseUri; private State state; private Status healthStatus = Status.UNKNOWN; private Links actuatorEndpoints = new Links(); private ApplicationInstance(Builder builder) { this.id = builder.id; this.application = builder.application; this.baseUri = builder.baseUri; this.state = State.CREATED;
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEvent; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; /* * Copyright 2015-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package be.ordina.msdashboard.applicationinstance; /** * The representation of an application's instance. * * @author Tim Ysewyn * @author Steve De Zitter */ public final class ApplicationInstance { private List<ApplicationEvent> changes = new ArrayList<>(); private final String id; private final String application; private final URI baseUri; private State state; private Status healthStatus = Status.UNKNOWN; private Links actuatorEndpoints = new Links(); private ApplicationInstance(Builder builder) { this.id = builder.id; this.application = builder.application; this.baseUri = builder.baseUri; this.state = State.CREATED;
this.changes.add(new ApplicationInstanceCreated(this));
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // }
import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEvent; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links;
private Status healthStatus = Status.UNKNOWN; private Links actuatorEndpoints = new Links(); private ApplicationInstance(Builder builder) { this.id = builder.id; this.application = builder.application; this.baseUri = builder.baseUri; this.state = State.CREATED; this.changes.add(new ApplicationInstanceCreated(this)); } public String getId() { return this.id; } public String getApplication() { return this.application; } public URI getBaseUri() { return this.baseUri; } public Status getHealthStatus() { return this.healthStatus; } void updateHealthStatus(Status healthStatus) { if (!this.healthStatus.equals(healthStatus)) { this.healthStatus = healthStatus;
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEvent; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; private Status healthStatus = Status.UNKNOWN; private Links actuatorEndpoints = new Links(); private ApplicationInstance(Builder builder) { this.id = builder.id; this.application = builder.application; this.baseUri = builder.baseUri; this.state = State.CREATED; this.changes.add(new ApplicationInstanceCreated(this)); } public String getId() { return this.id; } public String getApplication() { return this.application; } public URI getBaseUri() { return this.baseUri; } public Status getHealthStatus() { return this.healthStatus; } void updateHealthStatus(Status healthStatus) { if (!this.healthStatus.equals(healthStatus)) { this.healthStatus = healthStatus;
this.changes.add(new ApplicationInstanceHealthUpdated(this));
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // }
import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEvent; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links;
public URI getBaseUri() { return this.baseUri; } public Status getHealthStatus() { return this.healthStatus; } void updateHealthStatus(Status healthStatus) { if (!this.healthStatus.equals(healthStatus)) { this.healthStatus = healthStatus; this.changes.add(new ApplicationInstanceHealthUpdated(this)); } } public Links getActuatorEndpoints() { return this.actuatorEndpoints; } public boolean hasActuatorEndpointFor(String endpoint) { return this.actuatorEndpoints.hasLink(endpoint); } public Optional<Link> getActuatorEndpoint(String endpoint) { return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); } void updateActuatorEndpoints(Links actuatorEndpoints) { if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { this.actuatorEndpoints = actuatorEndpoints;
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEvent; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; public URI getBaseUri() { return this.baseUri; } public Status getHealthStatus() { return this.healthStatus; } void updateHealthStatus(Status healthStatus) { if (!this.healthStatus.equals(healthStatus)) { this.healthStatus = healthStatus; this.changes.add(new ApplicationInstanceHealthUpdated(this)); } } public Links getActuatorEndpoints() { return this.actuatorEndpoints; } public boolean hasActuatorEndpointFor(String endpoint) { return this.actuatorEndpoints.hasLink(endpoint); } public Optional<Link> getActuatorEndpoint(String endpoint) { return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); } void updateActuatorEndpoints(Links actuatorEndpoints) { if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { this.actuatorEndpoints = actuatorEndpoints;
this.changes.add(new ActuatorEndpointsUpdated(this));
ordina-jworks/microservices-dashboard
microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // }
import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEvent; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links;
void updateHealthStatus(Status healthStatus) { if (!this.healthStatus.equals(healthStatus)) { this.healthStatus = healthStatus; this.changes.add(new ApplicationInstanceHealthUpdated(this)); } } public Links getActuatorEndpoints() { return this.actuatorEndpoints; } public boolean hasActuatorEndpointFor(String endpoint) { return this.actuatorEndpoints.hasLink(endpoint); } public Optional<Link> getActuatorEndpoint(String endpoint) { return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); } void updateActuatorEndpoints(Links actuatorEndpoints) { if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { this.actuatorEndpoints = actuatorEndpoints; this.changes.add(new ActuatorEndpointsUpdated(this)); } } public void delete() { if (this.state != State.DELETED) { this.state = State.DELETED;
// Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ActuatorEndpointsUpdated.java // public class ActuatorEndpointsUpdated extends ApplicationEvent { // // public ActuatorEndpointsUpdated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceCreated.java // public class ApplicationInstanceCreated extends ApplicationEvent { // // public ApplicationInstanceCreated(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceDeleted.java // public class ApplicationInstanceDeleted extends ApplicationEvent { // // public ApplicationInstanceDeleted(ApplicationInstance instance) { // super(instance); // } // // public ApplicationInstance getApplicationInstance() { // return (ApplicationInstance) this.source; // } // // } // // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/events/ApplicationInstanceHealthUpdated.java // public class ApplicationInstanceHealthUpdated extends ApplicationEvent { // // public ApplicationInstanceHealthUpdated(ApplicationInstance instance) { // super(instance); // } // // } // Path: microservices-dashboard-server-core/src/main/java/be/ordina/msdashboard/applicationinstance/ApplicationInstance.java import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Optional; import be.ordina.msdashboard.applicationinstance.events.ActuatorEndpointsUpdated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceCreated; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceDeleted; import be.ordina.msdashboard.applicationinstance.events.ApplicationInstanceHealthUpdated; import org.springframework.boot.actuate.health.Status; import org.springframework.context.ApplicationEvent; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; void updateHealthStatus(Status healthStatus) { if (!this.healthStatus.equals(healthStatus)) { this.healthStatus = healthStatus; this.changes.add(new ApplicationInstanceHealthUpdated(this)); } } public Links getActuatorEndpoints() { return this.actuatorEndpoints; } public boolean hasActuatorEndpointFor(String endpoint) { return this.actuatorEndpoints.hasLink(endpoint); } public Optional<Link> getActuatorEndpoint(String endpoint) { return Optional.ofNullable(this.actuatorEndpoints.getLink(endpoint)); } void updateActuatorEndpoints(Links actuatorEndpoints) { if (!this.actuatorEndpoints.equals(actuatorEndpoints)) { this.actuatorEndpoints = actuatorEndpoints; this.changes.add(new ActuatorEndpointsUpdated(this)); } } public void delete() { if (this.state != State.DELETED) { this.state = State.DELETED;
this.changes.add(new ApplicationInstanceDeleted(this));
antag99/retinazer
retinazer/src/test/java/com/github/antag99/retinazer/util/LongBagTest.java
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/LongBag.java // public final class LongBag { // @Experimental // public long[] buffer; // // public LongBag() { // this(0); // } // // public LongBag(int capacity) { // buffer = new long[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // long[] newBuffer = new long[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // public long get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, long value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0L; // } // } // }
import org.junit.Test; import com.github.antag99.retinazer.util.LongBag; import static org.junit.Assert.*;
/******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class LongBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/LongBag.java // public final class LongBag { // @Experimental // public long[] buffer; // // public LongBag() { // this(0); // } // // public LongBag(int capacity) { // buffer = new long[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // long[] newBuffer = new long[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // public long get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, long value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0L; // } // } // } // Path: retinazer/src/test/java/com/github/antag99/retinazer/util/LongBagTest.java import org.junit.Test; import com.github.antag99.retinazer.util.LongBag; import static org.junit.Assert.*; /******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class LongBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
LongBag bag = new LongBag();
antag99/retinazer
retinazer/src/test/java/com/github/antag99/retinazer/util/IntBagTest.java
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/IntBag.java // public final class IntBag { // @Experimental // public int[] buffer; // // public IntBag() { // this(0); // } // // public IntBag(int capacity) { // buffer = new int[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // int[] newBuffer = new int[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // public int get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, int value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0; // } // } // }
import org.junit.Test; import com.github.antag99.retinazer.util.IntBag; import static org.junit.Assert.*;
/******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class IntBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/IntBag.java // public final class IntBag { // @Experimental // public int[] buffer; // // public IntBag() { // this(0); // } // // public IntBag(int capacity) { // buffer = new int[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // int[] newBuffer = new int[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // public int get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, int value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0; // } // } // } // Path: retinazer/src/test/java/com/github/antag99/retinazer/util/IntBagTest.java import org.junit.Test; import com.github.antag99.retinazer.util.IntBag; import static org.junit.Assert.*; /******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class IntBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
IntBag bag = new IntBag();
antag99/retinazer
retinazer/src/test/java/com/github/antag99/retinazer/util/DoubleBagTest.java
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/DoubleBag.java // public final class DoubleBag { // @Experimental // public double[] buffer; // // public DoubleBag() { // this(0); // } // // public DoubleBag(int capacity) { // buffer = new double[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // double[] newBuffer = new double[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // public double get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, double value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0d; // } // } // }
import org.junit.Test; import com.github.antag99.retinazer.util.DoubleBag; import static org.junit.Assert.*;
/******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class DoubleBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/DoubleBag.java // public final class DoubleBag { // @Experimental // public double[] buffer; // // public DoubleBag() { // this(0); // } // // public DoubleBag(int capacity) { // buffer = new double[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // double[] newBuffer = new double[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // public double get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, double value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0d; // } // } // } // Path: retinazer/src/test/java/com/github/antag99/retinazer/util/DoubleBagTest.java import org.junit.Test; import com.github.antag99.retinazer.util.DoubleBag; import static org.junit.Assert.*; /******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class DoubleBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
DoubleBag bag = new DoubleBag();
antag99/retinazer
retinazer/src/test/java/com/github/antag99/retinazer/util/ShortBagTest.java
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/ShortBag.java // public final class ShortBag { // @Experimental // public short[] buffer; // // public ShortBag() { // this(0); // } // // public ShortBag(int capacity) { // buffer = new short[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // short[] newBuffer = new short[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // public short get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, short value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0; // } // } // }
import org.junit.Test; import com.github.antag99.retinazer.util.ShortBag; import static org.junit.Assert.*;
/******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class ShortBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/ShortBag.java // public final class ShortBag { // @Experimental // public short[] buffer; // // public ShortBag() { // this(0); // } // // public ShortBag(int capacity) { // buffer = new short[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // short[] newBuffer = new short[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // public short get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, short value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0; // } // } // } // Path: retinazer/src/test/java/com/github/antag99/retinazer/util/ShortBagTest.java import org.junit.Test; import com.github.antag99.retinazer.util.ShortBag; import static org.junit.Assert.*; /******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class ShortBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
ShortBag bag = new ShortBag();
antag99/retinazer
retinazer/src/test/java/com/github/antag99/retinazer/util/ByteBagTest.java
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/ByteBag.java // public final class ByteBag { // @Experimental // public byte[] buffer; // // public ByteBag() { // this(0); // } // // public ByteBag(int capacity) { // buffer = new byte[capacity]; // } // // public byte get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, byte value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // if (value == 0) { // return; // } // int newCapacity = Bag.nextPowerOfTwo(index + 1); // byte[] newBuffer = new byte[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0; // } // } // }
import org.junit.Test; import com.github.antag99.retinazer.util.ByteBag; import static org.junit.Assert.*;
/******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class ByteBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/ByteBag.java // public final class ByteBag { // @Experimental // public byte[] buffer; // // public ByteBag() { // this(0); // } // // public ByteBag(int capacity) { // buffer = new byte[capacity]; // } // // public byte get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, byte value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // if (value == 0) { // return; // } // int newCapacity = Bag.nextPowerOfTwo(index + 1); // byte[] newBuffer = new byte[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0; // } // } // } // Path: retinazer/src/test/java/com/github/antag99/retinazer/util/ByteBagTest.java import org.junit.Test; import com.github.antag99.retinazer.util.ByteBag; import static org.junit.Assert.*; /******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class ByteBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
ByteBag bag = new ByteBag();
antag99/retinazer
retinazer/src/main/java/com/github/antag99/retinazer/Engine.java
// Path: retinazer/src/main/java/com/github/antag99/retinazer/EngineConfig.java // static final class EntitySystemRegistration { // final EntitySystem system; // final Priority priority; // // EntitySystemRegistration(EntitySystem system, Priority priority) { // this.system = system; // this.priority = priority; // } // }
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import com.github.antag99.retinazer.EngineConfig.EntitySystemRegistration;
/******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ /** Ashley copyright notice */ /******************************************************************************* * Copyright 2014 See AUTHORS.ASHLEY file. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ package com.github.antag99.retinazer; /** * Engine is the core class of retinazer; it manages all active entities, * performs system processing and initialization. */ public final class Engine { private final EntitySystem[] systems; private final Map<Class<? extends EntitySystem>, EntitySystem> systemsByType; final EntityManager entityManager; final ComponentManager componentManager; final FamilyManager familyManager; final WireManager wireManager; /** Tracks whether any components or entities have been modified; reset at every call to flush() */ boolean dirty = false; /** Tracks whether this engine is within a call to update() */ boolean update = false; /** * Creates a new {@link Engine} based on the specified configuration. Note * that the same configuration should <b>not</b> be reused, as system * implementations do not handle being registered to multiple engines. * * @param config * configuration for this Engine. */ public Engine(EngineConfig config) { entityManager = new EntityManager(this, config); componentManager = new ComponentManager(this, config); familyManager = new FamilyManager(this, config); wireManager = new WireManager(this, config);
// Path: retinazer/src/main/java/com/github/antag99/retinazer/EngineConfig.java // static final class EntitySystemRegistration { // final EntitySystem system; // final Priority priority; // // EntitySystemRegistration(EntitySystem system, Priority priority) { // this.system = system; // this.priority = priority; // } // } // Path: retinazer/src/main/java/com/github/antag99/retinazer/Engine.java import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import com.github.antag99.retinazer.EngineConfig.EntitySystemRegistration; /******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ /** Ashley copyright notice */ /******************************************************************************* * Copyright 2014 See AUTHORS.ASHLEY file. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ package com.github.antag99.retinazer; /** * Engine is the core class of retinazer; it manages all active entities, * performs system processing and initialization. */ public final class Engine { private final EntitySystem[] systems; private final Map<Class<? extends EntitySystem>, EntitySystem> systemsByType; final EntityManager entityManager; final ComponentManager componentManager; final FamilyManager familyManager; final WireManager wireManager; /** Tracks whether any components or entities have been modified; reset at every call to flush() */ boolean dirty = false; /** Tracks whether this engine is within a call to update() */ boolean update = false; /** * Creates a new {@link Engine} based on the specified configuration. Note * that the same configuration should <b>not</b> be reused, as system * implementations do not handle being registered to multiple engines. * * @param config * configuration for this Engine. */ public Engine(EngineConfig config) { entityManager = new EntityManager(this, config); componentManager = new ComponentManager(this, config); familyManager = new FamilyManager(this, config); wireManager = new WireManager(this, config);
List<EntitySystemRegistration> systemRegistrations = new ArrayList<>(config.systems);
antag99/retinazer
retinazer/src/test/java/com/github/antag99/retinazer/util/FloatBagTest.java
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/FloatBag.java // public final class FloatBag { // @Experimental // public float[] buffer; // // public FloatBag() { // this(0); // } // // public FloatBag(int capacity) { // buffer = new float[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // float[] newBuffer = new float[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // public float get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, float value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0f; // } // } // }
import org.junit.Test; import com.github.antag99.retinazer.util.FloatBag; import static org.junit.Assert.*;
/******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class FloatBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/FloatBag.java // public final class FloatBag { // @Experimental // public float[] buffer; // // public FloatBag() { // this(0); // } // // public FloatBag(int capacity) { // buffer = new float[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // float[] newBuffer = new float[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // public float get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return 0; // } // // return buffer[index]; // } // // public void set(int index, float value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = 0f; // } // } // } // Path: retinazer/src/test/java/com/github/antag99/retinazer/util/FloatBagTest.java import org.junit.Test; import com.github.antag99.retinazer.util.FloatBag; import static org.junit.Assert.*; /******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class FloatBagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
FloatBag bag = new FloatBag();
antag99/retinazer
retinazer/src/test/java/com/github/antag99/retinazer/util/BagTest.java
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/Bag.java // public final class Bag<E> { // @Experimental // public Object[] buffer; // // static int nextPowerOfTwo(int value) { // if (value == 0) { // return 1; // } // value--; // value |= value >>> 1; // value |= value >>> 2; // value |= value >>> 4; // value |= value >>> 8; // value |= value >>> 16; // return value + 1; // } // // public Bag() { // this(0); // } // // public Bag(int capacity) { // buffer = new Object[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // Object[] newBuffer = new Object[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // @SuppressWarnings("unchecked") // public E get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return null; // } // // return (E) buffer[index]; // } // // public void set(int index, E value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = null; // } // } // }
import org.junit.Test; import com.github.antag99.retinazer.util.Bag; import static org.junit.Assert.*;
/******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class BagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
// Path: retinazer/src/main/java/com/github/antag99/retinazer/util/Bag.java // public final class Bag<E> { // @Experimental // public Object[] buffer; // // static int nextPowerOfTwo(int value) { // if (value == 0) { // return 1; // } // value--; // value |= value >>> 1; // value |= value >>> 2; // value |= value >>> 4; // value |= value >>> 8; // value |= value >>> 16; // return value + 1; // } // // public Bag() { // this(0); // } // // public Bag(int capacity) { // buffer = new Object[capacity]; // } // // public void ensureCapacity(int capacity) { // if (this.buffer.length >= capacity) // return; // int newCapacity = Bag.nextPowerOfTwo(capacity); // Object[] newBuffer = new Object[newCapacity]; // System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); // this.buffer = newBuffer; // } // // @SuppressWarnings("unchecked") // public E get(int index) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // return null; // } // // return (E) buffer[index]; // } // // public void set(int index, E value) { // if (index < 0) { // throw new IndexOutOfBoundsException("index < 0: " + index); // } // // if (index >= buffer.length) { // ensureCapacity(index + 1); // } // // buffer[index] = value; // } // // public void clear() { // for (int i = 0, n = buffer.length; i < n; ++i) { // buffer[i] = null; // } // } // } // Path: retinazer/src/test/java/com/github/antag99/retinazer/util/BagTest.java import org.junit.Test; import com.github.antag99.retinazer.util.Bag; import static org.junit.Assert.*; /******************************************************************************* * Copyright (C) 2015 Anton Gustafsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. ******************************************************************************/ package com.github.antag99.retinazer.util; public class BagTest { /** * Ensures that the elements of a bag are actually stored */ @Test public void testStorage() {
Bag<Object> bag = new Bag<>();
wepay/kafka-connect-bigquery
kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/utils/SinkRecordConverter.java
// Path: kcbq-api/src/main/java/com/wepay/kafka/connect/bigquery/api/KafkaSchemaRecordType.java // public enum KafkaSchemaRecordType { // // VALUE("value"), // KEY("key"); // // private final String str; // // KafkaSchemaRecordType(String str) { // this.str = str; // } // // public String toString() { // return this.str; // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/KafkaDataBuilder.java // public class KafkaDataBuilder { // // public static final String KAFKA_DATA_TOPIC_FIELD_NAME = "topic"; // public static final String KAFKA_DATA_PARTITION_FIELD_NAME = "partition"; // public static final String KAFKA_DATA_OFFSET_FIELD_NAME = "offset"; // public static final String KAFKA_DATA_INSERT_TIME_FIELD_NAME = "insertTime"; // // /** // * Construct schema for Kafka Data Field // * // * @param kafkaDataFieldName The configured name of Kafka Data Field // * @return Field of Kafka Data, with definitions of kafka topic, partition, offset, and insertTime. // */ // public static Field buildKafkaDataField(String kafkaDataFieldName) { // Field topicField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_TOPIC_FIELD_NAME, LegacySQLTypeName.STRING); // Field partitionField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_PARTITION_FIELD_NAME, LegacySQLTypeName.INTEGER); // Field offsetField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_OFFSET_FIELD_NAME, LegacySQLTypeName.INTEGER); // Field.Builder insertTimeBuilder = com.google.cloud.bigquery.Field.newBuilder( // KAFKA_DATA_INSERT_TIME_FIELD_NAME, LegacySQLTypeName.TIMESTAMP) // .setMode(com.google.cloud.bigquery.Field.Mode.NULLABLE); // Field insertTimeField = insertTimeBuilder.build(); // // return Field.newBuilder(kafkaDataFieldName, LegacySQLTypeName.RECORD, // topicField, partitionField, offsetField, insertTimeField) // .setMode(com.google.cloud.bigquery.Field.Mode.NULLABLE).build(); // } // // /** // * Construct a map of Kafka Data record // * // * @param kafkaConnectRecord Kafka sink record to build kafka data from. // * @return HashMap which contains the values of kafka topic, partition, offset, and insertTime. // */ // public static Map<String, Object> buildKafkaDataRecord(SinkRecord kafkaConnectRecord) { // HashMap<String, Object> kafkaData = new HashMap<>(); // kafkaData.put(KAFKA_DATA_TOPIC_FIELD_NAME, kafkaConnectRecord.topic()); // kafkaData.put(KAFKA_DATA_PARTITION_FIELD_NAME, kafkaConnectRecord.kafkaPartition()); // kafkaData.put(KAFKA_DATA_OFFSET_FIELD_NAME, kafkaConnectRecord.kafkaOffset()); // kafkaData.put(KAFKA_DATA_INSERT_TIME_FIELD_NAME, System.currentTimeMillis() / 1000.0); // return kafkaData; // } // // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/RecordConverter.java // public interface RecordConverter<R> { // /** // * @param record The record to convert. // * @param recordType The type of the record to convert, either value or key. // * @return The converted record. // */ // R convertRecord(SinkRecord record, KafkaSchemaRecordType recordType); // // }
import com.google.cloud.bigquery.InsertAllRequest; import com.wepay.kafka.connect.bigquery.api.KafkaSchemaRecordType; import com.wepay.kafka.connect.bigquery.convert.KafkaDataBuilder; import com.wepay.kafka.connect.bigquery.convert.RecordConverter; import org.apache.kafka.connect.sink.SinkRecord; import java.util.Map; import java.util.Optional;
package com.wepay.kafka.connect.bigquery.utils; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * A class for converting a {@link SinkRecord SinkRecord} to {@link InsertAllRequest.RowToInsert BigQuery row} */ public class SinkRecordConverter { private final RecordConverter<Map<String, Object>> recordConverter; private final boolean sanitizeFieldName; private final Optional<String> kafkaKeyFieldName; private final Optional<String> kafkaDataFieldName; public SinkRecordConverter(RecordConverter<Map<String, Object>> recordConverter, boolean sanitizeFieldName, Optional<String> kafkaKeyFieldName, Optional<String> kafkaDataFieldName) { this.recordConverter = recordConverter; this.sanitizeFieldName = sanitizeFieldName; this.kafkaKeyFieldName = kafkaKeyFieldName; this.kafkaDataFieldName = kafkaDataFieldName; } public InsertAllRequest.RowToInsert getRecordRow(SinkRecord record) {
// Path: kcbq-api/src/main/java/com/wepay/kafka/connect/bigquery/api/KafkaSchemaRecordType.java // public enum KafkaSchemaRecordType { // // VALUE("value"), // KEY("key"); // // private final String str; // // KafkaSchemaRecordType(String str) { // this.str = str; // } // // public String toString() { // return this.str; // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/KafkaDataBuilder.java // public class KafkaDataBuilder { // // public static final String KAFKA_DATA_TOPIC_FIELD_NAME = "topic"; // public static final String KAFKA_DATA_PARTITION_FIELD_NAME = "partition"; // public static final String KAFKA_DATA_OFFSET_FIELD_NAME = "offset"; // public static final String KAFKA_DATA_INSERT_TIME_FIELD_NAME = "insertTime"; // // /** // * Construct schema for Kafka Data Field // * // * @param kafkaDataFieldName The configured name of Kafka Data Field // * @return Field of Kafka Data, with definitions of kafka topic, partition, offset, and insertTime. // */ // public static Field buildKafkaDataField(String kafkaDataFieldName) { // Field topicField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_TOPIC_FIELD_NAME, LegacySQLTypeName.STRING); // Field partitionField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_PARTITION_FIELD_NAME, LegacySQLTypeName.INTEGER); // Field offsetField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_OFFSET_FIELD_NAME, LegacySQLTypeName.INTEGER); // Field.Builder insertTimeBuilder = com.google.cloud.bigquery.Field.newBuilder( // KAFKA_DATA_INSERT_TIME_FIELD_NAME, LegacySQLTypeName.TIMESTAMP) // .setMode(com.google.cloud.bigquery.Field.Mode.NULLABLE); // Field insertTimeField = insertTimeBuilder.build(); // // return Field.newBuilder(kafkaDataFieldName, LegacySQLTypeName.RECORD, // topicField, partitionField, offsetField, insertTimeField) // .setMode(com.google.cloud.bigquery.Field.Mode.NULLABLE).build(); // } // // /** // * Construct a map of Kafka Data record // * // * @param kafkaConnectRecord Kafka sink record to build kafka data from. // * @return HashMap which contains the values of kafka topic, partition, offset, and insertTime. // */ // public static Map<String, Object> buildKafkaDataRecord(SinkRecord kafkaConnectRecord) { // HashMap<String, Object> kafkaData = new HashMap<>(); // kafkaData.put(KAFKA_DATA_TOPIC_FIELD_NAME, kafkaConnectRecord.topic()); // kafkaData.put(KAFKA_DATA_PARTITION_FIELD_NAME, kafkaConnectRecord.kafkaPartition()); // kafkaData.put(KAFKA_DATA_OFFSET_FIELD_NAME, kafkaConnectRecord.kafkaOffset()); // kafkaData.put(KAFKA_DATA_INSERT_TIME_FIELD_NAME, System.currentTimeMillis() / 1000.0); // return kafkaData; // } // // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/RecordConverter.java // public interface RecordConverter<R> { // /** // * @param record The record to convert. // * @param recordType The type of the record to convert, either value or key. // * @return The converted record. // */ // R convertRecord(SinkRecord record, KafkaSchemaRecordType recordType); // // } // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/utils/SinkRecordConverter.java import com.google.cloud.bigquery.InsertAllRequest; import com.wepay.kafka.connect.bigquery.api.KafkaSchemaRecordType; import com.wepay.kafka.connect.bigquery.convert.KafkaDataBuilder; import com.wepay.kafka.connect.bigquery.convert.RecordConverter; import org.apache.kafka.connect.sink.SinkRecord; import java.util.Map; import java.util.Optional; package com.wepay.kafka.connect.bigquery.utils; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * A class for converting a {@link SinkRecord SinkRecord} to {@link InsertAllRequest.RowToInsert BigQuery row} */ public class SinkRecordConverter { private final RecordConverter<Map<String, Object>> recordConverter; private final boolean sanitizeFieldName; private final Optional<String> kafkaKeyFieldName; private final Optional<String> kafkaDataFieldName; public SinkRecordConverter(RecordConverter<Map<String, Object>> recordConverter, boolean sanitizeFieldName, Optional<String> kafkaKeyFieldName, Optional<String> kafkaDataFieldName) { this.recordConverter = recordConverter; this.sanitizeFieldName = sanitizeFieldName; this.kafkaKeyFieldName = kafkaKeyFieldName; this.kafkaDataFieldName = kafkaDataFieldName; } public InsertAllRequest.RowToInsert getRecordRow(SinkRecord record) {
Map<String, Object> convertedRecord = recordConverter.convertRecord(record, KafkaSchemaRecordType.VALUE);
wepay/kafka-connect-bigquery
kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/utils/SinkRecordConverter.java
// Path: kcbq-api/src/main/java/com/wepay/kafka/connect/bigquery/api/KafkaSchemaRecordType.java // public enum KafkaSchemaRecordType { // // VALUE("value"), // KEY("key"); // // private final String str; // // KafkaSchemaRecordType(String str) { // this.str = str; // } // // public String toString() { // return this.str; // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/KafkaDataBuilder.java // public class KafkaDataBuilder { // // public static final String KAFKA_DATA_TOPIC_FIELD_NAME = "topic"; // public static final String KAFKA_DATA_PARTITION_FIELD_NAME = "partition"; // public static final String KAFKA_DATA_OFFSET_FIELD_NAME = "offset"; // public static final String KAFKA_DATA_INSERT_TIME_FIELD_NAME = "insertTime"; // // /** // * Construct schema for Kafka Data Field // * // * @param kafkaDataFieldName The configured name of Kafka Data Field // * @return Field of Kafka Data, with definitions of kafka topic, partition, offset, and insertTime. // */ // public static Field buildKafkaDataField(String kafkaDataFieldName) { // Field topicField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_TOPIC_FIELD_NAME, LegacySQLTypeName.STRING); // Field partitionField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_PARTITION_FIELD_NAME, LegacySQLTypeName.INTEGER); // Field offsetField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_OFFSET_FIELD_NAME, LegacySQLTypeName.INTEGER); // Field.Builder insertTimeBuilder = com.google.cloud.bigquery.Field.newBuilder( // KAFKA_DATA_INSERT_TIME_FIELD_NAME, LegacySQLTypeName.TIMESTAMP) // .setMode(com.google.cloud.bigquery.Field.Mode.NULLABLE); // Field insertTimeField = insertTimeBuilder.build(); // // return Field.newBuilder(kafkaDataFieldName, LegacySQLTypeName.RECORD, // topicField, partitionField, offsetField, insertTimeField) // .setMode(com.google.cloud.bigquery.Field.Mode.NULLABLE).build(); // } // // /** // * Construct a map of Kafka Data record // * // * @param kafkaConnectRecord Kafka sink record to build kafka data from. // * @return HashMap which contains the values of kafka topic, partition, offset, and insertTime. // */ // public static Map<String, Object> buildKafkaDataRecord(SinkRecord kafkaConnectRecord) { // HashMap<String, Object> kafkaData = new HashMap<>(); // kafkaData.put(KAFKA_DATA_TOPIC_FIELD_NAME, kafkaConnectRecord.topic()); // kafkaData.put(KAFKA_DATA_PARTITION_FIELD_NAME, kafkaConnectRecord.kafkaPartition()); // kafkaData.put(KAFKA_DATA_OFFSET_FIELD_NAME, kafkaConnectRecord.kafkaOffset()); // kafkaData.put(KAFKA_DATA_INSERT_TIME_FIELD_NAME, System.currentTimeMillis() / 1000.0); // return kafkaData; // } // // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/RecordConverter.java // public interface RecordConverter<R> { // /** // * @param record The record to convert. // * @param recordType The type of the record to convert, either value or key. // * @return The converted record. // */ // R convertRecord(SinkRecord record, KafkaSchemaRecordType recordType); // // }
import com.google.cloud.bigquery.InsertAllRequest; import com.wepay.kafka.connect.bigquery.api.KafkaSchemaRecordType; import com.wepay.kafka.connect.bigquery.convert.KafkaDataBuilder; import com.wepay.kafka.connect.bigquery.convert.RecordConverter; import org.apache.kafka.connect.sink.SinkRecord; import java.util.Map; import java.util.Optional;
package com.wepay.kafka.connect.bigquery.utils; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * A class for converting a {@link SinkRecord SinkRecord} to {@link InsertAllRequest.RowToInsert BigQuery row} */ public class SinkRecordConverter { private final RecordConverter<Map<String, Object>> recordConverter; private final boolean sanitizeFieldName; private final Optional<String> kafkaKeyFieldName; private final Optional<String> kafkaDataFieldName; public SinkRecordConverter(RecordConverter<Map<String, Object>> recordConverter, boolean sanitizeFieldName, Optional<String> kafkaKeyFieldName, Optional<String> kafkaDataFieldName) { this.recordConverter = recordConverter; this.sanitizeFieldName = sanitizeFieldName; this.kafkaKeyFieldName = kafkaKeyFieldName; this.kafkaDataFieldName = kafkaDataFieldName; } public InsertAllRequest.RowToInsert getRecordRow(SinkRecord record) { Map<String, Object> convertedRecord = recordConverter.convertRecord(record, KafkaSchemaRecordType.VALUE); if (kafkaKeyFieldName.isPresent()) { convertedRecord.put(kafkaKeyFieldName.get(), recordConverter.convertRecord(record, KafkaSchemaRecordType.KEY)); } if (kafkaDataFieldName.isPresent()) {
// Path: kcbq-api/src/main/java/com/wepay/kafka/connect/bigquery/api/KafkaSchemaRecordType.java // public enum KafkaSchemaRecordType { // // VALUE("value"), // KEY("key"); // // private final String str; // // KafkaSchemaRecordType(String str) { // this.str = str; // } // // public String toString() { // return this.str; // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/KafkaDataBuilder.java // public class KafkaDataBuilder { // // public static final String KAFKA_DATA_TOPIC_FIELD_NAME = "topic"; // public static final String KAFKA_DATA_PARTITION_FIELD_NAME = "partition"; // public static final String KAFKA_DATA_OFFSET_FIELD_NAME = "offset"; // public static final String KAFKA_DATA_INSERT_TIME_FIELD_NAME = "insertTime"; // // /** // * Construct schema for Kafka Data Field // * // * @param kafkaDataFieldName The configured name of Kafka Data Field // * @return Field of Kafka Data, with definitions of kafka topic, partition, offset, and insertTime. // */ // public static Field buildKafkaDataField(String kafkaDataFieldName) { // Field topicField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_TOPIC_FIELD_NAME, LegacySQLTypeName.STRING); // Field partitionField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_PARTITION_FIELD_NAME, LegacySQLTypeName.INTEGER); // Field offsetField = com.google.cloud.bigquery.Field.of(KAFKA_DATA_OFFSET_FIELD_NAME, LegacySQLTypeName.INTEGER); // Field.Builder insertTimeBuilder = com.google.cloud.bigquery.Field.newBuilder( // KAFKA_DATA_INSERT_TIME_FIELD_NAME, LegacySQLTypeName.TIMESTAMP) // .setMode(com.google.cloud.bigquery.Field.Mode.NULLABLE); // Field insertTimeField = insertTimeBuilder.build(); // // return Field.newBuilder(kafkaDataFieldName, LegacySQLTypeName.RECORD, // topicField, partitionField, offsetField, insertTimeField) // .setMode(com.google.cloud.bigquery.Field.Mode.NULLABLE).build(); // } // // /** // * Construct a map of Kafka Data record // * // * @param kafkaConnectRecord Kafka sink record to build kafka data from. // * @return HashMap which contains the values of kafka topic, partition, offset, and insertTime. // */ // public static Map<String, Object> buildKafkaDataRecord(SinkRecord kafkaConnectRecord) { // HashMap<String, Object> kafkaData = new HashMap<>(); // kafkaData.put(KAFKA_DATA_TOPIC_FIELD_NAME, kafkaConnectRecord.topic()); // kafkaData.put(KAFKA_DATA_PARTITION_FIELD_NAME, kafkaConnectRecord.kafkaPartition()); // kafkaData.put(KAFKA_DATA_OFFSET_FIELD_NAME, kafkaConnectRecord.kafkaOffset()); // kafkaData.put(KAFKA_DATA_INSERT_TIME_FIELD_NAME, System.currentTimeMillis() / 1000.0); // return kafkaData; // } // // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/RecordConverter.java // public interface RecordConverter<R> { // /** // * @param record The record to convert. // * @param recordType The type of the record to convert, either value or key. // * @return The converted record. // */ // R convertRecord(SinkRecord record, KafkaSchemaRecordType recordType); // // } // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/utils/SinkRecordConverter.java import com.google.cloud.bigquery.InsertAllRequest; import com.wepay.kafka.connect.bigquery.api.KafkaSchemaRecordType; import com.wepay.kafka.connect.bigquery.convert.KafkaDataBuilder; import com.wepay.kafka.connect.bigquery.convert.RecordConverter; import org.apache.kafka.connect.sink.SinkRecord; import java.util.Map; import java.util.Optional; package com.wepay.kafka.connect.bigquery.utils; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * A class for converting a {@link SinkRecord SinkRecord} to {@link InsertAllRequest.RowToInsert BigQuery row} */ public class SinkRecordConverter { private final RecordConverter<Map<String, Object>> recordConverter; private final boolean sanitizeFieldName; private final Optional<String> kafkaKeyFieldName; private final Optional<String> kafkaDataFieldName; public SinkRecordConverter(RecordConverter<Map<String, Object>> recordConverter, boolean sanitizeFieldName, Optional<String> kafkaKeyFieldName, Optional<String> kafkaDataFieldName) { this.recordConverter = recordConverter; this.sanitizeFieldName = sanitizeFieldName; this.kafkaKeyFieldName = kafkaKeyFieldName; this.kafkaDataFieldName = kafkaDataFieldName; } public InsertAllRequest.RowToInsert getRecordRow(SinkRecord record) { Map<String, Object> convertedRecord = recordConverter.convertRecord(record, KafkaSchemaRecordType.VALUE); if (kafkaKeyFieldName.isPresent()) { convertedRecord.put(kafkaKeyFieldName.get(), recordConverter.convertRecord(record, KafkaSchemaRecordType.KEY)); } if (kafkaDataFieldName.isPresent()) {
convertedRecord.put(kafkaDataFieldName.get(), KafkaDataBuilder.buildKafkaDataRecord(record));
wepay/kafka-connect-bigquery
kcbq-connector/src/integration-test/java/com/wepay/kafka/connect/bigquery/it/BigQueryConnectorIntegrationTest.java
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/BigQueryHelper.java // public class BigQueryHelper { // private static final Logger logger = LoggerFactory.getLogger(BigQueryHelper.class); // private static String keySource; // // /** // * Returns a default {@link BigQuery} instance for the specified project with credentials provided // * in the specified file, which can then be used for creating, updating, and inserting into tables // * from specific datasets. // * // * @param projectName The name of the BigQuery project to work with // * @param key The google credentials JSON key that can be used to provide // * credentials to BigQuery, or null if no authentication should be performed. // * @return The resulting BigQuery object. // */ // public BigQuery connect(String projectName, String key) { // if (key == null) { // return connect(projectName); // } // logger.debug("Attempting to open file {} for service account json key", key); // InputStream credentialsStream; // try { // if (keySource != null && keySource.equals("JSON")) { // credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)); // } else { // credentialsStream = new FileInputStream(key); // } // return new // BigQueryOptions.DefaultBigQueryFactory().create( // BigQueryOptions.newBuilder() // .setProjectId(projectName) // .setCredentials(GoogleCredentials.fromStream(credentialsStream)) // .build() // ); // } catch (IOException err) { // throw new BigQueryConnectException("Failed to access json key file", err); // } // } // /** // * Returns a default {@link BigQuery} instance for the specified project with credentials provided // * in the specified file, which can then be used for creating, updating, and inserting into tables // * from specific datasets. // * // * @param keySource The type of key config we can expect. This is either a String // * representation of the Google credentials file, or the path to the Google credentials file. // * @return The resulting BigQuery object. // */ // public BigQueryHelper setKeySource(String keySource) { // this.keySource = keySource; // return this; // } // // /** // * Returns a default {@link BigQuery} instance for the specified project with no authentication // * credentials, which can then be used for creating, updating, and inserting into tables from // * specific datasets. // * // * @param projectName The name of the BigQuery project to work with // * @return The resulting BigQuery object. // */ // public BigQuery connect(String projectName) { // logger.debug("Attempting to access BigQuery without authentication"); // return new BigQueryOptions.DefaultBigQueryFactory().create( // BigQueryOptions.newBuilder() // .setProjectId(projectName) // .build() // ); // } // }
import static com.google.cloud.bigquery.LegacySQLTypeName.BOOLEAN; import static com.google.cloud.bigquery.LegacySQLTypeName.BYTES; import static com.google.cloud.bigquery.LegacySQLTypeName.DATE; import static com.google.cloud.bigquery.LegacySQLTypeName.FLOAT; import static com.google.cloud.bigquery.LegacySQLTypeName.INTEGER; import static com.google.cloud.bigquery.LegacySQLTypeName.STRING; import static com.google.cloud.bigquery.LegacySQLTypeName.TIMESTAMP; import static org.junit.Assert.assertEquals; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.Field; import com.google.cloud.bigquery.FieldValue; import com.google.cloud.bigquery.FieldValueList; import com.google.cloud.bigquery.Schema; import com.google.cloud.bigquery.Table; import com.google.cloud.bigquery.TableResult; import com.wepay.kafka.connect.bigquery.BigQueryHelper; import com.wepay.kafka.connect.bigquery.exception.SinkConfigConnectException; import org.junit.BeforeClass; import org.junit.Test; import java.io.FileNotFoundException; import java.io.InputStream; import java.time.LocalDate; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Properties;
keyfile = properties.getProperty(KEYFILE_PROPERTY); if (keyfile == null) { throw new SinkConfigConnectException( "'" + KEYFILE_PROPERTY + "' property must be specified in test properties file" ); } project = properties.getProperty(PROJECT_PROPERTY); if (project == null) { throw new SinkConfigConnectException( "'" + PROJECT_PROPERTY + "' property must be specified in test properties file" ); } dataset = properties.getProperty(DATASET_PROPERTY); if (dataset == null) { throw new SinkConfigConnectException( "'" + DATASET_PROPERTY + "' property must be specified in test properties file" ); } keySource = properties.getProperty(KEY_SOURCE_PROPERTY); } } private static void initializeBigQuery() throws Exception {
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/BigQueryHelper.java // public class BigQueryHelper { // private static final Logger logger = LoggerFactory.getLogger(BigQueryHelper.class); // private static String keySource; // // /** // * Returns a default {@link BigQuery} instance for the specified project with credentials provided // * in the specified file, which can then be used for creating, updating, and inserting into tables // * from specific datasets. // * // * @param projectName The name of the BigQuery project to work with // * @param key The google credentials JSON key that can be used to provide // * credentials to BigQuery, or null if no authentication should be performed. // * @return The resulting BigQuery object. // */ // public BigQuery connect(String projectName, String key) { // if (key == null) { // return connect(projectName); // } // logger.debug("Attempting to open file {} for service account json key", key); // InputStream credentialsStream; // try { // if (keySource != null && keySource.equals("JSON")) { // credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)); // } else { // credentialsStream = new FileInputStream(key); // } // return new // BigQueryOptions.DefaultBigQueryFactory().create( // BigQueryOptions.newBuilder() // .setProjectId(projectName) // .setCredentials(GoogleCredentials.fromStream(credentialsStream)) // .build() // ); // } catch (IOException err) { // throw new BigQueryConnectException("Failed to access json key file", err); // } // } // /** // * Returns a default {@link BigQuery} instance for the specified project with credentials provided // * in the specified file, which can then be used for creating, updating, and inserting into tables // * from specific datasets. // * // * @param keySource The type of key config we can expect. This is either a String // * representation of the Google credentials file, or the path to the Google credentials file. // * @return The resulting BigQuery object. // */ // public BigQueryHelper setKeySource(String keySource) { // this.keySource = keySource; // return this; // } // // /** // * Returns a default {@link BigQuery} instance for the specified project with no authentication // * credentials, which can then be used for creating, updating, and inserting into tables from // * specific datasets. // * // * @param projectName The name of the BigQuery project to work with // * @return The resulting BigQuery object. // */ // public BigQuery connect(String projectName) { // logger.debug("Attempting to access BigQuery without authentication"); // return new BigQueryOptions.DefaultBigQueryFactory().create( // BigQueryOptions.newBuilder() // .setProjectId(projectName) // .build() // ); // } // } // Path: kcbq-connector/src/integration-test/java/com/wepay/kafka/connect/bigquery/it/BigQueryConnectorIntegrationTest.java import static com.google.cloud.bigquery.LegacySQLTypeName.BOOLEAN; import static com.google.cloud.bigquery.LegacySQLTypeName.BYTES; import static com.google.cloud.bigquery.LegacySQLTypeName.DATE; import static com.google.cloud.bigquery.LegacySQLTypeName.FLOAT; import static com.google.cloud.bigquery.LegacySQLTypeName.INTEGER; import static com.google.cloud.bigquery.LegacySQLTypeName.STRING; import static com.google.cloud.bigquery.LegacySQLTypeName.TIMESTAMP; import static org.junit.Assert.assertEquals; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.Field; import com.google.cloud.bigquery.FieldValue; import com.google.cloud.bigquery.FieldValueList; import com.google.cloud.bigquery.Schema; import com.google.cloud.bigquery.Table; import com.google.cloud.bigquery.TableResult; import com.wepay.kafka.connect.bigquery.BigQueryHelper; import com.wepay.kafka.connect.bigquery.exception.SinkConfigConnectException; import org.junit.BeforeClass; import org.junit.Test; import java.io.FileNotFoundException; import java.io.InputStream; import java.time.LocalDate; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Properties; keyfile = properties.getProperty(KEYFILE_PROPERTY); if (keyfile == null) { throw new SinkConfigConnectException( "'" + KEYFILE_PROPERTY + "' property must be specified in test properties file" ); } project = properties.getProperty(PROJECT_PROPERTY); if (project == null) { throw new SinkConfigConnectException( "'" + PROJECT_PROPERTY + "' property must be specified in test properties file" ); } dataset = properties.getProperty(DATASET_PROPERTY); if (dataset == null) { throw new SinkConfigConnectException( "'" + DATASET_PROPERTY + "' property must be specified in test properties file" ); } keySource = properties.getProperty(KEY_SOURCE_PROPERTY); } } private static void initializeBigQuery() throws Exception {
bigQuery = new BigQueryHelper().setKeySource(keySource).connect(project, keyfile);
wepay/kafka-connect-bigquery
kcbq-connector/src/test/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConvertersTest.java
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DateConverter extends LogicalTypeConverter { // /** // * Create a new DateConverter. // */ // public DateConverter() { // super(Date.LOGICAL_NAME, // Schema.Type.INT32, // LegacySQLTypeName.DATE); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBQDateFormat().format((java.util.Date) kafkaConnectObject); // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DecimalConverter extends LogicalTypeConverter { // /** // * Create a new DecimalConverter. // */ // public DecimalConverter() { // super(Decimal.LOGICAL_NAME, // Schema.Type.BYTES, // LegacySQLTypeName.FLOAT); // } // // @Override // public BigDecimal convert(Object kafkaConnectObject) { // // cast to get ClassCastException // return (BigDecimal) kafkaConnectObject; // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class TimestampConverter extends LogicalTypeConverter { // /** // * Create a new TimestampConverter. // */ // public TimestampConverter() { // super(Timestamp.LOGICAL_NAME, // Schema.Type.INT64, // LegacySQLTypeName.TIMESTAMP); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBqTimestampFormat().format((java.util.Date) kafkaConnectObject); // } // }
import java.math.BigDecimal; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.cloud.bigquery.LegacySQLTypeName; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DateConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DecimalConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.TimestampConverter; import org.apache.kafka.connect.data.Schema; import org.junit.Test;
package com.wepay.kafka.connect.bigquery.convert.logicaltype; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class KafkaLogicalConvertersTest { //corresponds to March 1 2017, 22:20:38.808 private static final Long TIMESTAMP = 1488406838808L; @Test public void testDateConversion() {
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DateConverter extends LogicalTypeConverter { // /** // * Create a new DateConverter. // */ // public DateConverter() { // super(Date.LOGICAL_NAME, // Schema.Type.INT32, // LegacySQLTypeName.DATE); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBQDateFormat().format((java.util.Date) kafkaConnectObject); // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DecimalConverter extends LogicalTypeConverter { // /** // * Create a new DecimalConverter. // */ // public DecimalConverter() { // super(Decimal.LOGICAL_NAME, // Schema.Type.BYTES, // LegacySQLTypeName.FLOAT); // } // // @Override // public BigDecimal convert(Object kafkaConnectObject) { // // cast to get ClassCastException // return (BigDecimal) kafkaConnectObject; // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class TimestampConverter extends LogicalTypeConverter { // /** // * Create a new TimestampConverter. // */ // public TimestampConverter() { // super(Timestamp.LOGICAL_NAME, // Schema.Type.INT64, // LegacySQLTypeName.TIMESTAMP); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBqTimestampFormat().format((java.util.Date) kafkaConnectObject); // } // } // Path: kcbq-connector/src/test/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConvertersTest.java import java.math.BigDecimal; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.cloud.bigquery.LegacySQLTypeName; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DateConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DecimalConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.TimestampConverter; import org.apache.kafka.connect.data.Schema; import org.junit.Test; package com.wepay.kafka.connect.bigquery.convert.logicaltype; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class KafkaLogicalConvertersTest { //corresponds to March 1 2017, 22:20:38.808 private static final Long TIMESTAMP = 1488406838808L; @Test public void testDateConversion() {
DateConverter converter = new DateConverter();
wepay/kafka-connect-bigquery
kcbq-connector/src/test/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConvertersTest.java
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DateConverter extends LogicalTypeConverter { // /** // * Create a new DateConverter. // */ // public DateConverter() { // super(Date.LOGICAL_NAME, // Schema.Type.INT32, // LegacySQLTypeName.DATE); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBQDateFormat().format((java.util.Date) kafkaConnectObject); // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DecimalConverter extends LogicalTypeConverter { // /** // * Create a new DecimalConverter. // */ // public DecimalConverter() { // super(Decimal.LOGICAL_NAME, // Schema.Type.BYTES, // LegacySQLTypeName.FLOAT); // } // // @Override // public BigDecimal convert(Object kafkaConnectObject) { // // cast to get ClassCastException // return (BigDecimal) kafkaConnectObject; // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class TimestampConverter extends LogicalTypeConverter { // /** // * Create a new TimestampConverter. // */ // public TimestampConverter() { // super(Timestamp.LOGICAL_NAME, // Schema.Type.INT64, // LegacySQLTypeName.TIMESTAMP); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBqTimestampFormat().format((java.util.Date) kafkaConnectObject); // } // }
import java.math.BigDecimal; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.cloud.bigquery.LegacySQLTypeName; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DateConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DecimalConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.TimestampConverter; import org.apache.kafka.connect.data.Schema; import org.junit.Test;
package com.wepay.kafka.connect.bigquery.convert.logicaltype; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class KafkaLogicalConvertersTest { //corresponds to March 1 2017, 22:20:38.808 private static final Long TIMESTAMP = 1488406838808L; @Test public void testDateConversion() { DateConverter converter = new DateConverter(); assertEquals(LegacySQLTypeName.DATE, converter.getBQSchemaType()); try { converter.checkEncodingType(Schema.Type.INT32); } catch (Exception ex) { fail("Expected encoding type check to succeed."); } Date date = new Date(TIMESTAMP); String formattedDate = converter.convert(date); assertEquals("2017-03-01", formattedDate); } @Test public void testDecimalConversion() {
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DateConverter extends LogicalTypeConverter { // /** // * Create a new DateConverter. // */ // public DateConverter() { // super(Date.LOGICAL_NAME, // Schema.Type.INT32, // LegacySQLTypeName.DATE); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBQDateFormat().format((java.util.Date) kafkaConnectObject); // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DecimalConverter extends LogicalTypeConverter { // /** // * Create a new DecimalConverter. // */ // public DecimalConverter() { // super(Decimal.LOGICAL_NAME, // Schema.Type.BYTES, // LegacySQLTypeName.FLOAT); // } // // @Override // public BigDecimal convert(Object kafkaConnectObject) { // // cast to get ClassCastException // return (BigDecimal) kafkaConnectObject; // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class TimestampConverter extends LogicalTypeConverter { // /** // * Create a new TimestampConverter. // */ // public TimestampConverter() { // super(Timestamp.LOGICAL_NAME, // Schema.Type.INT64, // LegacySQLTypeName.TIMESTAMP); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBqTimestampFormat().format((java.util.Date) kafkaConnectObject); // } // } // Path: kcbq-connector/src/test/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConvertersTest.java import java.math.BigDecimal; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.cloud.bigquery.LegacySQLTypeName; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DateConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DecimalConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.TimestampConverter; import org.apache.kafka.connect.data.Schema; import org.junit.Test; package com.wepay.kafka.connect.bigquery.convert.logicaltype; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class KafkaLogicalConvertersTest { //corresponds to March 1 2017, 22:20:38.808 private static final Long TIMESTAMP = 1488406838808L; @Test public void testDateConversion() { DateConverter converter = new DateConverter(); assertEquals(LegacySQLTypeName.DATE, converter.getBQSchemaType()); try { converter.checkEncodingType(Schema.Type.INT32); } catch (Exception ex) { fail("Expected encoding type check to succeed."); } Date date = new Date(TIMESTAMP); String formattedDate = converter.convert(date); assertEquals("2017-03-01", formattedDate); } @Test public void testDecimalConversion() {
DecimalConverter converter = new DecimalConverter();
wepay/kafka-connect-bigquery
kcbq-connector/src/test/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConvertersTest.java
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DateConverter extends LogicalTypeConverter { // /** // * Create a new DateConverter. // */ // public DateConverter() { // super(Date.LOGICAL_NAME, // Schema.Type.INT32, // LegacySQLTypeName.DATE); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBQDateFormat().format((java.util.Date) kafkaConnectObject); // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DecimalConverter extends LogicalTypeConverter { // /** // * Create a new DecimalConverter. // */ // public DecimalConverter() { // super(Decimal.LOGICAL_NAME, // Schema.Type.BYTES, // LegacySQLTypeName.FLOAT); // } // // @Override // public BigDecimal convert(Object kafkaConnectObject) { // // cast to get ClassCastException // return (BigDecimal) kafkaConnectObject; // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class TimestampConverter extends LogicalTypeConverter { // /** // * Create a new TimestampConverter. // */ // public TimestampConverter() { // super(Timestamp.LOGICAL_NAME, // Schema.Type.INT64, // LegacySQLTypeName.TIMESTAMP); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBqTimestampFormat().format((java.util.Date) kafkaConnectObject); // } // }
import java.math.BigDecimal; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.cloud.bigquery.LegacySQLTypeName; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DateConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DecimalConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.TimestampConverter; import org.apache.kafka.connect.data.Schema; import org.junit.Test;
fail("Expected encoding type check to succeed."); } Date date = new Date(TIMESTAMP); String formattedDate = converter.convert(date); assertEquals("2017-03-01", formattedDate); } @Test public void testDecimalConversion() { DecimalConverter converter = new DecimalConverter(); assertEquals(LegacySQLTypeName.FLOAT, converter.getBQSchemaType()); try { converter.checkEncodingType(Schema.Type.BYTES); } catch (Exception ex) { fail("Expected encoding type check to succeed."); } BigDecimal bigDecimal = new BigDecimal("3.14159"); BigDecimal convertedDecimal = converter.convert(bigDecimal); // expecting no-op assertEquals(bigDecimal, convertedDecimal); } @Test public void testTimestampConversion() {
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DateConverter extends LogicalTypeConverter { // /** // * Create a new DateConverter. // */ // public DateConverter() { // super(Date.LOGICAL_NAME, // Schema.Type.INT32, // LegacySQLTypeName.DATE); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBQDateFormat().format((java.util.Date) kafkaConnectObject); // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class DecimalConverter extends LogicalTypeConverter { // /** // * Create a new DecimalConverter. // */ // public DecimalConverter() { // super(Decimal.LOGICAL_NAME, // Schema.Type.BYTES, // LegacySQLTypeName.FLOAT); // } // // @Override // public BigDecimal convert(Object kafkaConnectObject) { // // cast to get ClassCastException // return (BigDecimal) kafkaConnectObject; // } // } // // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConverters.java // public static class TimestampConverter extends LogicalTypeConverter { // /** // * Create a new TimestampConverter. // */ // public TimestampConverter() { // super(Timestamp.LOGICAL_NAME, // Schema.Type.INT64, // LegacySQLTypeName.TIMESTAMP); // } // // @Override // public String convert(Object kafkaConnectObject) { // return getBqTimestampFormat().format((java.util.Date) kafkaConnectObject); // } // } // Path: kcbq-connector/src/test/java/com/wepay/kafka/connect/bigquery/convert/logicaltype/KafkaLogicalConvertersTest.java import java.math.BigDecimal; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.cloud.bigquery.LegacySQLTypeName; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DateConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.DecimalConverter; import com.wepay.kafka.connect.bigquery.convert.logicaltype.KafkaLogicalConverters.TimestampConverter; import org.apache.kafka.connect.data.Schema; import org.junit.Test; fail("Expected encoding type check to succeed."); } Date date = new Date(TIMESTAMP); String formattedDate = converter.convert(date); assertEquals("2017-03-01", formattedDate); } @Test public void testDecimalConversion() { DecimalConverter converter = new DecimalConverter(); assertEquals(LegacySQLTypeName.FLOAT, converter.getBQSchemaType()); try { converter.checkEncodingType(Schema.Type.BYTES); } catch (Exception ex) { fail("Expected encoding type check to succeed."); } BigDecimal bigDecimal = new BigDecimal("3.14159"); BigDecimal convertedDecimal = converter.convert(bigDecimal); // expecting no-op assertEquals(bigDecimal, convertedDecimal); } @Test public void testTimestampConversion() {
TimestampConverter converter = new TimestampConverter();
wepay/kafka-connect-bigquery
kcbq-connector/src/integration-test/java/com/wepay/kafka/connect/bigquery/it/utils/TableClearer.java
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/BigQueryHelper.java // public class BigQueryHelper { // private static final Logger logger = LoggerFactory.getLogger(BigQueryHelper.class); // private static String keySource; // // /** // * Returns a default {@link BigQuery} instance for the specified project with credentials provided // * in the specified file, which can then be used for creating, updating, and inserting into tables // * from specific datasets. // * // * @param projectName The name of the BigQuery project to work with // * @param key The google credentials JSON key that can be used to provide // * credentials to BigQuery, or null if no authentication should be performed. // * @return The resulting BigQuery object. // */ // public BigQuery connect(String projectName, String key) { // if (key == null) { // return connect(projectName); // } // logger.debug("Attempting to open file {} for service account json key", key); // InputStream credentialsStream; // try { // if (keySource != null && keySource.equals("JSON")) { // credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)); // } else { // credentialsStream = new FileInputStream(key); // } // return new // BigQueryOptions.DefaultBigQueryFactory().create( // BigQueryOptions.newBuilder() // .setProjectId(projectName) // .setCredentials(GoogleCredentials.fromStream(credentialsStream)) // .build() // ); // } catch (IOException err) { // throw new BigQueryConnectException("Failed to access json key file", err); // } // } // /** // * Returns a default {@link BigQuery} instance for the specified project with credentials provided // * in the specified file, which can then be used for creating, updating, and inserting into tables // * from specific datasets. // * // * @param keySource The type of key config we can expect. This is either a String // * representation of the Google credentials file, or the path to the Google credentials file. // * @return The resulting BigQuery object. // */ // public BigQueryHelper setKeySource(String keySource) { // this.keySource = keySource; // return this; // } // // /** // * Returns a default {@link BigQuery} instance for the specified project with no authentication // * credentials, which can then be used for creating, updating, and inserting into tables from // * specific datasets. // * // * @param projectName The name of the BigQuery project to work with // * @return The resulting BigQuery object. // */ // public BigQuery connect(String projectName) { // logger.debug("Attempting to access BigQuery without authentication"); // return new BigQueryOptions.DefaultBigQueryFactory().create( // BigQueryOptions.newBuilder() // .setProjectId(projectName) // .build() // ); // } // }
import com.google.api.gax.paging.Page; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.Table; import com.wepay.kafka.connect.bigquery.BigQueryHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package com.wepay.kafka.connect.bigquery.it.utils; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class TableClearer { private static final Logger logger = LoggerFactory.getLogger(TableClearer.class); private static String keySource; /** * Clears tables in the given project and dataset, using a provided JSON service account key. */ public static void main(String[] args) { if (args.length < 5) { usage(); } if (args.length == 5) { keySource = args[3]; }
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/BigQueryHelper.java // public class BigQueryHelper { // private static final Logger logger = LoggerFactory.getLogger(BigQueryHelper.class); // private static String keySource; // // /** // * Returns a default {@link BigQuery} instance for the specified project with credentials provided // * in the specified file, which can then be used for creating, updating, and inserting into tables // * from specific datasets. // * // * @param projectName The name of the BigQuery project to work with // * @param key The google credentials JSON key that can be used to provide // * credentials to BigQuery, or null if no authentication should be performed. // * @return The resulting BigQuery object. // */ // public BigQuery connect(String projectName, String key) { // if (key == null) { // return connect(projectName); // } // logger.debug("Attempting to open file {} for service account json key", key); // InputStream credentialsStream; // try { // if (keySource != null && keySource.equals("JSON")) { // credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)); // } else { // credentialsStream = new FileInputStream(key); // } // return new // BigQueryOptions.DefaultBigQueryFactory().create( // BigQueryOptions.newBuilder() // .setProjectId(projectName) // .setCredentials(GoogleCredentials.fromStream(credentialsStream)) // .build() // ); // } catch (IOException err) { // throw new BigQueryConnectException("Failed to access json key file", err); // } // } // /** // * Returns a default {@link BigQuery} instance for the specified project with credentials provided // * in the specified file, which can then be used for creating, updating, and inserting into tables // * from specific datasets. // * // * @param keySource The type of key config we can expect. This is either a String // * representation of the Google credentials file, or the path to the Google credentials file. // * @return The resulting BigQuery object. // */ // public BigQueryHelper setKeySource(String keySource) { // this.keySource = keySource; // return this; // } // // /** // * Returns a default {@link BigQuery} instance for the specified project with no authentication // * credentials, which can then be used for creating, updating, and inserting into tables from // * specific datasets. // * // * @param projectName The name of the BigQuery project to work with // * @return The resulting BigQuery object. // */ // public BigQuery connect(String projectName) { // logger.debug("Attempting to access BigQuery without authentication"); // return new BigQueryOptions.DefaultBigQueryFactory().create( // BigQueryOptions.newBuilder() // .setProjectId(projectName) // .build() // ); // } // } // Path: kcbq-connector/src/integration-test/java/com/wepay/kafka/connect/bigquery/it/utils/TableClearer.java import com.google.api.gax.paging.Page; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.Table; import com.wepay.kafka.connect.bigquery.BigQueryHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package com.wepay.kafka.connect.bigquery.it.utils; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class TableClearer { private static final Logger logger = LoggerFactory.getLogger(TableClearer.class); private static String keySource; /** * Clears tables in the given project and dataset, using a provided JSON service account key. */ public static void main(String[] args) { if (args.length < 5) { usage(); } if (args.length == 5) { keySource = args[3]; }
BigQuery bigQuery = new BigQueryHelper().setKeySource(keySource).connect(args[1], args[0]);
wepay/kafka-connect-bigquery
kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/BigQueryHelper.java
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/exception/BigQueryConnectException.java // public class BigQueryConnectException extends ConnectException { // public BigQueryConnectException(String msg) { // super(msg); // } // // public BigQueryConnectException(String msg, Throwable thr) { // super(msg, thr); // } // // public BigQueryConnectException(Throwable thr) { // super(thr); // } // // public BigQueryConnectException(Map<Long, List<BigQueryError>> errors) { // super(formatInsertAllErrors(errors)); // } // // private static String formatInsertAllErrors(Map<Long, List<BigQueryError>> errorsMap) { // StringBuilder messageBuilder = new StringBuilder(); // messageBuilder.append("table insertion failed for the following rows:"); // for (Map.Entry<Long, List<BigQueryError>> errorsEntry : errorsMap.entrySet()) { // for (BigQueryError error : errorsEntry.getValue()) { // messageBuilder.append(String.format( // "%n\t[row index %d]: %s: %s", // errorsEntry.getKey(), // error.getReason(), // error.getMessage() // )); // } // } // return messageBuilder.toString(); // } // }
import java.nio.charset.StandardCharsets; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQueryOptions; import com.wepay.kafka.connect.bigquery.exception.BigQueryConnectException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.ByteArrayInputStream;
package com.wepay.kafka.connect.bigquery; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * Convenience class for creating a default {@link com.google.cloud.bigquery.BigQuery} instance, * with or without login credentials. */ public class BigQueryHelper { private static final Logger logger = LoggerFactory.getLogger(BigQueryHelper.class); private static String keySource; /** * Returns a default {@link BigQuery} instance for the specified project with credentials provided * in the specified file, which can then be used for creating, updating, and inserting into tables * from specific datasets. * * @param projectName The name of the BigQuery project to work with * @param key The google credentials JSON key that can be used to provide * credentials to BigQuery, or null if no authentication should be performed. * @return The resulting BigQuery object. */ public BigQuery connect(String projectName, String key) { if (key == null) { return connect(projectName); } logger.debug("Attempting to open file {} for service account json key", key); InputStream credentialsStream; try { if (keySource != null && keySource.equals("JSON")) { credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)); } else { credentialsStream = new FileInputStream(key); } return new BigQueryOptions.DefaultBigQueryFactory().create( BigQueryOptions.newBuilder() .setProjectId(projectName) .setCredentials(GoogleCredentials.fromStream(credentialsStream)) .build() ); } catch (IOException err) {
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/exception/BigQueryConnectException.java // public class BigQueryConnectException extends ConnectException { // public BigQueryConnectException(String msg) { // super(msg); // } // // public BigQueryConnectException(String msg, Throwable thr) { // super(msg, thr); // } // // public BigQueryConnectException(Throwable thr) { // super(thr); // } // // public BigQueryConnectException(Map<Long, List<BigQueryError>> errors) { // super(formatInsertAllErrors(errors)); // } // // private static String formatInsertAllErrors(Map<Long, List<BigQueryError>> errorsMap) { // StringBuilder messageBuilder = new StringBuilder(); // messageBuilder.append("table insertion failed for the following rows:"); // for (Map.Entry<Long, List<BigQueryError>> errorsEntry : errorsMap.entrySet()) { // for (BigQueryError error : errorsEntry.getValue()) { // messageBuilder.append(String.format( // "%n\t[row index %d]: %s: %s", // errorsEntry.getKey(), // error.getReason(), // error.getMessage() // )); // } // } // return messageBuilder.toString(); // } // } // Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/BigQueryHelper.java import java.nio.charset.StandardCharsets; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQueryOptions; import com.wepay.kafka.connect.bigquery.exception.BigQueryConnectException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.ByteArrayInputStream; package com.wepay.kafka.connect.bigquery; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * Convenience class for creating a default {@link com.google.cloud.bigquery.BigQuery} instance, * with or without login credentials. */ public class BigQueryHelper { private static final Logger logger = LoggerFactory.getLogger(BigQueryHelper.class); private static String keySource; /** * Returns a default {@link BigQuery} instance for the specified project with credentials provided * in the specified file, which can then be used for creating, updating, and inserting into tables * from specific datasets. * * @param projectName The name of the BigQuery project to work with * @param key The google credentials JSON key that can be used to provide * credentials to BigQuery, or null if no authentication should be performed. * @return The resulting BigQuery object. */ public BigQuery connect(String projectName, String key) { if (key == null) { return connect(projectName); } logger.debug("Attempting to open file {} for service account json key", key); InputStream credentialsStream; try { if (keySource != null && keySource.equals("JSON")) { credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)); } else { credentialsStream = new FileInputStream(key); } return new BigQueryOptions.DefaultBigQueryFactory().create( BigQueryOptions.newBuilder() .setProjectId(projectName) .setCredentials(GoogleCredentials.fromStream(credentialsStream)) .build() ); } catch (IOException err) {
throw new BigQueryConnectException("Failed to access json key file", err);
wepay/kafka-connect-bigquery
kcbq-connector/src/test/java/com/wepay/kafka/connect/bigquery/SchemaManagerTest.java
// Path: kcbq-api/src/main/java/com/wepay/kafka/connect/bigquery/api/SchemaRetriever.java // public interface SchemaRetriever { // /** // * Called with all of the configuration settings passed to the connector via its // * {@link org.apache.kafka.connect.sink.SinkConnector#start(Map)} method. // * @param properties The configuration settings of the connector. // */ // void configure(Map<String, String> properties); // // /** // * Retrieve the most current key schema for the given sink record. // * @param record The record to retrieve a key schema for. // * @return The key Schema for the given record. // */ // Schema retrieveKeySchema(SinkRecord record); // // /** // * Retrieve the most current value schema for the given sink record. // * @param record The record to retrieve a value schema for. // * @return The value Schema for the given record. // */ // Schema retrieveValueSchema(SinkRecord record); // // }
import org.apache.kafka.connect.data.Schema; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.util.Arrays; import java.util.List; import java.util.Optional; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.Field; import com.google.cloud.bigquery.LegacySQLTypeName; import com.google.cloud.bigquery.StandardTableDefinition; import com.google.cloud.bigquery.TableId; import com.google.cloud.bigquery.TableInfo; import com.wepay.kafka.connect.bigquery.api.SchemaRetriever; import com.wepay.kafka.connect.bigquery.convert.SchemaConverter;
package com.wepay.kafka.connect.bigquery; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class SchemaManagerTest { private String testTableName = "testTable"; private String testDatasetName = "testDataset"; private String testDoc = "test doc"; private TableId tableId = TableId.of(testDatasetName, testTableName);
// Path: kcbq-api/src/main/java/com/wepay/kafka/connect/bigquery/api/SchemaRetriever.java // public interface SchemaRetriever { // /** // * Called with all of the configuration settings passed to the connector via its // * {@link org.apache.kafka.connect.sink.SinkConnector#start(Map)} method. // * @param properties The configuration settings of the connector. // */ // void configure(Map<String, String> properties); // // /** // * Retrieve the most current key schema for the given sink record. // * @param record The record to retrieve a key schema for. // * @return The key Schema for the given record. // */ // Schema retrieveKeySchema(SinkRecord record); // // /** // * Retrieve the most current value schema for the given sink record. // * @param record The record to retrieve a value schema for. // * @return The value Schema for the given record. // */ // Schema retrieveValueSchema(SinkRecord record); // // } // Path: kcbq-connector/src/test/java/com/wepay/kafka/connect/bigquery/SchemaManagerTest.java import org.apache.kafka.connect.data.Schema; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.util.Arrays; import java.util.List; import java.util.Optional; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.Field; import com.google.cloud.bigquery.LegacySQLTypeName; import com.google.cloud.bigquery.StandardTableDefinition; import com.google.cloud.bigquery.TableId; import com.google.cloud.bigquery.TableInfo; import com.wepay.kafka.connect.bigquery.api.SchemaRetriever; import com.wepay.kafka.connect.bigquery.convert.SchemaConverter; package com.wepay.kafka.connect.bigquery; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class SchemaManagerTest { private String testTableName = "testTable"; private String testDatasetName = "testDataset"; private String testDoc = "test doc"; private TableId tableId = TableId.of(testDatasetName, testTableName);
private SchemaRetriever mockSchemaRetriever;
wepay/kafka-connect-bigquery
kcbq-connector/src/integration-test/java/com/wepay/kafka/connect/bigquery/it/utils/BucketClearer.java
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/GCSBuilder.java // public class GCSBuilder { // private static final Logger logger = LoggerFactory.getLogger(GCSBuilder.class); // // private final String projectName; // private String key; // private String keySource; // // public GCSBuilder(String projectName) { // this.projectName = projectName; // this.key = null; // } // // public GCSBuilder setKeySource(String keySourceType) { // this.keySource = keySourceType; // return this; // } // // public GCSBuilder setKey(String keyFile) { // this.key = keyFile; // return this; // } // public Storage build() { // return connect(projectName, key); // } // // /** // * Returns a default {@link Storage} instance for the specified project with credentials provided // * in the specified file. // * // * @param projectName The name of the GCS project to work with // * @param key The name of a file containing a JSON key that can be used to provide // * credentials to GCS, or null if no authentication should be performed. // * @return The resulting Storage object. // */ // private Storage connect(String projectName, String key) { // if (key == null) { // return connect(projectName); // } // try { // InputStream credentialsStream; // if (keySource != null && keySource.equals("JSON")) { // credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)); // } else { // credentialsStream = new FileInputStream(key); // } // return StorageOptions.newBuilder() // .setProjectId(projectName) // .setCredentials(GoogleCredentials.fromStream(credentialsStream)) // .build() // .getService(); // } catch (IOException err) { // throw new GCSConnectException("Failed to access json key file", err); // } // } // // /** // * Returns a default {@link Storage} instance for the specified project with no authentication // * credentials. // * // * @param projectName The name of the GCS project to work with // * @return The resulting Storage object. // */ // private Storage connect(String projectName) { // logger.debug("Attempting to access BigQuery without authentication"); // return StorageOptions.newBuilder() // .setProjectId(projectName) // .build() // .getService(); // } // }
import com.google.cloud.storage.Blob; import com.google.cloud.storage.Bucket; import com.google.cloud.storage.Storage; import com.wepay.kafka.connect.bigquery.GCSBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
package com.wepay.kafka.connect.bigquery.it.utils; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class BucketClearer { private static final Logger logger = LoggerFactory.getLogger(BucketClearer.class); private static String keySource; /** * Clears tables in the given project and dataset, using a provided JSON service account key. */ public static void main(String[] args) { if (args.length < 4) { usage(); } if (args.length == 4) { keySource = args[3]; }
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/GCSBuilder.java // public class GCSBuilder { // private static final Logger logger = LoggerFactory.getLogger(GCSBuilder.class); // // private final String projectName; // private String key; // private String keySource; // // public GCSBuilder(String projectName) { // this.projectName = projectName; // this.key = null; // } // // public GCSBuilder setKeySource(String keySourceType) { // this.keySource = keySourceType; // return this; // } // // public GCSBuilder setKey(String keyFile) { // this.key = keyFile; // return this; // } // public Storage build() { // return connect(projectName, key); // } // // /** // * Returns a default {@link Storage} instance for the specified project with credentials provided // * in the specified file. // * // * @param projectName The name of the GCS project to work with // * @param key The name of a file containing a JSON key that can be used to provide // * credentials to GCS, or null if no authentication should be performed. // * @return The resulting Storage object. // */ // private Storage connect(String projectName, String key) { // if (key == null) { // return connect(projectName); // } // try { // InputStream credentialsStream; // if (keySource != null && keySource.equals("JSON")) { // credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)); // } else { // credentialsStream = new FileInputStream(key); // } // return StorageOptions.newBuilder() // .setProjectId(projectName) // .setCredentials(GoogleCredentials.fromStream(credentialsStream)) // .build() // .getService(); // } catch (IOException err) { // throw new GCSConnectException("Failed to access json key file", err); // } // } // // /** // * Returns a default {@link Storage} instance for the specified project with no authentication // * credentials. // * // * @param projectName The name of the GCS project to work with // * @return The resulting Storage object. // */ // private Storage connect(String projectName) { // logger.debug("Attempting to access BigQuery without authentication"); // return StorageOptions.newBuilder() // .setProjectId(projectName) // .build() // .getService(); // } // } // Path: kcbq-connector/src/integration-test/java/com/wepay/kafka/connect/bigquery/it/utils/BucketClearer.java import com.google.cloud.storage.Blob; import com.google.cloud.storage.Bucket; import com.google.cloud.storage.Storage; import com.wepay.kafka.connect.bigquery.GCSBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; package com.wepay.kafka.connect.bigquery.it.utils; /* * Copyright 2016 WePay, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class BucketClearer { private static final Logger logger = LoggerFactory.getLogger(BucketClearer.class); private static String keySource; /** * Clears tables in the given project and dataset, using a provided JSON service account key. */ public static void main(String[] args) { if (args.length < 4) { usage(); } if (args.length == 4) { keySource = args[3]; }
Storage gcs = new GCSBuilder(args[1]).setKey(args[0]).setKeySource(keySource).build();